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 4d112e20a18f226eeea21e0784560b7d724442e8..ad874fb0404c66cfe429664f8b741963e28c71a7 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 8143df7e429ba25d973b8f935d613fccbadb1c4f..d81d4588a5c42810d358da5dcc863646e470c2bd 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 cc43d2d3582294ad158bb909993f3340d23c425e..ed44077694f1985fe90ca582616b64a08e49ee6a 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 e54f3b0f7ecf274ef9c9a086b57426a2574287ff..2e1e2fa36ad9948da883d645d7d77a6b0f510eaf 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 143ed590f1b15b5efeeca101b34620ac5496472f..4d751d1facdd28d25c9aa80b21f5b8e8c8889e75 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 b5f9ab43029f7ad9e5fabd16401a1c826724aad2..2d677223b58b6ff9efde0442fdd32347605fb3d6 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 64b64dc8b98f09badc5f65a874c391dd460d4f9e..23a78cd1bb53696ed3c00b5fa681fe055c005ab5 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 56f8684738251cbfa46e1eabd50451a04be590c0..b5f72a54844d76ce99f33e4da48df1901b67f34d 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 0000000000000000000000000000000000000000..1c3e8c1254d5cf9da5c97c003c710be175686675 --- /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 568bc2aa76da69fbf6119be0555441c7b274a414..243eb26e6068b9e1f897cc99b94006b85b0b901a 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 261affb4e030a757d44be1e6f50bb229a4b61454..f98e907bbc55c03ce003a5359bd1055c337bf047 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 44fc4388bc966887351479af1a195576cea4a3bb..672646c135dadc7ca61f8c512948a11df409d8b7 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 072a08083c9ac0111029bff634759f47ae79823b..33f2a6f1af5229aa8c2f597e4f3bdf561f83f476 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>