Skip to content

Commit

Permalink
Upgrade usability of prepub notifications #4089
Browse files Browse the repository at this point in the history
  • Loading branch information
joemull committed May 29, 2024
1 parent d897237 commit 9820e96
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 115 deletions.
5 changes: 3 additions & 2 deletions src/events/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ class Events:
ON_ARTICLE_PUBLISHED = 'on_article_published'

# kwargs: request, article
# raised when an Editor notifies an author that publication is set
ON_AUTHOR_PUBLICATION = 'on_author_publication'
# raised when an editor notifies author, editors,
# and/or reviewers that publication is set
ON_PREPUB_NOTIFICATIONS = 'on_prepub_notifications'

# kwargs: request, override
# raised when an Editor overrides review security
Expand Down
6 changes: 3 additions & 3 deletions src/events/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@
event_logic.Events.register_for_event(event_logic.Events.ON_CORRECTIONS_CANCELLED,
transactional_emails.send_cancel_corrections)

# Publication
event_logic.Events.register_for_event(event_logic.Events.ON_AUTHOR_PUBLICATION,
transactional_emails.send_author_publication_notification)
# Prepublication
event_logic.Events.register_for_event(event_logic.Events.ON_PREPUB_NOTIFICATIONS,
transactional_emails.send_prepub_notifications)

# Send notifications to registered users.
event_logic.Events.register_for_event(event_logic.Events.ON_ARTICLE_SUBMITTED,
Expand Down
20 changes: 20 additions & 0 deletions src/journal/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tinymce.widgets import TinyMCE

from core import models as core_models
from core.forms import FullSettingEmailForm
from journal import models as journal_models, logic
from utils.forms import CaptchaForm

Expand Down Expand Up @@ -136,3 +137,22 @@ class Meta:
'display_issue_doi',
'display_issues_grouped_by_decade',
)


class BasePrepubNotificationFormSet(forms.BaseFormSet):

def get_form_kwargs(self, index):
kwargs = super().get_form_kwargs(index)
if index == 0:
kwargs['setting_name'] = 'author_publication'
elif index == 1:
kwargs['setting_name'] = 'peer_reviewer_pub_notification'
return kwargs


PrepubNotificationFormSet = forms.formset_factory(
FullSettingEmailForm,
formset=BasePrepubNotificationFormSet,
extra=0,
max_num=2,
)
56 changes: 41 additions & 15 deletions src/journal/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,30 +273,56 @@ def handle_set_pubdate(request, article):
return [date_time_str, ['Not a recognised Date/Time format. Date: 2016-12-16, Time: 20:20.']]


def get_notify_author_text(request, article):
context = {
'article': article,
}
def get_initial_for_prepub_notifications(request, article):
author_initial = {}
author_initial['to'] = article.correspondence_author.email
cc = [au.email for au in article.non_correspondence_authors()]
notify_section_editors = request.journal.get_setting(
'general',
'notify_section_editors_of_publication',
)
if notify_section_editors:
cc.extend([ed.email for ed in article.section_editors()])
author_initial['cc'] = ', '.join(cc)

return render_template.get_message_content(request, context, 'author_publication')
notify_peer_reviewers = request.journal.get_setting(
'general',
'notify_peer_reviewers_of_publication',
)

if not notify_peer_reviewers:
return [author_initial]
else:
peer_reviewer_initial = {}
custom_reply_to = request.journal.get_setting(
'general',
'replyto_address'
)
peer_reviewer_initial['to'] = custom_reply_to or request.user.email
reviewer_emails = article.peer_reviewers(emails=True, completed=True)
peer_reviewer_initial['bcc'] = ', '.join(reviewer_emails)
return [author_initial, peer_reviewer_initial]

def notify_author(request, article):

def handle_prepub_notifications(request, article, formset):
kwargs = {
'request': request,
'article': article,
'user_message': request.POST.get('email_to_author', 'No message from Editor.'),
'section_editors': request.POST.get('section_editors', False),
'peer_reviewers': request.POST.get('peer_reviewers', False),
'formset': formset,
}

event_logic.Events.raise_event(event_logic.Events.ON_AUTHOR_PUBLICATION,
task_object=article,
**kwargs)

article.fixedpubcheckitems.notify_the_author = True
event_logic.Events.raise_event(
event_logic.Events.ON_PREPUB_NOTIFICATIONS,
task_object=article,
**kwargs,
)
article.fixedpubcheckitems.send_notifications = True
article.fixedpubcheckitems.save()
messages.add_message(request, messages.INFO, 'Author notified.')
messages.add_message(
request,
messages.SUCCESS,
'Notifications sent.'
)


def set_render_galley(request, article):
Expand Down
44 changes: 31 additions & 13 deletions src/journal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,11 +1031,19 @@ def publish_article(request, article_id):
doi_data, doi = logic.get_doi_data(article)
issues = request.journal.issues
new_issue_form = issue_forms.NewIssue(journal=article.journal)
notify_author_email_form = core_forms.SimpleTinyMCEForm(
'email_to_author',
initial = {
'email_to_author': logic.get_notify_author_text(request, article)
}
notification_form_kwargs = {
'email_context': {
'article': article,
},
'request': request,
}
notification_initial = logic.get_initial_for_prepub_notifications(
request,
article,
)
notification_formset = forms.PrepubNotificationFormSet(
form_kwargs=notification_form_kwargs,
initial=notification_initial,
)
modal = request.GET.get('m', None)
pubdate_errors = []
Expand Down Expand Up @@ -1100,14 +1108,24 @@ def publish_article(request, article_id):
else:
modal = 'pubdate'

if 'author' in request.POST:
logic.notify_author(request, article)
return redirect(
reverse(
'publish_article',
kwargs={'article_id': article.pk},
)
if 'notifications' in request.POST:
notification_formset = forms.PrepubNotificationFormSet(
request.POST,
form_kwargs=notification_form_kwargs,
initial=notification_initial,
)
if notification_formset.is_valid():
logic.handle_prepub_notifications(
request,
article,
notification_formset,
)
else:
messages.add_message(
request,
messages.ERROR,
'Something went wrong. Please try again.',
)

if 'galley' in request.POST:
logic.set_render_galley(request, article)
Expand Down Expand Up @@ -1205,7 +1223,7 @@ def publish_article(request, article_id):
'new_issue_form': new_issue_form,
'modal': modal,
'pubdate_errors': pubdate_errors,
'notify_author_email_form': notify_author_email_form,
'notification_formset': notification_formset,
}

return render(request, template, context)
Expand Down
37 changes: 0 additions & 37 deletions src/templates/admin/elements/publish/author.html

This file was deleted.

66 changes: 66 additions & 0 deletions src/templates/admin/elements/publish/notifications.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{% load foundation %}
<div
class="reveal small"
id="notifications"
data-reveal
data-animation-in="slide-in-up"
data-animation-out="slide-out-down">
<div class="card">
<div class="card-divider">
<h3><i class="fa fa-envelope-o">&nbsp;</i>Send Notifications</h3>
</div>
{% if not article.fixedpubcheckitems.send_notifications %}
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ notification_formset.management_form }}
<div class="card-section">
<div class="row">
<div class="large-12 columns">
<h4>Authors</h4>
<p>You can send an email to authors and others
notifying them of the publication date and time.
Any coauthors
{% if journal_settings.general.notify_section_editors_of_publication %}
and section editors
(<a href="{% url 'core_edit_setting' 'general' 'notify_section_editors_of_publication' %}">change setting</a>)
{% endif %}
have been added to CC.</p>
<p>From: {{ request.user.full_name }} &lt;{{ request.user.email }}&gt;</p>
</div>
</div>
{{ notification_formset.0|foundation }}
</div>
{% if journal_settings.general.notify_peer_reviewers_of_publication %}
<div class="card-section">
<div class="row">
<div class="large-12 columns">
<h4>Peer reviewers</h4>
<p>Peer reviewers will be notified with the following message
(<a href="{% url 'core_edit_setting' 'general' 'notify_peer_reviewers_of_publication' %}">change setting</a>).
</p>
<p>From: {{ request.user.full_name }} &lt;{{ request.user.email }}&gt;</p>
</div>
</div>
{{ notification_formset.1|foundation }}
</div>
{% endif %}
<div class="card-divider">
<div class="button-group">
<button type="submit" class="button success" name="notifications"><i class="fa fa-envelope-o">&nbsp;</i>Send</button>
</div>
</div>
</form>
{% else %}
<div class="card-section">
<div class="row">
<div class="large-12 columns">
<p>Notifications have already been sent.</p>
</div>
</div>
</div>
{% endif %}
</div>
<button class="close-button" data-close aria-label="Close reveal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
49 changes: 42 additions & 7 deletions src/templates/admin/journal/publish_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
{% load static %}
{% load foundation %}

{% block css %}
{{ block.super }}
<link href="{% static "common/css/jquery-te-1.4.0.css" %}" rel="stylesheet">
{% endblock css %}
{% block title %}Pre Publication - {{ article.pk }}{% endblock title %}
{% block title-section %}Pre Publication Checklist{% endblock %}
{% block title-sub %}#{{ article.pk }} / {{ article.correspondence_author.last_name }} / {{ article.safe_title }}{% endblock %}
Expand Down Expand Up @@ -133,20 +137,47 @@ <h2>Select Article Image</h2>
</div>
</div>

<div id="notify_the_authorbox" class="box {% if article.fixedpubcheckitems.notify_the_author %}success{% else %}warning{% endif %} checklist">
<div
id="send_notificationsbox"
class="box {% if article.fixedpubcheckitems.send_notifications %}success{% else %}warning{% endif %} checklist">
<div class="row">
<div class="large-3 columns">
<i class="fa fa-envelope-o pub-icon">&nbsp;</i>
</div>
<div class="large-9 columns">
<h2>Notify the Author of Publication</h2>
<p>You can notify the Author(s) of publication so they can publicise their work. <i>NB. This requires that the publication date is already set.</i></p>
<h2>Send Notifications</h2>
<p>You can notify authors and others of
publication by email. <i>Note: This requires that the publication
date is already set.</i></p>
<div class="button-group">
<input onclick="submit_check_item('fixed', 'notify_the_author', this)" type="checkbox" id="notify_the_author" {% if article.fixedpubcheckitems.notify_the_author %}checked="checked"{% endif %}><label class="toggle" for="notify_the_author">{% if article.fixedpubcheckitems.notify_the_author %}<s>Mark as Complete</s>{% else %}Mark as Complete{% endif %}</label>
<input
onclick="submit_check_item('fixed', 'send_notifications', this)"
type="checkbox"
id="notify_the_author"
{% if article.fixedpubcheckitems.send_notifications %}
checked="checked"
{% endif %}>
<label
class="toggle"
for="notify_the_author">
{% if article.fixedpubcheckitems.send_notifications %}
<s>Mark as Complete</s>
{% else %}
Mark as Complete
{% endif %}
</label>
{% if article.date_published %}
<a href="#" data-open="author" class="button small success pub-button">Notify Author</a>
<a
href="#"
data-open="notifications"
class="button small success pub-button">
Set Notifications
</a>
{% else %}
<button class="button small disabled pub-button">Set a Publication Date to Enable</button>
<button
class="button small disabled pub-button">
Set a Publication Date to Enable
</button>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -210,14 +241,17 @@ <h2>Confirm Article Set for Publication</h2>
{% include "elements/publish/doi_data.html" %}
{% include "elements/publish/issues.html" %}
{% include "elements/publish/pubdate.html" %}
{% include "elements/publish/author.html" %}
{% include "elements/publish/notifications.html" %}
{% include "elements/publish/galley.html" %}
{% include "elements/publish/images.html" %}
{% include "elements/publish/open_reviews.html" %}

{% endblock body %}

{% block js %}
{{ block.super }}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
{{ notification_formset.0.media.js }}
<script src="{% static "admin/js/modal.js" %}"></script>
<script src="{% static "admin/js/csrf.js" %}"></script>
{% include "elements/notes/note_script.html" %}
Expand Down Expand Up @@ -261,4 +295,5 @@ <h2>Confirm Article Set for Publication</h2>
{% endif %}
{% include "elements/datepicker.html" with target="#date" %}
{% include "elements/timepicker.html" with target="#time" %}

{% endblock js %}
Loading

0 comments on commit 9820e96

Please sign in to comment.