SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 01968ac6 authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

Move email text to templates

parent e0203c0b
No related branches found
No related tags found
No related merge requests found
......@@ -48,8 +48,8 @@ class VetThesisLinkForm(RequestThesisLinkForm):
LINK_DOES_NOT_WORK = 2
THESIS_REFUSAL_CHOICES = (
(EMPTY_CHOICE, '---'),
(ALREADY_EXISTS, 'a link to this thesis already exists'),
(LINK_DOES_NOT_WORK, 'the external link to this thesis does not work'),
(ALREADY_EXISTS, 'A link to this thesis already exists'),
(LINK_DOES_NOT_WORK, 'The external link to this thesis does not work'),
)
action_option = forms.ChoiceField(
......@@ -69,59 +69,38 @@ class VetThesisLinkForm(RequestThesisLinkForm):
'full_url': self.request.build_absolute_uri(
reverse('theses:thesis', kwargs={'thesislink_id': thesislink.id}))
}
if int(self.cleaned_data['action_option']) == VetThesisLinkForm.ACCEPT:
action = int(self.cleaned_data['action_option'])
if action == VetThesisLinkForm.ACCEPT or action == VetThesisLinkForm.MODIFY:
thesislink.vetted = True
thesislink.vetted_by = Contributor.objects.get(user=user)
thesislink.save()
message_plain = render_to_string('theses/thesislink_accepted.txt', mail_params)
print(message_plain)
email = EmailMessage(
'SciPost Thesis Link activated',
message_plain,
'SciPost Theses <theses@scipost.org>',
[thesislink.requested_by.user.email],
['theses@scipost.org'],
reply_to=['theses@scipost.org']
)
email.send(fail_silently=False)
elif int(self.cleaned_data['action_option']) == VetThesisLinkForm.REFUSE:
email_text = ('Dear ' + title_dict[thesislink.requested_by.title] + ' '
+ thesislink.requested_by.user.last_name
+ ', \n\nThe Thesis Link you have requested, concerning thesis with'
+ ' title ' + thesislink.title + ' by ' + thesislink.author
+ ', has not been activated for the following reason: '
+ self.cleaned_data['refusal_reason']
+ '.\n\nThank you for your interest, \nThe SciPost Team.')
if self.cleaned_data['justification']:
email_text += '\n\nFurther explanations: ' + \
self.cleaned_data['justification']
emailmessage = EmailMessage('SciPost Thesis Link', email_text,
'SciPost Theses <theses@scipost.org>',
[thesislink.requested_by.user.email],
['theses@scipost.org'],
reply_to=['theses@scipost.org'])
emailmessage.send(fail_silently=False)
subject_line = 'SciPost Thesis Link activated'
if action == VetThesisLinkForm.ACCEPT:
message_plain = render_to_string('theses/thesislink_accepted.txt', mail_params)
elif action == VetThesisLinkForm.MODIFY:
message_plain = render_to_string('theses/thesislink_modified.txt', mail_params)
elif action == VetThesisLinkForm.REFUSE:
refusal_reason = int(self.cleaned_data['refusal_reason'])
refusal_reason = dict(self.fields['refusal_reason'].choices)[refusal_reason]
mail_params['refusal_reason'] = refusal_reason
mail_params['justification'] = self.cleaned_data['justification']
message_plain = render_to_string('theses/thesislink_refused.txt', mail_params)
subject_line = 'SciPost Thesis Link'
thesislink.delete()
elif int(self.cleaned_data['action_option']) == VetThesisLinkForm.MODIFY:
thesislink.vetted = True
thesislink.vetted_by = Contributor.objects.get(user=user)
thesislink.save()
email_text = ('Dear ' + title_dict[thesislink.requested_by.title] + ' '
+ thesislink.requested_by.user.last_name
+ ', \n\nThe Thesis Link you have requested, concerning thesis with'
+ ' title ' + thesislink.title + ' by ' + thesislink.author
+ ', has been activated '
'(with slight modifications to your submitted details) at '
'https://scipost.org/thesis/' + str(thesislink.id) + '.'
'\n\nThank you for your contribution, \nThe SciPost Team.')
emailmessage = EmailMessage('SciPost Thesis Link activated', email_text,
'SciPost Theses <theses@scipost.org>',
[thesislink.requested_by.user.email],
['theses@scipost.org'],
reply_to=['theses@scipost.org'])
emailmessage.send(fail_silently=False)
email = EmailMessage(
subject_line,
message_plain,
'SciPost Theses <theses@scipost.org>',
[thesislink.requested_by.user.email],
['theses@scipost.org'],
reply_to=['theses@scipost.org']
).send(fail_silently=False)
class ThesisLinkSearchForm(forms.Form):
......
Dear {{ vocative_title }} {{ thesislink.requested_by.user.last_name }},
The Thesis Link you have requested, concerning thesis with title `{{ thesislink.title }}' by {{ thesislink.author }},
has been activated at {{ full_url }}.
The Thesis Link you have requested, concerning thesis with title `{{ thesislink.title }}' by {{ thesislink.author }}, has been activated at {{ full_url }}.
Thank you for your contribution,
The SciPost Team
Dear {{ vocative_title }} {{ thesislink.requested_by.user.last_name }},
The Thesis Link you have requested, concerning thesis with title `{{ thesislink.title }}' by {{ thesislink.author }}, has not been activated for the following reason:
{{ refusal_reason }}.
{% if justification %}
Further explanations:
{{ justification }}
{% endif %}
Thank you for your interest,
The SciPost Team
Dear {{ vocative_title }} {{ thesislink.requested_by.user.last_name }},
The Thesis Link you have requested, concerning thesis with title `{{ thesislink.title }}' by {{ thesislink.author }}, has been activated at (with slight modifications to your submitted details) {{ full_url }}.
Thank you for your contribution,
The SciPost Team
......@@ -131,6 +131,8 @@ class TestVetThesisLinkRequests(TestCase):
post_data = model_form_data(ThesisLinkFactory(), VetThesisLinkForm, form_kwargs={'request': request})
post_data["action_option"] = VetThesisLinkForm.REFUSE
post_data["refusal_reason"] = VetThesisLinkForm.ALREADY_EXISTS
post_data["justification"] = "This thesis already exists."
target = reverse('theses:vet_thesislink', kwargs={'pk': self.thesislink.id})
request = RequestFactory().post(target, post_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment