From 6a7b45904fc14f135c9c8621166e69e19b9328cf Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Wed, 20 Sep 2023 16:55:06 +0200 Subject: [PATCH] rename collections related field on submissions --- .../journals/_publication_li_content-alt.html | 2 +- .../journals/_publication_li_content.html | 2 +- .../journals/_publication_summary.html | 2 +- .../journals/templates/journals/about.html | 4 +-- .../templates/journals/journal_detail.html | 6 ++-- .../templates/journals/journal_list.html | 4 +-- .../scipost/portal/_hx_journals.html | 4 +-- scipost_django/scipost/views.py | 10 +++--- .../0008_alter_collections_related_names.py | 36 +++++++++++++++++++ scipost_django/series/models.py | 23 +++++++++--- scipost_django/series/views.py | 2 +- scipost_django/submissions/admin.py | 9 +++++ .../submissions/_submission_summary.html | 6 ++-- 13 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 scipost_django/series/migrations/0008_alter_collections_related_names.py diff --git a/scipost_django/journals/templates/journals/_publication_li_content-alt.html b/scipost_django/journals/templates/journals/_publication_li_content-alt.html index 4d112e20a..ad874fb04 100644 --- a/scipost_django/journals/templates/journals/_publication_li_content-alt.html +++ b/scipost_django/journals/templates/journals/_publication_li_content-alt.html @@ -14,7 +14,7 @@ </div> <div class="citation">{{ publication.citation }}</div> <span class="">published {{ publication.publication_date|date:'j F Y' }}</span> - {% for collection in publication.collection_set.all %} + {% for collection in publication.collections.all %} <p class="m-1"><em>Part of the <a href="{{ collection.get_absolute_url }}">{{ collection }}</a> Collection in the <a href="{{ collection.series.get_absolute_url }}">{{ collection.series }}</a> Series.</em></p> {% endfor %} </div> diff --git a/scipost_django/journals/templates/journals/_publication_li_content.html b/scipost_django/journals/templates/journals/_publication_li_content.html index 8143df7e4..d81d4588a 100644 --- a/scipost_django/journals/templates/journals/_publication_li_content.html +++ b/scipost_django/journals/templates/journals/_publication_li_content.html @@ -12,7 +12,7 @@ <p class="meta mb-0"> {{ publication.citation }} · <span class="fw-light">published {{ publication.publication_date|date:'j F Y' }}</span> </p> - {% for collection in publication.collection_set.all %} + {% for collection in publication.collections.all %} <p class="m-1"><em>Part of the <a href="{{ collection.get_absolute_url }}">{{ collection }}</a> Collection in the <a href="{{ collection.series.get_absolute_url }}">{{ collection.series }}</a> Series.</em></p> {% endfor %} </div> diff --git a/scipost_django/journals/templates/journals/_publication_summary.html b/scipost_django/journals/templates/journals/_publication_summary.html index cc43d2d35..ed4407769 100644 --- a/scipost_django/journals/templates/journals/_publication_summary.html +++ b/scipost_django/journals/templates/journals/_publication_summary.html @@ -12,7 +12,7 @@ {% if publication.cc_license != 'CC BY 4.0' %} · licensed under {{ publication.get_cc_license_display }} {% endif %} - {% for collection in publication.collection_set.all %} + {% for collection in publication.collections.all %} <p class="m-2"><em>Part of the <a href="{{ collection.get_absolute_url }}">{{ collection }}</a> Collection in the <a href="{{ collection.series.get_absolute_url }}">{{ collection.series }}</a> Series.</em></p> {% endfor %} diff --git a/scipost_django/journals/templates/journals/about.html b/scipost_django/journals/templates/journals/about.html index e54f3b0f7..2e1e2fa36 100644 --- a/scipost_django/journals/templates/journals/about.html +++ b/scipost_django/journals/templates/journals/about.html @@ -112,10 +112,10 @@ Content </h2> {% automarkup journal.content %} - {% if journal.series_set.all|length > 0 %} + {% if journal.contained_series.all|length > 0 %} Series hosted in this Journal: <ul> - {% for series in journal.series_set.all %} + {% for series in journal.contained_series.all %} <li> <a href="{{ series.get_absolute_url }}" target="_blank">{{ series }}</a> </li> diff --git a/scipost_django/journals/templates/journals/journal_detail.html b/scipost_django/journals/templates/journals/journal_detail.html index 143ed590f..4d751d1fa 100644 --- a/scipost_django/journals/templates/journals/journal_detail.html +++ b/scipost_django/journals/templates/journals/journal_detail.html @@ -20,7 +20,7 @@ <li class="nav-item"> <a class="nav-link" id="accepted-tab" data-bs-toggle="tab" href="#accepted" role="tab" aria-controls="accepted" aria-selected="true">Accepted Submissions</a> </li> - {% if journal.series_set.all|length > 0 %} + {% if journal.contained_series.all|length > 0 %} <li class="nav-item"> <a class="nav-link" id="series-tab" data-bs-toggle="tab" href="#series" role="tab" aria-controls="series" aria-selected="true">Series</a> </li> @@ -64,11 +64,11 @@ {% endfor %} </ul> </div> - {% if journal.series_set.all|length > 0 %} + {% if journal.contained_series.all|length > 0 %} <div class="tab-pane pt-4" id="series" role="tabpanel" aria-labelledby="series-tab"> <h3 class="highlight">Series contained in this Journal</h3> <ul> - {% for series in journal.series_set.all %} + {% for series in journal.contained_series.all %} <li><a href="{{ series.get_absolute_url }}" target="_blank">{{ series }}</a></li> {% endfor %} </ul> diff --git a/scipost_django/journals/templates/journals/journal_list.html b/scipost_django/journals/templates/journals/journal_list.html index b5f9ab430..2d677223b 100644 --- a/scipost_django/journals/templates/journals/journal_list.html +++ b/scipost_django/journals/templates/journals/journal_list.html @@ -63,11 +63,11 @@ <div class="card-body"> {% automarkup journal.blurb %} </div> - {% if journal.series_set.all|length > 0 %} + {% if journal.contained_series.all|length > 0 %} <div class="card-footer"> Series hosted in this Journal: <ul> - {% for series in journal.series_set.all %} + {% for series in journal.contained_series.all %} <li> <a href="{{ series.get_absolute_url }}" target="_blank">{{ series }}</a> </li> diff --git a/scipost_django/scipost/templates/scipost/portal/_hx_journals.html b/scipost_django/scipost/templates/scipost/portal/_hx_journals.html index 64b64dc8b..23a78cd1b 100644 --- a/scipost_django/scipost/templates/scipost/portal/_hx_journals.html +++ b/scipost_django/scipost/templates/scipost/portal/_hx_journals.html @@ -20,11 +20,11 @@ <div class="card-body"> {% automarkup journal.blurb %} </div> - {% if journal.series_set.all|length > 0 %} + {% if journal.contained_series.all|length > 0 %} <div class="card-footer"> Series hosted in this Journal: <ul> - {% for series in journal.series_set.all %} + {% for series in journal.contained_series.all %} <li> <a href="{{ series.get_absolute_url }}" target="_blank">{{ series }}</a> </li> diff --git a/scipost_django/scipost/views.py b/scipost_django/scipost/views.py index 56f868473..b5f72a548 100644 --- a/scipost_django/scipost/views.py +++ b/scipost_django/scipost/views.py @@ -210,9 +210,9 @@ def portal_hx_home(request): "publications": Publication.objects.published() .exclude(doi_label__contains="Proc") .order_by("-publication_date", "-paper_nr") - .prefetch_related( - "in_issue__in_journal", "specialties", "collection_set__series" - )[:5], + .prefetch_related("in_issue__in_journal", "specialties", "collections__series")[ + :5 + ], } return render(request, "scipost/portal/_hx_home.html", context) @@ -241,7 +241,7 @@ def portal_hx_journals(request): if session_acad_field_slug and session_acad_field_slug != "all": journals = journals.filter( college__acad_field__slug=session_acad_field_slug, - ).prefetch_related("series_set") + ).prefetch_related("contained_series") context["journals"] = journals else: # build a dictionary of journals per branch / acad_field journals_dict = {} @@ -289,7 +289,7 @@ def portal_hx_publications_page(request): "in_issue__in_journal", "in_issue__in_volume__in_journal", "specialties", - "collection_set__series", + "collections__series", ) paginator = Paginator(publications, 10) page_nr = request.GET.get("page") diff --git a/scipost_django/series/migrations/0008_alter_collections_related_names.py b/scipost_django/series/migrations/0008_alter_collections_related_names.py new file mode 100644 index 000000000..1c3e8c125 --- /dev/null +++ b/scipost_django/series/migrations/0008_alter_collections_related_names.py @@ -0,0 +1,36 @@ +# Generated by Django 3.2.18 on 2023-09-20 16:05 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('journals', '0128_populate_submission_object_types'), + ('submissions', '0142_alter_submission_author_list'), + ('series', '0007_collection_expected_editors'), + ] + + operations = [ + migrations.AlterField( + model_name='collection', + name='publications', + field=models.ManyToManyField(blank=True, related_name='collections', through='series.CollectionPublicationsTable', to='journals.Publication'), + ), + migrations.AlterField( + model_name='collection', + name='series', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='collections', to='series.series'), + ), + migrations.AlterField( + model_name='collection', + name='submissions', + field=models.ManyToManyField(blank=True, related_name='collections', to='submissions.Submission'), + ), + migrations.AlterField( + model_name='series', + name='container_journals', + field=models.ManyToManyField(blank=True, related_name='contained_series', to='journals.Journal'), + ), + ] diff --git a/scipost_django/series/models.py b/scipost_django/series/models.py index 568bc2aa7..243eb26e6 100644 --- a/scipost_django/series/models.py +++ b/scipost_django/series/models.py @@ -27,7 +27,9 @@ class Series(models.Model): blank=True, ) image = models.ImageField(upload_to="series/images/", blank=True) - container_journals = models.ManyToManyField("journals.Journal", blank=True) + container_journals = models.ManyToManyField( + "journals.Journal", blank=True, related_name="contained_series" + ) class Meta: verbose_name_plural = "series" @@ -45,7 +47,11 @@ class Collection(models.Model): """ series = models.ForeignKey( - "series.Series", blank=True, null=True, on_delete=models.CASCADE + "series.Series", + blank=True, + null=True, + on_delete=models.CASCADE, + related_name="collections", ) name = models.CharField(max_length=256, blank=True) slug = models.SlugField(unique=True, allow_unicode=True) @@ -66,14 +72,23 @@ class Collection(models.Model): expected_editors = models.ManyToManyField( "colleges.Fellowship", blank=True, related_name="collections_editing" ) - submissions = models.ManyToManyField("submissions.Submission", blank=True) + submissions = models.ManyToManyField( + "submissions.Submission", blank=True, related_name="collections" + ) publications = models.ManyToManyField( - "journals.Publication", through="series.CollectionPublicationsTable", blank=True + "journals.Publication", + through="series.CollectionPublicationsTable", + blank=True, + related_name="collections", ) def __str__(self): return self.name + @property + def name_with_series(self): + return f"{self.series.name} - {self.name}" + def get_absolute_url(self): return reverse("series:collection_detail", kwargs={"slug": self.slug}) diff --git a/scipost_django/series/views.py b/scipost_django/series/views.py index 261affb4e..f98e907bb 100644 --- a/scipost_django/series/views.py +++ b/scipost_django/series/views.py @@ -38,7 +38,7 @@ class SeriesDetailView(DetailView): context = super().get_context_data(*args, **kwargs) # Sort collections in series by event start date - context["collections"] = self.object.collection_set.all().order_by( + context["collections"] = self.object.collections.all().order_by( "event_start_date" ) return context diff --git a/scipost_django/submissions/admin.py b/scipost_django/submissions/admin.py index 44fc4388b..672646c13 100644 --- a/scipost_django/submissions/admin.py +++ b/scipost_django/submissions/admin.py @@ -117,6 +117,14 @@ class SubmissionTieringInline(admin.StackedInline): ] +class CollectionInline(admin.StackedInline): + model = Submission.collections.through + extra = 0 + autocomplete_fields = [ + "collection", + ] + + class SubmissionAdmin(GuardedModelAdmin): date_hierarchy = "submission_date" list_display = ( @@ -162,6 +170,7 @@ class SubmissionAdmin(GuardedModelAdmin): ReadinessInline, SubmissionClearanceInline, SubmissionTieringInline, + CollectionInline, ] # Admin fields should be added in the fieldsets diff --git a/scipost_django/submissions/templates/submissions/_submission_summary.html b/scipost_django/submissions/templates/submissions/_submission_summary.html index 072a08083..33f2a6f1a 100644 --- a/scipost_django/submissions/templates/submissions/_submission_summary.html +++ b/scipost_django/submissions/templates/submissions/_submission_summary.html @@ -86,16 +86,16 @@ <td>{{ submission.proceedings }}</td> </tr> {% endif %} - {% with ncollections=submission.collection_set.all|length %} + {% with ncollections=submission.collections.all|length %} {% if ncollections > 0 %} <tr> <td></td> <td> for consideration in Collection{{ ncollections|pluralize }}: <ul class="mb-0 pb-0"> - {% for collection in submission.collection_set.all %} + {% for collection in submission.collections.all %} <li> - <a href="{{ collection.get_absolute_url }}" target="_blank">{{ collection }}</a> + <a href="{{ collection.get_absolute_url }}" target="_blank">{{ collection.name_with_series }}</a> </li> {% endfor %} </ul> -- GitLab