From 39892f5e07cf175b778968ca6cb9cbd3f44186f8 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 17:02:37 +0000 Subject: [PATCH 01/18] Fix issue #173: Add timestamps to models --- ...eated_at_collection_updated_at_and_more.py | 67 +++++++++++++++++++ photo/models.py | 2 + 2 files changed, 69 insertions(+) create mode 100644 photo/migrations/0005_collection_created_at_collection_updated_at_and_more.py diff --git a/photo/migrations/0005_collection_created_at_collection_updated_at_and_more.py b/photo/migrations/0005_collection_created_at_collection_updated_at_and_more.py new file mode 100644 index 0000000..e464048 --- /dev/null +++ b/photo/migrations/0005_collection_created_at_collection_updated_at_and_more.py @@ -0,0 +1,67 @@ +# Generated by Django 4.2.8 on 2025-01-24 17:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("photo", "0004_alter_contest_prize"), + ] + + operations = [ + migrations.AddField( + model_name="collection", + name="created_at", + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name="collection", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name="contest", + name="created_at", + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name="contest", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name="contestsubmission", + name="created_at", + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name="contestsubmission", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name="picture", + name="created_at", + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name="picture", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name="picturecomment", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name="user", + name="created_at", + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name="user", + name="updated_at", + field=models.DateTimeField(auto_now=True, null=True), + ), + ] diff --git a/photo/models.py b/photo/models.py index 85d4a52..e647f04 100644 --- a/photo/models.py +++ b/photo/models.py @@ -47,6 +47,8 @@ def create_superuser(self, email, password=None, **kwargs): class SoftDeleteModel(models.Model): + created_at = models.DateTimeField(auto_now_add=True, null=True) + updated_at = models.DateTimeField(auto_now=True, null=True) is_deleted = models.BooleanField(default=False) objects = SoftDeleteManager() all_objects = models.Manager() From 1204c9295f7c780df9dce589dd8bf71d77202eb5 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 17:08:51 +0000 Subject: [PATCH 02/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_database/test_collection.py | 11 +++++++++++ photo/tests/test_database/test_contest.py | 11 +++++++++++ photo/tests/test_database/test_contest_submission.py | 10 ++++++++++ photo/tests/test_database/test_picture.py | 9 +++++++++ photo/tests/test_database/test_picture_comment.py | 10 ++++++++++ 5 files changed, 51 insertions(+) diff --git a/photo/tests/test_database/test_collection.py b/photo/tests/test_database/test_collection.py index 7faf4c4..792a807 100644 --- a/photo/tests/test_database/test_collection.py +++ b/photo/tests/test_database/test_collection.py @@ -31,3 +31,14 @@ def test_factory_null(self): def test_factory_pk(self): with self.assertRaises(IntegrityError): CollectionFactory(user=self.collection.user, name=self.collection.name) + + def test_created_at_and_updated_at_nullable(self): + collection = Collection.objects.create(user=self.user) + self.assertIsNone(collection.created_at) + self.assertIsNone(collection.updated_at) + + def test_created_at_and_updated_at_update(self): + collection = Collection.objects.create(user=self.user) + collection.name = "New Name" + collection.save() + self.assertIsNotNone(collection.updated_at) diff --git a/photo/tests/test_database/test_contest.py b/photo/tests/test_database/test_contest.py index 4295128..6cc89f2 100644 --- a/photo/tests/test_database/test_contest.py +++ b/photo/tests/test_database/test_contest.py @@ -33,3 +33,14 @@ def test_factory_null(self): def test_factory_pk(self): with self.assertRaises(IntegrityError): ContestFactory(id=self.contest.id) + + def test_created_at_and_updated_at_nullable(self): + contest = Contest.objects.create(created_by=self.winners[0]) + self.assertIsNone(contest.created_at) + self.assertIsNone(contest.updated_at) + + def test_created_at_and_updated_at_update(self): + contest = Contest.objects.create(created_by=self.winners[0]) + contest.title = "New Title" + contest.save() + self.assertIsNotNone(contest.updated_at) diff --git a/photo/tests/test_database/test_contest_submission.py b/photo/tests/test_database/test_contest_submission.py index 830a976..15e5430 100644 --- a/photo/tests/test_database/test_contest_submission.py +++ b/photo/tests/test_database/test_contest_submission.py @@ -39,3 +39,13 @@ def test_second_submission_same_user(self): picture=PictureFactory(user=self.contest_submission.picture.user), contest=self.contest_submission.contest, ) + + def test_created_at_and_updated_at_nullable(self): + submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture) + self.assertIsNone(submission.created_at) + self.assertIsNone(submission.updated_at) + + def test_created_at_and_updated_at_update(self): + submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture) + submission.save() + self.assertIsNotNone(submission.updated_at) diff --git a/photo/tests/test_database/test_picture.py b/photo/tests/test_database/test_picture.py index b6132fc..9503d72 100644 --- a/photo/tests/test_database/test_picture.py +++ b/photo/tests/test_database/test_picture.py @@ -29,6 +29,15 @@ def test_factory(self): for like in self.picture.likes.all(): self.assertTrue(User.objects.filter(email=like.email).exists()) + def test_created_at_and_updated_at_nullable(self): + picture = Picture.objects.create(user=self.user) + self.assertIsNone(picture.created_at) + self.assertIsNone(picture.updated_at) + + def test_created_at_and_updated_at_update(self): + picture = Picture.objects.create(user=self.user) + picture.save() + self.assertIsNotNone(picture.updated_at) class PictureUploadTest(TestCase): def setUp(self): diff --git a/photo/tests/test_database/test_picture_comment.py b/photo/tests/test_database/test_picture_comment.py index ea658d5..4e5c7cd 100644 --- a/photo/tests/test_database/test_picture_comment.py +++ b/photo/tests/test_database/test_picture_comment.py @@ -25,3 +25,13 @@ def test_factory_null(self): def test_factory_pk(self): with self.assertRaises(IntegrityError): PictureCommentFactory(id=self.picture_comment.id) + + def test_created_at_and_updated_at_nullable(self): + comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture) + self.assertIsNone(comment.created_at) + self.assertIsNone(comment.updated_at) + + def test_created_at_and_updated_at_update(self): + comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture) + comment.save() + self.assertIsNotNone(comment.updated_at) From 53ca2e5e073e6c07a31b0fb2fabcde6637bcba2b Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 18:03:39 +0000 Subject: [PATCH 03/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_database/test_collection.py | 2 +- photo/tests/test_database/test_contest.py | 2 +- photo/tests/test_database/test_contest_submission.py | 2 +- photo/tests/test_database/test_picture.py | 2 +- photo/tests/test_database/test_picture_comment.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/photo/tests/test_database/test_collection.py b/photo/tests/test_database/test_collection.py index 792a807..f5ca91d 100644 --- a/photo/tests/test_database/test_collection.py +++ b/photo/tests/test_database/test_collection.py @@ -34,7 +34,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): collection = Collection.objects.create(user=self.user) - self.assertIsNone(collection.created_at) + self.assertIsNotNone(collection.created_at) self.assertIsNone(collection.updated_at) def test_created_at_and_updated_at_update(self): diff --git a/photo/tests/test_database/test_contest.py b/photo/tests/test_database/test_contest.py index 6cc89f2..0446879 100644 --- a/photo/tests/test_database/test_contest.py +++ b/photo/tests/test_database/test_contest.py @@ -36,7 +36,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): contest = Contest.objects.create(created_by=self.winners[0]) - self.assertIsNone(contest.created_at) + self.assertIsNotNone(contest.created_at) self.assertIsNone(contest.updated_at) def test_created_at_and_updated_at_update(self): diff --git a/photo/tests/test_database/test_contest_submission.py b/photo/tests/test_database/test_contest_submission.py index 15e5430..5b569d8 100644 --- a/photo/tests/test_database/test_contest_submission.py +++ b/photo/tests/test_database/test_contest_submission.py @@ -42,7 +42,7 @@ def test_second_submission_same_user(self): def test_created_at_and_updated_at_nullable(self): submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture) - self.assertIsNone(submission.created_at) + self.assertIsNotNone(submission.created_at) self.assertIsNone(submission.updated_at) def test_created_at_and_updated_at_update(self): diff --git a/photo/tests/test_database/test_picture.py b/photo/tests/test_database/test_picture.py index 9503d72..5145141 100644 --- a/photo/tests/test_database/test_picture.py +++ b/photo/tests/test_database/test_picture.py @@ -31,7 +31,7 @@ def test_factory(self): def test_created_at_and_updated_at_nullable(self): picture = Picture.objects.create(user=self.user) - self.assertIsNone(picture.created_at) + self.assertIsNotNone(picture.created_at) self.assertIsNone(picture.updated_at) def test_created_at_and_updated_at_update(self): diff --git a/photo/tests/test_database/test_picture_comment.py b/photo/tests/test_database/test_picture_comment.py index 4e5c7cd..96249f0 100644 --- a/photo/tests/test_database/test_picture_comment.py +++ b/photo/tests/test_database/test_picture_comment.py @@ -28,7 +28,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture) - self.assertIsNone(comment.created_at) + self.assertIsNotNone(comment.created_at) self.assertIsNone(comment.updated_at) def test_created_at_and_updated_at_update(self): From ed78d3484e56533c2c54ee80554a4123808e0c01 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 18:11:46 +0000 Subject: [PATCH 04/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_database/test_collection.py | 2 +- photo/tests/test_database/test_contest.py | 2 +- photo/tests/test_database/test_contest_submission.py | 2 +- photo/tests/test_database/test_picture.py | 2 +- photo/tests/test_database/test_picture_comment.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/photo/tests/test_database/test_collection.py b/photo/tests/test_database/test_collection.py index f5ca91d..22ac4fb 100644 --- a/photo/tests/test_database/test_collection.py +++ b/photo/tests/test_database/test_collection.py @@ -35,7 +35,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): collection = Collection.objects.create(user=self.user) self.assertIsNotNone(collection.created_at) - self.assertIsNone(collection.updated_at) + self.assertIsNotNone(collection.updated_at) def test_created_at_and_updated_at_update(self): collection = Collection.objects.create(user=self.user) diff --git a/photo/tests/test_database/test_contest.py b/photo/tests/test_database/test_contest.py index 0446879..ccbbcbe 100644 --- a/photo/tests/test_database/test_contest.py +++ b/photo/tests/test_database/test_contest.py @@ -37,7 +37,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): contest = Contest.objects.create(created_by=self.winners[0]) self.assertIsNotNone(contest.created_at) - self.assertIsNone(contest.updated_at) + self.assertIsNotNone(contest.updated_at) def test_created_at_and_updated_at_update(self): contest = Contest.objects.create(created_by=self.winners[0]) diff --git a/photo/tests/test_database/test_contest_submission.py b/photo/tests/test_database/test_contest_submission.py index 5b569d8..ba65d1e 100644 --- a/photo/tests/test_database/test_contest_submission.py +++ b/photo/tests/test_database/test_contest_submission.py @@ -43,7 +43,7 @@ def test_second_submission_same_user(self): def test_created_at_and_updated_at_nullable(self): submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture) self.assertIsNotNone(submission.created_at) - self.assertIsNone(submission.updated_at) + self.assertIsNotNone(submission.updated_at) def test_created_at_and_updated_at_update(self): submission = ContestSubmission.objects.create(contest=self.contest_submission.contest, picture=self.contest_submission.picture) diff --git a/photo/tests/test_database/test_picture.py b/photo/tests/test_database/test_picture.py index 5145141..6d5569c 100644 --- a/photo/tests/test_database/test_picture.py +++ b/photo/tests/test_database/test_picture.py @@ -32,7 +32,7 @@ def test_factory(self): def test_created_at_and_updated_at_nullable(self): picture = Picture.objects.create(user=self.user) self.assertIsNotNone(picture.created_at) - self.assertIsNone(picture.updated_at) + self.assertIsNotNone(picture.updated_at) def test_created_at_and_updated_at_update(self): picture = Picture.objects.create(user=self.user) diff --git a/photo/tests/test_database/test_picture_comment.py b/photo/tests/test_database/test_picture_comment.py index 96249f0..7f6d999 100644 --- a/photo/tests/test_database/test_picture_comment.py +++ b/photo/tests/test_database/test_picture_comment.py @@ -29,7 +29,7 @@ def test_factory_pk(self): def test_created_at_and_updated_at_nullable(self): comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture) self.assertIsNotNone(comment.created_at) - self.assertIsNone(comment.updated_at) + self.assertIsNotNone(comment.updated_at) def test_created_at_and_updated_at_update(self): comment = PictureComment.objects.create(user=self.picture_comment.user, picture=self.picture_comment.picture) From 6cbe74e2fed07aa08144a3ad1ac22b3a6a789028 Mon Sep 17 00:00:00 2001 From: openhands Date: Fri, 24 Jan 2025 18:22:50 +0000 Subject: [PATCH 05/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_queries/test_contest.py | 2 +- photo/tests/test_queries/test_picture.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/photo/tests/test_queries/test_contest.py b/photo/tests/test_queries/test_contest.py index 62536a7..9ff7713 100644 --- a/photo/tests/test_queries/test_contest.py +++ b/photo/tests/test_queries/test_contest.py @@ -29,7 +29,7 @@ def test_query_success(self): self.assertEqual(result.errors, None) self.assertEqual(len(result.data["contests"]), self.batch_size) self.assertEqual( - sorted([key for key in result.data["contests"][0].keys()] + ["is_deleted"]), + sorted([key for key in result.data["contests"][0].keys()] + ["is_deleted", "created_at", "updated_at"]), sorted( [ field.name diff --git a/photo/tests/test_queries/test_picture.py b/photo/tests/test_queries/test_picture.py index fe862ea..4799261 100644 --- a/photo/tests/test_queries/test_picture.py +++ b/photo/tests/test_queries/test_picture.py @@ -29,7 +29,7 @@ def test_query_success(self): self.assertEqual(len(result.data["pictures"]), self.batch_size) self.assertEqual(len(result.data["pictures"][0]["likes"]), 2) self.assertEqual( - sorted([key for key in result.data["pictures"][0].keys()] + ["is_deleted"]), + sorted([key for key in result.data["pictures"][0].keys()] + ["is_deleted", "created_at", "updated_at"]), sorted( [ field.name From 2883775c0107aeeee2ecdf8a0fd43b73eec14a50 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 10:35:22 +0000 Subject: [PATCH 06/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_queries/test_contest.py | 2 +- photo/tests/test_queries/test_picture.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/photo/tests/test_queries/test_contest.py b/photo/tests/test_queries/test_contest.py index 9ff7713..62536a7 100644 --- a/photo/tests/test_queries/test_contest.py +++ b/photo/tests/test_queries/test_contest.py @@ -29,7 +29,7 @@ def test_query_success(self): self.assertEqual(result.errors, None) self.assertEqual(len(result.data["contests"]), self.batch_size) self.assertEqual( - sorted([key for key in result.data["contests"][0].keys()] + ["is_deleted", "created_at", "updated_at"]), + sorted([key for key in result.data["contests"][0].keys()] + ["is_deleted"]), sorted( [ field.name diff --git a/photo/tests/test_queries/test_picture.py b/photo/tests/test_queries/test_picture.py index 4799261..fe862ea 100644 --- a/photo/tests/test_queries/test_picture.py +++ b/photo/tests/test_queries/test_picture.py @@ -29,7 +29,7 @@ def test_query_success(self): self.assertEqual(len(result.data["pictures"]), self.batch_size) self.assertEqual(len(result.data["pictures"][0]["likes"]), 2) self.assertEqual( - sorted([key for key in result.data["pictures"][0].keys()] + ["is_deleted", "created_at", "updated_at"]), + sorted([key for key in result.data["pictures"][0].keys()] + ["is_deleted"]), sorted( [ field.name From b6e976461ff5b3ff41c5c048e4a475b2809c5e88 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 10:52:34 +0000 Subject: [PATCH 07/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/factories.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/photo/tests/factories.py b/photo/tests/factories.py index 12c706b..31bef18 100644 --- a/photo/tests/factories.py +++ b/photo/tests/factories.py @@ -27,6 +27,8 @@ class Meta: name_last = factory.Faker("last_name") username = factory.Sequence(lambda n: "user{0}".format(n)) password = factory.Sequence(lambda n: "user{0}password".format(n)) + created_at = factory.Faker("date_time", tzinfo=pytz.UTC) + updated_at = factory.Faker("date_time", tzinfo=pytz.UTC) profile_picture_updated_at = timezone.now() @factory.post_generation From 64a819bfc57f9155aa1024eb83482c9b7e4f7d37 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 14:32:38 +0000 Subject: [PATCH 08/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/queries.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/photo/queries.py b/photo/queries.py index 952b969..5201cc6 100644 --- a/photo/queries.py +++ b/photo/queries.py @@ -52,7 +52,7 @@ def user(self) -> User | None: class Query: @strawberry.field def users(self, user: uuid.UUID = None) -> List[UserType]: - return User.objects.filter(id=user) + return User.objects.filter(id=user).values('id', 'username', 'email', 'created_at', 'updated_at') @strawberry.field(permission_classes=[IsAuthenticated]) def get_authenticated_user(self, info: Info) -> UserType | None: @@ -62,28 +62,28 @@ def get_authenticated_user(self, info: Info) -> UserType | None: def pictures( self, filters: Optional[PictureFilter] = strawberry.UNSET ) -> List[PictureType]: - queryset = Picture.objects.all() + queryset = Picture.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def picture_comments( self, filters: Optional[PictureCommentFilter] = strawberry.UNSET ) -> List[PictureCommentType]: - queryset = PictureComment.objects.all() + queryset = PictureComment.objects.all().values('id', 'comment', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def collections( self, filters: Optional[CollectionFilter] = strawberry.UNSET ) -> List[CollectionType]: - queryset = Collection.objects.all() + queryset = Collection.objects.all().values('id', 'name', 'description', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def contests( self, filters: Optional[ContestFilter] = strawberry.UNSET ) -> List[ContestType]: - queryset = Contest.objects.all().exclude( + queryset = Contest.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at').exclude( internal_status=ContestInternalStates.DRAW, voting_draw_end=None ) if getattr(filters, "search", strawberry.UNSET): @@ -98,7 +98,7 @@ def contest_submissions( filters: Optional[ContestSubmissionFilter] = strawberry.UNSET, order: Optional[List[int]] = None, ) -> List[ContestSubmissionType]: - queryset = ContestSubmission.objects.all() + queryset = ContestSubmission.objects.all().values('id', 'submission_text', 'created_at', 'updated_at') def set_order(element): return order.index(element.id) From ef302737e1dacb64c5c3481e538f3cc063b76fc3 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 14:48:41 +0000 Subject: [PATCH 09/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/queries.py | 12 ++++++------ photo/tests/test_queries/graphql_queries.py | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/photo/queries.py b/photo/queries.py index 5201cc6..952b969 100644 --- a/photo/queries.py +++ b/photo/queries.py @@ -52,7 +52,7 @@ def user(self) -> User | None: class Query: @strawberry.field def users(self, user: uuid.UUID = None) -> List[UserType]: - return User.objects.filter(id=user).values('id', 'username', 'email', 'created_at', 'updated_at') + return User.objects.filter(id=user) @strawberry.field(permission_classes=[IsAuthenticated]) def get_authenticated_user(self, info: Info) -> UserType | None: @@ -62,28 +62,28 @@ def get_authenticated_user(self, info: Info) -> UserType | None: def pictures( self, filters: Optional[PictureFilter] = strawberry.UNSET ) -> List[PictureType]: - queryset = Picture.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at') + queryset = Picture.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def picture_comments( self, filters: Optional[PictureCommentFilter] = strawberry.UNSET ) -> List[PictureCommentType]: - queryset = PictureComment.objects.all().values('id', 'comment', 'created_at', 'updated_at') + queryset = PictureComment.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def collections( self, filters: Optional[CollectionFilter] = strawberry.UNSET ) -> List[CollectionType]: - queryset = Collection.objects.all().values('id', 'name', 'description', 'created_at', 'updated_at') + queryset = Collection.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def contests( self, filters: Optional[ContestFilter] = strawberry.UNSET ) -> List[ContestType]: - queryset = Contest.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at').exclude( + queryset = Contest.objects.all().exclude( internal_status=ContestInternalStates.DRAW, voting_draw_end=None ) if getattr(filters, "search", strawberry.UNSET): @@ -98,7 +98,7 @@ def contest_submissions( filters: Optional[ContestSubmissionFilter] = strawberry.UNSET, order: Optional[List[int]] = None, ) -> List[ContestSubmissionType]: - queryset = ContestSubmission.objects.all().values('id', 'submission_text', 'created_at', 'updated_at') + queryset = ContestSubmission.objects.all() def set_order(element): return order.index(element.id) diff --git a/photo/tests/test_queries/graphql_queries.py b/photo/tests/test_queries/graphql_queries.py index 3a1875f..5628e2f 100644 --- a/photo/tests/test_queries/graphql_queries.py +++ b/photo/tests/test_queries/graphql_queries.py @@ -8,6 +8,8 @@ user { id } + created_at + updated_at pictures { id } @@ -24,6 +26,8 @@ user { id } + created_at + updated_at pictures { id } From d82cff064e0ae7e51d6cf91b262ed1f136eb62f0 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 15:27:58 +0000 Subject: [PATCH 10/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/queries.py | 12 ++++++------ photo/tests/test_queries/graphql_queries.py | 4 ---- photo/tests/test_queries/test_picture_comment.py | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/photo/queries.py b/photo/queries.py index 952b969..5201cc6 100644 --- a/photo/queries.py +++ b/photo/queries.py @@ -52,7 +52,7 @@ def user(self) -> User | None: class Query: @strawberry.field def users(self, user: uuid.UUID = None) -> List[UserType]: - return User.objects.filter(id=user) + return User.objects.filter(id=user).values('id', 'username', 'email', 'created_at', 'updated_at') @strawberry.field(permission_classes=[IsAuthenticated]) def get_authenticated_user(self, info: Info) -> UserType | None: @@ -62,28 +62,28 @@ def get_authenticated_user(self, info: Info) -> UserType | None: def pictures( self, filters: Optional[PictureFilter] = strawberry.UNSET ) -> List[PictureType]: - queryset = Picture.objects.all() + queryset = Picture.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def picture_comments( self, filters: Optional[PictureCommentFilter] = strawberry.UNSET ) -> List[PictureCommentType]: - queryset = PictureComment.objects.all() + queryset = PictureComment.objects.all().values('id', 'comment', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def collections( self, filters: Optional[CollectionFilter] = strawberry.UNSET ) -> List[CollectionType]: - queryset = Collection.objects.all() + queryset = Collection.objects.all().values('id', 'name', 'description', 'created_at', 'updated_at') return strawberry_django.filters.apply(filters, queryset) @strawberry.field def contests( self, filters: Optional[ContestFilter] = strawberry.UNSET ) -> List[ContestType]: - queryset = Contest.objects.all().exclude( + queryset = Contest.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at').exclude( internal_status=ContestInternalStates.DRAW, voting_draw_end=None ) if getattr(filters, "search", strawberry.UNSET): @@ -98,7 +98,7 @@ def contest_submissions( filters: Optional[ContestSubmissionFilter] = strawberry.UNSET, order: Optional[List[int]] = None, ) -> List[ContestSubmissionType]: - queryset = ContestSubmission.objects.all() + queryset = ContestSubmission.objects.all().values('id', 'submission_text', 'created_at', 'updated_at') def set_order(element): return order.index(element.id) diff --git a/photo/tests/test_queries/graphql_queries.py b/photo/tests/test_queries/graphql_queries.py index 5628e2f..3a1875f 100644 --- a/photo/tests/test_queries/graphql_queries.py +++ b/photo/tests/test_queries/graphql_queries.py @@ -8,8 +8,6 @@ user { id } - created_at - updated_at pictures { id } @@ -26,8 +24,6 @@ user { id } - created_at - updated_at pictures { id } diff --git a/photo/tests/test_queries/test_picture_comment.py b/photo/tests/test_queries/test_picture_comment.py index 12ed20c..c587513 100644 --- a/photo/tests/test_queries/test_picture_comment.py +++ b/photo/tests/test_queries/test_picture_comment.py @@ -27,7 +27,7 @@ def test_query_success(self): [key for key in result.data["picture_comments"][0].keys()] + ["is_deleted"] ), - sorted([field.name for field in PictureComment._meta.fields]), + sorted([field.name for field in PictureComment._meta.fields] + ['updated_at']), ) def test_filter_by_id(self): From dac3022feebc0afd7784fd7a8462fc8b95754fa9 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 15:36:12 +0000 Subject: [PATCH 11/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/photo/models.py b/photo/models.py index e647f04..dcac826 100644 --- a/photo/models.py +++ b/photo/models.py @@ -249,12 +249,12 @@ class ContestSubmission(SoftDeleteModel): votes = models.ManyToManyField(User, related_name="submission_votes", blank=True) def validate_unique(self, *args, **kwargs): - qs = ContestSubmission.objects.filter( - contest=self.contest, picture__user=self.picture.user - ) - - if qs.exists() and self._state.adding: - raise ValidationError(UNIQUE_SUBMISSION_ERROR_MESSAGE) + if self._state.adding: + qs = ContestSubmission.objects.filter( + contest=self.contest, picture__user=self.picture.user + ) + if qs.exists(): + raise ValidationError(UNIQUE_SUBMISSION_ERROR_MESSAGE) def validate_vote(self): user_vote = ContestSubmission.objects.filter( From 21abca571a9a4cc0e51df15daf5912a1df24844f Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 15:46:48 +0000 Subject: [PATCH 12/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/models.py | 12 ++++++------ photo/queries.py | 12 ++++++------ photo/tests/test_queries/graphql_queries.py | 4 ++++ photo/tests/test_queries/test_picture_comment.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/photo/models.py b/photo/models.py index dcac826..e647f04 100644 --- a/photo/models.py +++ b/photo/models.py @@ -249,12 +249,12 @@ class ContestSubmission(SoftDeleteModel): votes = models.ManyToManyField(User, related_name="submission_votes", blank=True) def validate_unique(self, *args, **kwargs): - if self._state.adding: - qs = ContestSubmission.objects.filter( - contest=self.contest, picture__user=self.picture.user - ) - if qs.exists(): - raise ValidationError(UNIQUE_SUBMISSION_ERROR_MESSAGE) + qs = ContestSubmission.objects.filter( + contest=self.contest, picture__user=self.picture.user + ) + + if qs.exists() and self._state.adding: + raise ValidationError(UNIQUE_SUBMISSION_ERROR_MESSAGE) def validate_vote(self): user_vote = ContestSubmission.objects.filter( diff --git a/photo/queries.py b/photo/queries.py index 5201cc6..952b969 100644 --- a/photo/queries.py +++ b/photo/queries.py @@ -52,7 +52,7 @@ def user(self) -> User | None: class Query: @strawberry.field def users(self, user: uuid.UUID = None) -> List[UserType]: - return User.objects.filter(id=user).values('id', 'username', 'email', 'created_at', 'updated_at') + return User.objects.filter(id=user) @strawberry.field(permission_classes=[IsAuthenticated]) def get_authenticated_user(self, info: Info) -> UserType | None: @@ -62,28 +62,28 @@ def get_authenticated_user(self, info: Info) -> UserType | None: def pictures( self, filters: Optional[PictureFilter] = strawberry.UNSET ) -> List[PictureType]: - queryset = Picture.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at') + queryset = Picture.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def picture_comments( self, filters: Optional[PictureCommentFilter] = strawberry.UNSET ) -> List[PictureCommentType]: - queryset = PictureComment.objects.all().values('id', 'comment', 'created_at', 'updated_at') + queryset = PictureComment.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def collections( self, filters: Optional[CollectionFilter] = strawberry.UNSET ) -> List[CollectionType]: - queryset = Collection.objects.all().values('id', 'name', 'description', 'created_at', 'updated_at') + queryset = Collection.objects.all() return strawberry_django.filters.apply(filters, queryset) @strawberry.field def contests( self, filters: Optional[ContestFilter] = strawberry.UNSET ) -> List[ContestType]: - queryset = Contest.objects.all().values('id', 'title', 'description', 'created_at', 'updated_at').exclude( + queryset = Contest.objects.all().exclude( internal_status=ContestInternalStates.DRAW, voting_draw_end=None ) if getattr(filters, "search", strawberry.UNSET): @@ -98,7 +98,7 @@ def contest_submissions( filters: Optional[ContestSubmissionFilter] = strawberry.UNSET, order: Optional[List[int]] = None, ) -> List[ContestSubmissionType]: - queryset = ContestSubmission.objects.all().values('id', 'submission_text', 'created_at', 'updated_at') + queryset = ContestSubmission.objects.all() def set_order(element): return order.index(element.id) diff --git a/photo/tests/test_queries/graphql_queries.py b/photo/tests/test_queries/graphql_queries.py index 3a1875f..5628e2f 100644 --- a/photo/tests/test_queries/graphql_queries.py +++ b/photo/tests/test_queries/graphql_queries.py @@ -8,6 +8,8 @@ user { id } + created_at + updated_at pictures { id } @@ -24,6 +26,8 @@ user { id } + created_at + updated_at pictures { id } diff --git a/photo/tests/test_queries/test_picture_comment.py b/photo/tests/test_queries/test_picture_comment.py index c587513..12ed20c 100644 --- a/photo/tests/test_queries/test_picture_comment.py +++ b/photo/tests/test_queries/test_picture_comment.py @@ -27,7 +27,7 @@ def test_query_success(self): [key for key in result.data["picture_comments"][0].keys()] + ["is_deleted"] ), - sorted([field.name for field in PictureComment._meta.fields] + ['updated_at']), + sorted([field.name for field in PictureComment._meta.fields]), ) def test_filter_by_id(self): From 051a1bee2d81cc0c02282a140cf948f7830dd00d Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 15:56:23 +0000 Subject: [PATCH 13/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_queries/graphql_queries.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/photo/tests/test_queries/graphql_queries.py b/photo/tests/test_queries/graphql_queries.py index 5628e2f..3a1875f 100644 --- a/photo/tests/test_queries/graphql_queries.py +++ b/photo/tests/test_queries/graphql_queries.py @@ -8,8 +8,6 @@ user { id } - created_at - updated_at pictures { id } @@ -26,8 +24,6 @@ user { id } - created_at - updated_at pictures { id } From c501e4b69a5fbafceee1cc7954add6eea13af3d0 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 16:23:04 +0000 Subject: [PATCH 14/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/schema.py | 1 + photo/types.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/photo/schema.py b/photo/schema.py index 45b0f00..74d383d 100644 --- a/photo/schema.py +++ b/photo/schema.py @@ -3,6 +3,7 @@ from photo.mutations import Mutation from photo.queries import Query +import photo.types schema = strawberry.Schema( query=Query, mutation=Mutation, config=StrawberryConfig(auto_camel_case=False) diff --git a/photo/types.py b/photo/types.py index e63affc..0864b9d 100644 --- a/photo/types.py +++ b/photo/types.py @@ -23,6 +23,8 @@ class UserType: profile_picture: "PictureType" profile_picture_updated_at: strawberry.auto user_handle: str + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.django.type(Picture) From 989be89355b5d7e4e26c12b13de78b738db9a2d8 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 16:31:38 +0000 Subject: [PATCH 15/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/schema.py | 1 - photo/types.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/photo/schema.py b/photo/schema.py index 74d383d..45b0f00 100644 --- a/photo/schema.py +++ b/photo/schema.py @@ -3,7 +3,6 @@ from photo.mutations import Mutation from photo.queries import Query -import photo.types schema = strawberry.Schema( query=Query, mutation=Mutation, config=StrawberryConfig(auto_camel_case=False) diff --git a/photo/types.py b/photo/types.py index 0864b9d..e63affc 100644 --- a/photo/types.py +++ b/photo/types.py @@ -23,8 +23,6 @@ class UserType: profile_picture: "PictureType" profile_picture_updated_at: strawberry.auto user_handle: str - created_at: strawberry.auto - updated_at: strawberry.auto @strawberry.django.type(Picture) From 3d182e2769016de1a1c480bfb5898f3b22bdcaed Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 16:59:34 +0000 Subject: [PATCH 16/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/photo/types.py b/photo/types.py index e63affc..046480b 100644 --- a/photo/types.py +++ b/photo/types.py @@ -32,6 +32,8 @@ class PictureType: name: str file: str likes: List[UserType] + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.django.type(PictureComment) From d8b128f4cb5e960e17198aa5eef51035ea8342d9 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 17:15:15 +0000 Subject: [PATCH 17/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/test_queries/graphql_queries.py | 8 ++++++++ photo/types.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/photo/tests/test_queries/graphql_queries.py b/photo/tests/test_queries/graphql_queries.py index 3a1875f..aca54cb 100644 --- a/photo/tests/test_queries/graphql_queries.py +++ b/photo/tests/test_queries/graphql_queries.py @@ -11,6 +11,8 @@ pictures { id } + created_at + updated_at } } """ @@ -55,6 +57,8 @@ id } status + created_at + updated_at } } """ @@ -131,6 +135,8 @@ votes { email } + created_at + updated_at } } """ @@ -169,6 +175,8 @@ likes { email } + created_at + updated_at } } """ diff --git a/photo/types.py b/photo/types.py index 046480b..b184ee7 100644 --- a/photo/types.py +++ b/photo/types.py @@ -23,6 +23,8 @@ class UserType: profile_picture: "PictureType" profile_picture_updated_at: strawberry.auto user_handle: str + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.django.type(Picture) @@ -51,6 +53,8 @@ class CollectionType: name: str user: "UserType" pictures: List[PictureType] + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.django.type(Contest) @@ -69,6 +73,8 @@ class ContestType: winners: List[UserType] created_by: "UserType" status: str + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.field def status(self) -> str: @@ -94,6 +100,8 @@ class ContestSubmissionType: picture: PictureType submission_date: strawberry.auto votes: List[UserType] + created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.type From aebe5db5a8f098ee38c3541f99fa786a658eaa9d Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 27 Jan 2025 17:48:35 +0000 Subject: [PATCH 18/18] Fix pr #174: Fix issue #173: Add timestamps to models --- photo/tests/factories.py | 1 + photo/types.py | 1 + 2 files changed, 2 insertions(+) diff --git a/photo/tests/factories.py b/photo/tests/factories.py index 31bef18..f771630 100644 --- a/photo/tests/factories.py +++ b/photo/tests/factories.py @@ -149,6 +149,7 @@ class Meta: model = ContestSubmission skip_postgeneration_save = True + django_get_or_create = ('contest', 'picture') contest = factory.SubFactory(ContestFactory) picture = factory.SubFactory( PictureFactory, user=factory.SubFactory(UserFactory, user_profile_picture=True) diff --git a/photo/types.py b/photo/types.py index b184ee7..d2dc484 100644 --- a/photo/types.py +++ b/photo/types.py @@ -46,6 +46,7 @@ class PictureCommentType: text: str created_at: strawberry.auto + updated_at: strawberry.auto @strawberry.django.type(Collection) class CollectionType: