Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix details modal on collections page #592

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/core/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from rest_framework.serializers import ModelSerializer, SerializerMethodField

from core.models import Artwork, Exhibit, Marker, Object
from users.serializers import ProfileSerializer


class MarkerSerializer(ModelSerializer):
owner = ProfileSerializer(read_only=True)

source_size = SerializerMethodField()

class Meta:
model = Marker
fields = (
"id",
"owner",
"source",
"uploaded_at",
"author",
"title",
"patt",
"source_size",
"artworks_count",
"exhibits_count",
)
read_only_fields = (
"id",
"uploaded_at",
)

def get_source_size(self, obj):
return obj.source.size


class ObjectSerializer(ModelSerializer):
owner = ProfileSerializer(read_only=True)
source_size = SerializerMethodField()

class Meta:
model = Object
fields = (
"id",
"owner",
"source",
"source_size",
"uploaded_at",
"author",
"title",
"scale",
"position",
"rotation",
"artworks_count",
"exhibits_count",
)
read_only_fields = (
"id",
"uploaded_at",
)

def get_source_size(self, obj):
return obj.source.size


class ArtworkSerializer(ModelSerializer):
marker = MarkerSerializer(read_only=True)
augmented = ObjectSerializer(read_only=True)
author = ProfileSerializer(read_only=True)

class Meta:
model = Artwork
fields = (
"id",
"author",
"marker",
"augmented",
"title",
"description",
"created_at",
"exhibits_count",
)
read_only_fields = (
"id",
"uploaded_at",
)


class ExhibitSerializer(ModelSerializer):
class Meta:
model = Exhibit
fields = ("id", "owner", "name", "slug", "artworks", "creation_date")
read_only_fields = (
"id",
"creation_date",
)
Empty file removed src/core/serializers/__init__.py
Empty file.
21 changes: 0 additions & 21 deletions src/core/serializers/artworks.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/serializers/exhibits.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/core/serializers/markers.py

This file was deleted.

23 changes: 0 additions & 23 deletions src/core/serializers/objects.py

This file was deleted.

10 changes: 6 additions & 4 deletions src/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
from django.urls import include, path, re_path
from rest_framework_nested.routers import DefaultRouter

from core.views.artworks import ArtworkViewset
from core.views.exhibits import ExhibitViewset
from core.views.markers import MarkerViewset
from core.views.objects import ObjectViewset
from core.views.static_views import (
community,
documentation,
Expand All @@ -26,6 +22,12 @@
service_worker,
upload_image,
)
from core.views.viewsets import (
ArtworkViewset,
ExhibitViewset,
MarkerViewset,
ObjectViewset,
)

api_router = DefaultRouter()
api_router.register("markers", MarkerViewset, basename="marker")
Expand Down
10 changes: 0 additions & 10 deletions src/core/views/artworks.py

This file was deleted.

10 changes: 0 additions & 10 deletions src/core/views/exhibits.py

This file was deleted.

10 changes: 0 additions & 10 deletions src/core/views/markers.py

This file was deleted.

10 changes: 0 additions & 10 deletions src/core/views/objects.py

This file was deleted.

1 change: 0 additions & 1 deletion src/core/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def see_all(request, which="", page=1):
request_type: paginated_data,
"seeall": True,
}

return render(request, "core/collection.jinja2", ctx)


Expand Down
34 changes: 34 additions & 0 deletions src/core/views/viewsets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet

from core.models import Artwork, Exhibit, Marker, Object
from core.serializers import (
ArtworkSerializer,
ExhibitSerializer,
MarkerSerializer,
ObjectSerializer,
)


class ArtworkViewset(ListModelMixin, RetrieveModelMixin, GenericViewSet):
serializer_class = ArtworkSerializer
queryset = (
Artwork.objects.all()
.select_related("marker", "augmented", "author")
.order_by("id")
)


class ExhibitViewset(ListModelMixin, RetrieveModelMixin, GenericViewSet):
serializer_class = ExhibitSerializer
queryset = Exhibit.objects.all().order_by("id")


class MarkerViewset(ListModelMixin, RetrieveModelMixin, GenericViewSet):
serializer_class = MarkerSerializer
queryset = Marker.objects.all().order_by("id")


class ObjectViewset(ListModelMixin, RetrieveModelMixin, GenericViewSet):
serializer_class = ObjectSerializer
queryset = Object.objects.all().order_by("id")
4 changes: 3 additions & 1 deletion src/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def clean(self):

password = self.cleaned_data.get("password")

logged_user = authenticate(self.request, username=user.username, password=password)
logged_user = authenticate(
self.request, username=user.username, password=password
)
if logged_user is None:
raise forms.ValidationError(_("Wrong password!"))

Expand Down
Loading
Loading