diff --git a/theses/forms.py b/theses/forms.py index 758b586096d923282f2743dac7cb9b11d571c738..3f5dfcc0e5784131d4e8a0d9f7039bad5b07064a 100644 --- a/theses/forms.py +++ b/theses/forms.py @@ -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): diff --git a/theses/templates/theses/thesislink_accepted.txt b/theses/templates/theses/thesislink_accepted.txt index d1ccc54145d6d00e7b765c5c5fc8209e99733bdc..dd3f511a4093ecbc784a8a321d2b87ba2a6121da 100644 --- a/theses/templates/theses/thesislink_accepted.txt +++ b/theses/templates/theses/thesislink_accepted.txt @@ -1,8 +1,6 @@ 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 diff --git a/theses/templates/theses/thesislink_refused.txt b/theses/templates/theses/thesislink_refused.txt new file mode 100644 index 0000000000000000000000000000000000000000..0528fe6ff0831720c081e1605a2b97c9ab7c4eb5 --- /dev/null +++ b/theses/templates/theses/thesislink_refused.txt @@ -0,0 +1,11 @@ +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 diff --git a/theses/templates/thesislink_modified.txt b/theses/templates/thesislink_modified.txt new file mode 100644 index 0000000000000000000000000000000000000000..b39ffd34d057f348281108990de698342780758a --- /dev/null +++ b/theses/templates/thesislink_modified.txt @@ -0,0 +1,6 @@ +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 diff --git a/theses/test_views.py b/theses/test_views.py index f049bbc38f5bc67a694ef8d4778c0b1e88028d22..068fd5935d30c2ad0d8da087b866a709ad69767f 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -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)