From 61fe597e1571b7e38a5acaa590bd8e11d1421b18 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sat, 17 Aug 2024 12:10:47 +0200 Subject: [PATCH] Fix retrieving documents/galleys in manage_issue --- ...e_allowed_sections_issue_date_close_and_more.py | 10 ++++++++++ src/journal/models.py | 6 +++++- src/journal/views.py | 14 +++++++++----- src/submission/forms.py | 2 +- src/templates/admin/elements/issue/galleys.html | 5 ++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/journal/migrations/0066_issue_allowed_sections_issue_date_close_and_more.py b/src/journal/migrations/0066_issue_allowed_sections_issue_date_close_and_more.py index 5f440ad48..e2a30c63f 100644 --- a/src/journal/migrations/0066_issue_allowed_sections_issue_date_close_and_more.py +++ b/src/journal/migrations/0066_issue_allowed_sections_issue_date_close_and_more.py @@ -3,6 +3,7 @@ import core.model_utils from django.conf import settings from django.db import migrations, models +import django.utils.timezone class Migration(migrations.Migration): @@ -173,4 +174,13 @@ class Migration(migrations.Migration): blank=True, default="", help_text="Short name or codde", max_length=300 ), ), + migrations.AlterField( + model_name="issue", + name="date", + field=models.DateTimeField( + default=django.utils.timezone.now, + help_text="Date after which the issue if visible to the public (this does not affect the article's visibility).", + verbose_name="Publication date", + ), + ), ] diff --git a/src/journal/models.py b/src/journal/models.py index 3e6e69b63..0ba6df7ae 100644 --- a/src/journal/models.py +++ b/src/journal/models.py @@ -672,7 +672,11 @@ class Issue(AbstractLastModifiedModel): "Autogenerated cache of the display format of an issue title" ), ) - date = models.DateTimeField(default=timezone.now) + date = models.DateTimeField( + default=timezone.now, + verbose_name=gettext("Publication date"), + help_text=gettext("Date after which the issue if visible to the public (this does not affect the article's visibility)."), + ) order = models.IntegerField(default=0) issue_type = models.ForeignKey( "journal.IssueType", blank=False, null=True, on_delete=models.SET_NULL) diff --git a/src/journal/views.py b/src/journal/views.py index 95b0301e2..61828b66f 100755 --- a/src/journal/views.py +++ b/src/journal/views.py @@ -1317,6 +1317,8 @@ def manage_issues(request, issue_id=None, event=None): from core.logic import resize_and_crop issue_list = models.Issue.objects.filter(journal=request.journal) + galleys = [] + documents = [] if issue_id: issue = get_object_or_404(models.Issue, pk=issue_id) form = issue_forms.NewIssue(instance=issue, journal=issue.journal) @@ -1386,10 +1388,12 @@ def manage_issues(request, issue_id=None, event=None): modal = 'issue' template = 'journal/manage/issues.html' - try: - galleys = [issue.galley.file] - except IssueGalley.DoesNotExist: - galleys = [] + if issue: + try: + galleys = [issue.galley.file] + except IssueGalley.DoesNotExist: + pass + documents = list(issue.documents.all()) context = { 'issues': issue_list if not issue else [issue], 'issue': issue, @@ -1397,7 +1401,7 @@ def manage_issues(request, issue_id=None, event=None): 'modal': modal, 'galley_form': galley_form, 'galleys': galleys, - 'documents': list(issue.documents.all()), + 'documents': documents, 'articles': issue.get_sorted_articles(published_only=False) if issue else None, 'sort_form': sort_form, } diff --git a/src/submission/forms.py b/src/submission/forms.py index d90398551..c81c74bb0 100755 --- a/src/submission/forms.py +++ b/src/submission/forms.py @@ -148,7 +148,7 @@ def __init__(self, *args, **kwargs): license_queryset = license_queryset.filter( available_for_submission=self.FILTER_PUBLIC_FIELDS, ) - if article.primary_issue and article.primary_issue.allowed_sections: + if article.primary_issue and article.primary_issue.allowed_sections.exists(): section_queryset = section_queryset.filter( pk__in=article.primary_issue.allowed_sections.values_list('pk', flat=True), ) diff --git a/src/templates/admin/elements/issue/galleys.html b/src/templates/admin/elements/issue/galleys.html index ca4c1e3d2..4be631073 100644 --- a/src/templates/admin/elements/issue/galleys.html +++ b/src/templates/admin/elements/issue/galleys.html @@ -23,11 +23,10 @@

{{ title }}

{{ file.original_filename|truncatechars:40 }} {{ object_name|title }} {% if object_mode == "galley" %} -   +   {% else %} -   +   {% endif %} - {% if object_mode == "galley" %}   {% endif %}