From e96ea1e1b327e5ab843b1dd0f4da5a37bc49e1aa Mon Sep 17 00:00:00 2001 From: Tam Le Date: Thu, 10 Oct 2024 17:07:21 +0200 Subject: [PATCH 1/4] Created factory for album --- app/gallery/factories/_init_.py | 1 + app/gallery/factories/album_factory.py | 15 +++++++++++++++ app/gallery/views/album.py | 2 +- app/tests/gallery/_init_.py | 0 app/tests/gallery/test_album_sort.py | 6 ++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/gallery/factories/_init_.py create mode 100644 app/gallery/factories/album_factory.py create mode 100644 app/tests/gallery/_init_.py create mode 100644 app/tests/gallery/test_album_sort.py diff --git a/app/gallery/factories/_init_.py b/app/gallery/factories/_init_.py new file mode 100644 index 000000000..22079f972 --- /dev/null +++ b/app/gallery/factories/_init_.py @@ -0,0 +1 @@ +from app.gallery.factories.album_factory import AlbumFactory diff --git a/app/gallery/factories/album_factory.py b/app/gallery/factories/album_factory.py new file mode 100644 index 000000000..e2abd6592 --- /dev/null +++ b/app/gallery/factories/album_factory.py @@ -0,0 +1,15 @@ +import factory +from factory.django import DjangoModelFactory + +from app.gallery.models.album import Album + + +class AlbumFactory(DjangoModelFactory): + class Meta: + model = Album + + id = factory.Sequence(lambda n: f"picture_{n}") + image = factory.Faker("image") + title = factory.Faker("title") + image_alt = factory.Faker("image_alt") + description = factory.Faker("description") diff --git a/app/gallery/views/album.py b/app/gallery/views/album.py index 36a1ce41c..cf09863a9 100644 --- a/app/gallery/views/album.py +++ b/app/gallery/views/album.py @@ -12,7 +12,7 @@ class AlbumViewSet(BaseViewSet): serializer_class = AlbumSerializer - queryset = Album.objects.all() + queryset = Album.objects.all().order_by("-created_at") permission_classes = [BasicViewPermission] lookup_field = "id" pagination_class = BasePagination diff --git a/app/tests/gallery/_init_.py b/app/tests/gallery/_init_.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/tests/gallery/test_album_sort.py b/app/tests/gallery/test_album_sort.py new file mode 100644 index 000000000..d22dab556 --- /dev/null +++ b/app/tests/gallery/test_album_sort.py @@ -0,0 +1,6 @@ +from datetime import timedelta + +from django.utils import timezone +from rest_framework import status + +import pytest From 73ae12a389001adc72501466e556064932a0610d Mon Sep 17 00:00:00 2001 From: Tam Le Date: Mon, 21 Oct 2024 16:50:32 +0200 Subject: [PATCH 2/4] Fixed the order method in albums --- app/gallery/models/album.py | 3 +++ app/gallery/views/album.py | 2 +- app/tests/gallery/test_album_sort.py | 6 ------ 3 files changed, 4 insertions(+), 7 deletions(-) delete mode 100644 app/tests/gallery/test_album_sort.py diff --git a/app/gallery/models/album.py b/app/gallery/models/album.py index 43dfe6722..b3caf6821 100644 --- a/app/gallery/models/album.py +++ b/app/gallery/models/album.py @@ -18,6 +18,9 @@ class Album(BaseModel, BasePermissionModel, OptionalImage): slug = models.SlugField(max_length=50, primary_key=False) write_access = AdminGroup.all() + class Meta: + ordering = ["-created_at"] + def __str__(self): return self.title diff --git a/app/gallery/views/album.py b/app/gallery/views/album.py index cf09863a9..36a1ce41c 100644 --- a/app/gallery/views/album.py +++ b/app/gallery/views/album.py @@ -12,7 +12,7 @@ class AlbumViewSet(BaseViewSet): serializer_class = AlbumSerializer - queryset = Album.objects.all().order_by("-created_at") + queryset = Album.objects.all() permission_classes = [BasicViewPermission] lookup_field = "id" pagination_class = BasePagination diff --git a/app/tests/gallery/test_album_sort.py b/app/tests/gallery/test_album_sort.py deleted file mode 100644 index d22dab556..000000000 --- a/app/tests/gallery/test_album_sort.py +++ /dev/null @@ -1,6 +0,0 @@ -from datetime import timedelta - -from django.utils import timezone -from rest_framework import status - -import pytest From e9488a8862be39746100a578475d295e9c3da6b2 Mon Sep 17 00:00:00 2001 From: Tam Le Date: Mon, 21 Oct 2024 17:13:01 +0200 Subject: [PATCH 3/4] Fixed linting --- app/gallery/factories/_init_.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/gallery/factories/_init_.py b/app/gallery/factories/_init_.py index 22079f972..e69de29bb 100644 --- a/app/gallery/factories/_init_.py +++ b/app/gallery/factories/_init_.py @@ -1 +0,0 @@ -from app.gallery.factories.album_factory import AlbumFactory From 9eb34a9fd07a8dc7a35fe6e168a43d8d6e04a32b Mon Sep 17 00:00:00 2001 From: Tam Le Date: Mon, 21 Oct 2024 19:01:24 +0200 Subject: [PATCH 4/4] run migrations --- .../migrations/0003_alter_album_options.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/gallery/migrations/0003_alter_album_options.py diff --git a/app/gallery/migrations/0003_alter_album_options.py b/app/gallery/migrations/0003_alter_album_options.py new file mode 100644 index 000000000..5d8f724bd --- /dev/null +++ b/app/gallery/migrations/0003_alter_album_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.5 on 2024-10-21 17:00 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("gallery", "0002_remove_picture_album_album_id_alter_album_slug"), + ] + + operations = [ + migrations.AlterModelOptions( + name="album", + options={"ordering": ["-created_at"]}, + ), + ]