diff --git a/scipost_django/ontology/models/branch.py b/scipost_django/ontology/models/branch.py index 7f469cfe968ddbca1c820a695c095fd5d70256ac..4f12ab415ea40eb283707455931b6caf065113c4 100644 --- a/scipost_django/ontology/models/branch.py +++ b/scipost_django/ontology/models/branch.py @@ -34,4 +34,4 @@ class Branch(models.Model): @property def submissions(self): - return Submission.objects.public_newest().filter(acad_field__branch=self.id) + return Submission.objects.public_latest().filter(acad_field__branch=self.id) diff --git a/scipost_django/ontology/templates/ontology/_topic_card.html b/scipost_django/ontology/templates/ontology/_topic_card.html index 964049117a2ebd95fef7d5e7af54f795ae03964d..5ee6772a44f02edf8809f1fe1358fd1c1b9f2c6d 100644 --- a/scipost_django/ontology/templates/ontology/_topic_card.html +++ b/scipost_django/ontology/templates/ontology/_topic_card.html @@ -94,7 +94,7 @@ </div> <div class="card-body"> <ul> - {% for sub in topic.submission_set.public_newest.unpublished %} + {% for sub in topic.submission_set.public_latest.unpublished %} <li> <a href="{{ sub.get_absolute_url }}">{{ sub.title }}</a> <br>by {{ sub.author_list }} diff --git a/scipost_django/profiles/templates/profiles/_profile_card.html b/scipost_django/profiles/templates/profiles/_profile_card.html index 9eb1ceb52c9a76c246bd8cccee1a0059f1bdf3c4..f631202abef1ae39c40c74fc09da0dea853ddd5d 100644 --- a/scipost_django/profiles/templates/profiles/_profile_card.html +++ b/scipost_django/profiles/templates/profiles/_profile_card.html @@ -130,7 +130,7 @@ </div> <div class="card-body"> <ul> - {% for sub in profile.contributor.submissions.public_newest.unpublished %} + {% for sub in profile.contributor.submissions.public_latest.unpublished %} <li><a href="{{ sub.get_absolute_url }}">{{ sub }}</a></li> {% empty %} <li>No ongoing Submission found</li> diff --git a/scipost_django/submissions/api/viewsets/submission.py b/scipost_django/submissions/api/viewsets/submission.py index 915a8c5e805e9a13e3cd40860dffc7bf67ed5f75..b03decaebf67e9d0bd212d82506f1c841b7de387 100644 --- a/scipost_django/submissions/api/viewsets/submission.py +++ b/scipost_django/submissions/api/viewsets/submission.py @@ -41,7 +41,7 @@ class SubmissionPublicAPIViewSet( class SubmissionPublicSearchAPIViewSet( FilteringOptionsActionMixin, viewsets.ReadOnlyModelViewSet ): - queryset = Submission.objects.public_newest().unpublished() + queryset = Submission.objects.public_latest().unpublished() permission_classes = [ AllowAny, ] diff --git a/scipost_django/submissions/forms.py b/scipost_django/submissions/forms.py index 3d30b3edb5857bc3540253880054ca57d75d48f5..0dd9a33dc81efd2118d846fd8e46642fbc0f6012 100644 --- a/scipost_django/submissions/forms.py +++ b/scipost_django/submissions/forms.py @@ -131,7 +131,7 @@ class SubmissionSearchForm(forms.Form): """ Return all Submission objects fitting search criteria. """ - submissions = Submission.objects.public_newest().unpublished() + submissions = Submission.objects.public_latest().unpublished() if self.acad_field_slug and self.acad_field_slug != "all": submissions = submissions.filter(acad_field__slug=self.acad_field_slug) if self.specialty_slug and self.specialty_slug != "all": @@ -496,7 +496,7 @@ class SubmissionOldSearchForm(forms.Form): def search_results(self): """Return all Submission objects according to search.""" - return Submission.objects.public_newest().filter( + return Submission.objects.public_latest().filter( title__icontains=self.cleaned_data.get("title", ""), author_list__icontains=self.cleaned_data.get("author", ""), abstract__icontains=self.cleaned_data.get("abstract", ""), diff --git a/scipost_django/submissions/managers/submission.py b/scipost_django/submissions/managers/submission.py index e235a5212dcdfd8a460726479d2116b371ca4abe..16086616a5fbdc6211fbc151daf98df971cfb619 100644 --- a/scipost_django/submissions/managers/submission.py +++ b/scipost_django/submissions/managers/submission.py @@ -11,25 +11,6 @@ from .. import constants class SubmissionQuerySet(models.QuerySet): - def _newest_version_only(self, queryset): - """ - TODO: Make more efficient... with agregation or whatever. - TODO: just replace this by the `latest` filter defined below. - - The current Queryset should return only the latest version - of the submissions. - - Method only compatible with PostgreSQL - """ - # This method used a double query, which is a consequence of the complex distinct() - # filter combined with the PostGresQL engine. Without the double query, ordering - # on a specific field after filtering seems impossible. - ids = ( - queryset.order_by("thread_hash", "-submission_date") - .distinct("thread_hash") - .values_list("id", flat=True) - ) - return queryset.filter(id__in=ids) def latest(self, queryset): return queryset.exclude(status=self.model.RESUBMITTED) @@ -181,12 +162,12 @@ class SubmissionQuerySet(models.QuerySet): status__in=[self.model.RESUBMITTED, self.model.PUBLISHED] ) - def public_newest(self): + def public_latest(self): """ - This query contains set of public() submissions, filtered to only the newest available + This query contains set of public() submissions, filtered to only the latest available version. """ - return self._newest_version_only(self.public()) + return self.latest(self.public()) def treated(self): """This query returns all Submissions that are presumed to be 'done'.""" @@ -246,11 +227,11 @@ class SubmissionQuerySet(models.QuerySet): def rejected(self): """Return rejected Submissions.""" - return self._newest_version_only(self.filter(status=self.model.REJECTED)) + return self.latest(self.filter(status=self.model.REJECTED)) def withdrawn(self): """Return withdrawn Submissions.""" - return self._newest_version_only(self.filter(status=self.model.WITHDRAWN)) + return self.latest(self.filter(status=self.model.WITHDRAWN)) def open_for_reporting(self): """Return Submissions open for reporting.""" diff --git a/scipost_django/submissions/search_indexes.py b/scipost_django/submissions/search_indexes.py index 56f906b481aded7ed613577d2e3b66b2ad1808fa..38b5f1fbc98931a0b1df72965c3c371534fc7eab 100644 --- a/scipost_django/submissions/search_indexes.py +++ b/scipost_django/submissions/search_indexes.py @@ -23,4 +23,4 @@ class SubmissionIndex(indexes.SearchIndex, indexes.Indexable): def index_queryset(self, using=None): """Used when the entire index for model is updated.""" - return self.get_model().objects.public_newest() + return self.get_model().objects.public_latest() diff --git a/scipost_django/submissions/views.py b/scipost_django/submissions/views.py index bd604548a17a3a6e9bf5f4d7585c36d6a5d35722..7bb49b9c8ac7c1298ec4dc316419cf856ca2316d 100644 --- a/scipost_django/submissions/views.py +++ b/scipost_django/submissions/views.py @@ -551,7 +551,7 @@ class SubmissionListView(PaginationMixin, ListView): def get_queryset(self): """Return queryset, filtered with GET request data if given.""" - queryset = Submission.objects.public_newest() + queryset = Submission.objects.public_latest() self.form = self.form(self.request.GET) if "field" in self.request.GET: queryset = queryset.filter(acad_field__slug=self.request.GET["field"])