From b43bdd3e1558c11ab4c82ca79f7eed5d07021521 Mon Sep 17 00:00:00 2001 From: AndrzejMorawski00 Date: Sun, 27 Oct 2024 20:35:51 +0100 Subject: [PATCH 1/4] remove duplicate objects from queryset --- zapisy/apps/theses/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zapisy/apps/theses/models.py b/zapisy/apps/theses/models.py index e9167cdd8a..bc421bfa19 100644 --- a/zapisy/apps/theses/models.py +++ b/zapisy/apps/theses/models.py @@ -49,7 +49,7 @@ def visible(self, user): (~Q(status=ThesisStatus.BEING_EVALUATED) & ~Q(status=ThesisStatus.RETURNED_FOR_CORRECTIONS)) | Q(advisor__user=user) | Q(supporting_advisor__user=user) | - Q(students__user=user)) + Q(students__user=user)).distinct() class Thesis(models.Model): From 7aa8c50360a720a25ac9be399fe204264665cc17 Mon Sep 17 00:00:00 2001 From: AndrzejMorawski00 Date: Wed, 27 Nov 2024 21:54:23 +0100 Subject: [PATCH 2/4] change queryset to prevent duplicates --- zapisy/apps/theses/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zapisy/apps/theses/models.py b/zapisy/apps/theses/models.py index bc421bfa19..a045114667 100644 --- a/zapisy/apps/theses/models.py +++ b/zapisy/apps/theses/models.py @@ -45,11 +45,12 @@ class ThesesQuerySet(models.QuerySet): def visible(self, user): if user.is_staff or is_theses_board_member(user): return self + student_theses = self.filter(students__user=user) return self.filter( (~Q(status=ThesisStatus.BEING_EVALUATED) & ~Q(status=ThesisStatus.RETURNED_FOR_CORRECTIONS)) | Q(advisor__user=user) | Q(supporting_advisor__user=user) | - Q(students__user=user)).distinct() + Q(id__in=student_theses)) class Thesis(models.Model): From e162e47cb1117cbe23b1edc16c0871fe83bb42db Mon Sep 17 00:00:00 2001 From: AndrzejMorawski00 Date: Tue, 3 Dec 2024 22:01:54 +0100 Subject: [PATCH 3/4] move filter logic into user_theses object --- zapisy/apps/theses/models.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/zapisy/apps/theses/models.py b/zapisy/apps/theses/models.py index a045114667..02b2bd6600 100644 --- a/zapisy/apps/theses/models.py +++ b/zapisy/apps/theses/models.py @@ -45,13 +45,10 @@ class ThesesQuerySet(models.QuerySet): def visible(self, user): if user.is_staff or is_theses_board_member(user): return self - student_theses = self.filter(students__user=user) - return self.filter( - (~Q(status=ThesisStatus.BEING_EVALUATED) & ~Q(status=ThesisStatus.RETURNED_FOR_CORRECTIONS)) | - Q(advisor__user=user) | - Q(supporting_advisor__user=user) | - Q(id__in=student_theses)) + user_theses = self.filter(Q(students__user=user) | Q(advisor__user=user) | Q(supporting_advisor__user=user)) + return self.filter((~Q(status=ThesisStatus.BEING_EVALUATED) & + ~Q(status=ThesisStatus.RETURNED_FOR_CORRECTIONS)) | Q(id__in=user_theses)) class Thesis(models.Model): """Represents a thesis in the theses system. From 044e68304f1df1006e1236d941d4886cb358d09e Mon Sep 17 00:00:00 2001 From: AndrzejMorawski00 Date: Tue, 3 Dec 2024 22:11:43 +0100 Subject: [PATCH 4/4] I guess I know how it works now --- zapisy/apps/theses/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/zapisy/apps/theses/models.py b/zapisy/apps/theses/models.py index 02b2bd6600..5eb773cc40 100644 --- a/zapisy/apps/theses/models.py +++ b/zapisy/apps/theses/models.py @@ -50,6 +50,7 @@ def visible(self, user): return self.filter((~Q(status=ThesisStatus.BEING_EVALUATED) & ~Q(status=ThesisStatus.RETURNED_FOR_CORRECTIONS)) | Q(id__in=user_theses)) + class Thesis(models.Model): """Represents a thesis in the theses system.