Skip to content

Commit

Permalink
#2086: Changes author review deletion email to use new EmailForm
Browse files Browse the repository at this point in the history
  • Loading branch information
mauromsl committed Oct 25, 2023
1 parent 77667c2 commit f8edb28
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 77 deletions.
81 changes: 46 additions & 35 deletions src/copyediting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,56 +633,67 @@ def delete_author_review(request, article_id, copyedit_id, author_review_id):
pk=author_review_id,
assignment__article__journal=request.journal,
)
email_template = logic.get_copyedit_message(
article = author_review.assignment.article,
copyedit = author_review.assignment

email_context = logic.get_author_copyedit_message_context(
request,
article=author_review.assignment.article,
copyedit=author_review.assignment,
template='author_copyedit_deleted',
author_review=author_review,
copyedit,
author_review,
)
email_subject = request.journal.get_setting(
'email_subject',
'subject_author_copyedit_deleted',

form = core_forms.SettingEmailForm(
setting_name='author_copyedit_deleted',
email_context=email_context,
request=request,
)

if request.POST:
event_kwargs = {
'user_message_content': request.POST.get('user_message_content'),
'subject': email_subject,
'author_review': author_review,
'request': request,
'skip': True if 'skip' in request.POST else False
}
event_logic.Events.raise_event(
event_logic.Events.ON_COPYEDIT_AUTHOR_REVIEW_DELETED,
**event_kwargs,
skip = 'skip' in request.POST
form = core_forms.SettingEmailForm(
request.POST, request.FILES,
setting_name='author_copyedit_deleted',
email_context=email_context,
request=request,
)
messages.add_message(
request,
messages.SUCCESS,
'Author review for {} has been deleted.'.format(
author_review.assignment.article.title,
if form.is_valid() or skip:
author_review.delete()
kwargs = {
'copyedit_assignment': copyedit,
'article': article,
'author_review': author_review,
'email_data': form.as_dataclass(),
'request': request,
'skip': skip,
}
event_logic.Events.raise_event(
event_logic.Events.ON_COPYEDIT_AUTHOR_REVIEW_DELETED,
**kwargs,
)
messages.add_message(
request,
messages.SUCCESS,
'Author review for {} has been deleted.'.format(
author_review.assignment.article.title,
)
)
)
author_review.delete()

return redirect(
reverse(
'editor_review',
kwargs={
'article_id': article_id,
'copyedit_id': copyedit_id,
}
return redirect(
reverse(
'editor_review',
kwargs={
'article_id': article_id,
'copyedit_id': copyedit_id,
}
)
)
)

template = 'admin/copyediting/delete_author_review.html'
context = {
'author_review': author_review,
'article': author_review.assignment.article,
'copyedit': author_review.assignment,
'email_template': email_template,
'email_subject': email_subject,
'form': form,
}
return render(
request,
Expand Down
27 changes: 7 additions & 20 deletions src/templates/admin/copyediting/delete_author_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,18 @@ <h2>Delete Author Copyedit Request</h2>
<div class="content">
<p>To delete this Author Copyedit Request, review the message below and, if needed, add a reason for the deletion. You can skip sending the email, this is particularly useful if you have not yet notified the author of the review request.</p>
<div class="card">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="card-divider">
<h4>To {{ copyedit.article.correspondence_author.full_name }}</h4>
<h5>From {{ request.user.full_name }}</h5>
</div>
<div class="card-section">
<p>Subject: <strong>{{ email_subject }}</strong></p>
<textarea rows="10" name="user_message_content">{{ email_template|linebreaksbr }}</textarea>
<label for="attachment"><p>Attachment (You can select multiple files): </p></label>
<input type="file" name="attachment" multiple>
</div>
<div class="card-divider">
<div class="button-group">
<button type="submit" class="button success" name="send"><i class="fa fa-envelope-o">&nbsp;</i>Send</button>
<button type="submit" class="button warning" name="skip"><i class="fa fa-step-forward">&nbsp;</i>Skip</button>
</div>
</div>
</form>
{% include 'admin/elements/email_form.html' with form=form skip=1 %}
</div>
</div>
</div>

{% endblock %}

{% block js %}
{% include "elements/jqte.html" %}
{{ block.super}}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
{{ form.media.js }}

{% endblock js %}


56 changes: 34 additions & 22 deletions src/utils/transactional_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ def send_copyedit_decision(**kwargs):
def send_copyedit_author_review(**kwargs):
request = kwargs['request']
copyedit_assignment = kwargs['copyedit_assignment']
user_message_content = kwargs['user_message_content']
author_review = kwargs['author_review']
email_data = kwargs['email_data']
skip = kwargs.get('skip', False)

description = '{0} has requested copyedit review for {1} from {2}'.format(
Expand All @@ -735,12 +736,22 @@ def send_copyedit_author_review(**kwargs):
copyedit_assignment.article.correspondence_author.full_name())

if not skip:
log_dict = {'level': 'Info', 'action_text': description, 'types': 'Copyedit Author Review',
'target': copyedit_assignment.article}
log_dict = {
'level': 'Info',
'action_text': description,
'types': 'Copyedit Author Review',
'target': copyedit_assignment.article,
}

notify_helpers.send_email_with_body_from_user(request, 'subject_copyeditor_notify_author',
copyedit_assignment.article.correspondence_author.email,
user_message_content, log_dict=log_dict)
core_email.send_email(
copyedit_assignment.article.correspondence_author,
email_data,
request,
article=copyedit_assignment.article,
log_dict=log_dict,
)
author_review.notified = True
author_review.save()
notify_helpers.send_slack(request, description, ['slack_editors'])


Expand Down Expand Up @@ -782,8 +793,8 @@ def send_copyedit_complete(**kwargs):
def send_author_copyedit_deleted(**kwargs):
request = kwargs.get('request')
author_review = kwargs.get('author_review')
subject = kwargs.get('subject')
user_message_content = kwargs.get('user_message_content')
article = kwargs["article"]
email_data = kwargs.get('email_data')
skip = kwargs.get('skip', False)

description = '{0} has deleted a copyedit review for {1} from {2}'.format(
Expand All @@ -795,26 +806,27 @@ def send_author_copyedit_deleted(**kwargs):
'level': 'Info',
'action_text': description,
'types': 'Author Copyedit Review Deleted',
'target': author_review.assignment.article,
}

if not skip:
notify_helpers.send_email_with_body_from_user(
core_email.send_email(
author_review.author,
email_data,
request,
subject,
author_review.assignment.article.correspondence_author.email,
user_message_content,
article=article,
log_dict=log_dict,
)
else:
util_models.LogEntry.add_entry(
'Author Copyedit Review Deleted',
description,
'Info',
request.user,
request,
author_review.assignment.article,
)

util_models.LogEntry.add_entry(
'Author Copyedit Review Deleted',
description,
'Info',
request.user,
request,
article,
)

notify_helpers.send_slack(request, description, ['slack_editors'])


def send_copyedit_ack(**kwargs):
Expand Down

0 comments on commit f8edb28

Please sign in to comment.