Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes the render galley prepub item and replaces it with a preview article option #4605

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/journal/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def _section(self, obj):
class FixedPubCheckItemsAdmin(admin_utils.ArticleFKModelAdmin):
list_display = ('_article', '_journal', 'metadata', 'verify_doi',
'select_issue', 'set_pub_date', 'send_notifications',
'select_render_galley', 'select_article_image',
'preview_article', 'select_article_image',
'select_open_reviews')
list_filter = ('article__journal', 'metadata', 'verify_doi',
'select_issue', 'set_pub_date', 'send_notifications',
'select_render_galley', 'select_article_image',
'preview_article', 'select_article_image',
'select_open_reviews')
search_fields = ('article__pk', 'article__title', 'article__journal__code')
raw_id_fields = ('article',)
Expand Down
1 change: 0 additions & 1 deletion src/journal/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ def get_best_galley(article, galleys):
except core_models.Galley.DoesNotExist:
pass
try:

image_galley = galleys.get(
file__mime_type__in=files.IMAGE_MIMETYPES,
public=True,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.15 on 2025-01-31 12:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('journal', '0066_issue_type_bleach_20240507_1359'),
]

operations = [
migrations.RemoveField(
model_name='fixedpubcheckitems',
name='select_render_galley',
),
migrations.AddField(
model_name='fixedpubcheckitems',
name='preview_article',
field=models.BooleanField(default=False),
),
]
2 changes: 1 addition & 1 deletion src/journal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ class FixedPubCheckItems(models.Model):
select_issue = models.BooleanField(default=False)
set_pub_date = models.BooleanField(default=False)
send_notifications = models.BooleanField(default=False)
select_render_galley = models.BooleanField(default=False)
preview_article = models.BooleanField(default=False)
select_article_image = models.BooleanField(default=False)
select_open_reviews = models.BooleanField(default=False)

Expand Down
5 changes: 5 additions & 0 deletions src/journal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
views.publish_article, name='publish_article'),
re_path(r'^publish/article/(?P<article_id>\d+)/check/$',
views.publish_article_check, name='publish_article_check'),
re_path(
r'^publish/article/(?P<article_id>\d+)/preview/$',
views.article_preview,
name='publish_article_preview',
),

# Issues
re_path(r'^manage/issues/$',
Expand Down
90 changes: 64 additions & 26 deletions src/journal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,20 @@ def collection_by_code(request, collection_code):
))


@decorators.frontend_enabled
@article_exists
@article_stage_accepted_or_later_required
def article(request, identifier_type, identifier):
""" Renders an article.
def article_base_view(
request,
identifier_type,
identifier,
is_preview=False,
):
"""Base view to handle article rendering logic.

:param request: the request associated with this call
:param request: the request object
:param identifier_type: the identifier type
:param identifier: the identifier
:return: a rendered template of the article
:param is_preview: flag to alter logic for preview (boolean)
:return: HttpResponse object
"""
article_object = submission_models.Article.get_article(
request.journal,
Expand All @@ -453,33 +457,31 @@ def article(request, identifier_type, identifier):
content, tables_in_galley = None, None
galleys = article_object.galley_set.filter(public=True)

# check if there is a galley file attached that needs rendering
if article_object.is_published:
galley = get_best_galley(article_object, galleys)
if galley:
content = galley.file_content(recover=True)
else:
content = ''
tables_in_galley = logic.get_all_tables_from_html(content)
store_article_access(
request,
article_object,
"view",
galley.type if galley else None)
galley = get_best_galley(article_object, galleys)
if galley:
content = galley.file_content(recover=True)
else:
article_object.abstract = (
"<p><strong>This is an accepted article with a DOI pre-assigned"
" that is not yet published.</strong></p>"
) + (article_object.abstract or "")
content = ''

tables_in_galley = logic.get_all_tables_from_html(content)
store_article_access(
request,
article_object,
"view",
galley.type if galley else None,
)

if request.journal.disable_html_downloads:
# exclude any HTML galleys.
galleys = galleys.exclude(
file__mime_type='text/html',
)

template = 'journal/article.html'
if not is_preview and not article_object.is_published:
article_object.abstract = (
"<p><strong>This is an accepted article with a DOI pre-assigned"
" that is not yet published.</strong></p>"
) + (article_object.abstract or "")

context = {
'article': article_object,
'galleys': galleys,
Expand All @@ -489,7 +491,43 @@ def article(request, identifier_type, identifier):
'tables_in_galley': tables_in_galley,
}

return render(request, template, context)
return render(request, 'journal/article.html', context)


@decorators.frontend_enabled
@article_stage_accepted_or_later_required
def article(request, identifier_type, identifier):
"""
Renders a publicly accessible article.

:param request: the request object
:param identifier_type: the identifier type [id, doi, pubid]
:param identifier: the identifier
:return: HttpResponse object
"""
return article_base_view(
request=request,
identifier_type=identifier_type,
identifier=identifier,
is_preview=False,
)


@production_user_or_editor_required
def article_preview(request, article_id):
"""
Renders an article preview for editors and production staff.

:param request: the request object
:param article_id: the Article object primary key
:return: HttpResponse object
"""
return article_base_view(
request=request,
identifier_type="id",
identifier=article_id,
is_preview=True,
)


def article_from_identifier(request, identifier_type, identifier):
Expand Down
12 changes: 11 additions & 1 deletion src/submission/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,17 @@ def __init__(self, *args, **kwargs):

class EditArticleMetadata(ArticleInfo):
class Meta(ArticleInfo.Meta):
fields = ArticleInfo.Meta.fields + ('competing_interests', 'jats_article_type_override')
fields = ArticleInfo.Meta.fields + (
'competing_interests',
'jats_article_type_override',
'render_galley',
)

def __init__(self, *args, **kwargs):
super(EditArticleMetadata, self).__init__(*args, **kwargs)
if 'instance' in kwargs:
article = kwargs['instance']
self.fields['render_galley'].queryset = article.galley_set.all()


class AuthorForm(forms.ModelForm):
Expand Down
13 changes: 11 additions & 2 deletions src/submission/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,17 @@ def jats_article_type(self):
)

# Galley
render_galley = models.ForeignKey('core.Galley', related_name='render_galley', blank=True, null=True,
on_delete=models.SET_NULL)
render_galley = models.ForeignKey(
'core.Galley',
related_name='render_galley',
blank=True,
null=True,
on_delete=models.SET_NULL,
help_text="Overrides the default galley rendered on the article "
"landing page. The default order Janeway selects a galley "
"to render is HTML, XML then any Image galleys. Other "
"galley types will not be rendered.",
)

# Dates
date_started = models.DateTimeField(auto_now_add=True)
Expand Down
26 changes: 18 additions & 8 deletions src/templates/admin/journal/publish_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,34 @@ <h2>Select open peer reviews to display</h2>
</div>
{% endif %}

<div id="select_render_galleybox" class="box {% if article.fixedpubcheckitems.select_render_galley %}success{% else %}warning{% endif %} checklist">
<div id="preview_articlebox" class="box {% if article.fixedpubcheckitems.preview_article %}success{% else %}warning{% endif %} checklist">
<div class="row">
<div class="large-3 columns">
<i class="fa fa-file-o pub-icon">&nbsp;</i>
<i class="fa fa-eye pub-icon">&nbsp;</i>
</div>
<div class="large-9 columns">
<h2>Select a Galley for Rendering</h2>
<p>If you have HTML or XML galleys, you can select which one will render by default.</p>
<h2>Preview Article</h2>
<p>Review how the article will appear to readers by opening the preview.</p>
<div class="button-group">
<input onclick="submit_check_item('fixed', 'select_render_galley', this)" type="checkbox" id="select_render_galley" {% if article.fixedpubcheckitems.select_render_galley %}checked="checked"{% endif %}><label class="toggle" for="select_render_galley">{% if article.fixedpubcheckitems.select_render_galley %}<s>Mark as Complete</s>{% else %}Mark as Complete{% endif %}</label>
<a href="#" data-open="galley" class="button small success pub-button">Select Galley</a>
<input
onclick="submit_check_item('fixed', 'preview_article', this)"
type="checkbox"
id="preview_article"
{% if article.fixedpubcheckitems.preview_article %}checked="checked"{% endif %}>
<label class="toggle" for="preview_article">
{% if article.fixedpubcheckitems.preview_article %}
<s>Mark as Complete</s>
{% else %}
Mark as Complete
{% endif %}
</label>
<a href="{% url 'publish_article_preview' article.pk %}" class="button small success pub-button">Open Preview</a>
</div>
</div>
</div>
</div>


<div id="set_pub_datebox" class="box {% if article.fixedpubcheckitems.set_pub_date %}success{% else %}warning{% endif %} checklist">
<div class="row">
<div class="large-3 columns">
Expand Down Expand Up @@ -267,8 +279,6 @@ <h2>Confirm Article Set for Publication</h2>
"url": "{% url 'publish_article_check' article.pk %}",
"data": data,
"success": function(data) {
console.log(item.id)
console.log(data)
if (data.id == true) {
$("label[for='" + item.id +"']").wrapInner("<s></s>");
$("#"+ item.id + "box").removeClass("warning");
Expand Down
3 changes: 3 additions & 0 deletions src/templates/admin/submission/edit/metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ <h2 id="edit-metadata">Edit Metadata</h2>
{{ info_form.jats_article_type_override }}
</div>
</div>
<div class="large-6 columns">
{{ info_form.render_galley|foundation }}
</div>
</div>
{% if request.journal.submissionconfiguration.competing_interests %}
<div class="large-10 columns">
Expand Down