From e06a8e8e2b398c572e915b69fac6ae3f28c689a9 Mon Sep 17 00:00:00 2001 From: Geert Kapteijns <ghkapteijns@gmail.com> Date: Thu, 15 Dec 2016 17:54:40 +0100 Subject: [PATCH] Fix redirect error in thesis detailview after posting comment --- comments/forms.py | 1 - comments/models.py | 8 ++------ theses/factories.py | 2 +- theses/forms.py | 1 + theses/test_views.py | 9 +++++++++ theses/views.py | 9 ++++----- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/comments/forms.py b/comments/forms.py index 0e94f326e..d87f969a3 100644 --- a/comments/forms.py +++ b/comments/forms.py @@ -62,7 +62,6 @@ class CommentForm(forms.ModelForm): ) - class VetCommentForm(forms.Form): action_option = forms.ChoiceField(widget=forms.RadioSelect, choices=COMMENT_ACTION_CHOICES, required=True, label='Action') diff --git a/comments/models.py b/comments/models.py index d18801033..1e6c1c5d1 100644 --- a/comments/models.py +++ b/comments/models.py @@ -33,15 +33,11 @@ COMMENT_STATUS = ( ) comment_status_dict = dict(COMMENT_STATUS) + class Comment(models.Model): """ A Comment is an unsollicited note, submitted by a Contributor, on a particular publication or in reply to an earlier Comment. """ - # status: - # 1: vetted - # 0: unvetted - # -1: rejected (unclear) - # -2: rejected (incorrect) - # -3: rejected (not useful) + status = models.SmallIntegerField(default=0) vetted_by = models.ForeignKey(Contributor, blank=True, null=True, on_delete=models.CASCADE, diff --git a/theses/factories.py b/theses/factories.py index 522f63b96..19489c3c1 100644 --- a/theses/factories.py +++ b/theses/factories.py @@ -1,6 +1,6 @@ import factory from .models import ThesisLink -from scipost.factories import UserFactory, ContributorFactory +from scipost.factories import ContributorFactory class ThesisLinkFactory(factory.django.DjangoModelFactory): diff --git a/theses/forms.py b/theses/forms.py index 9186071a2..2193a767c 100644 --- a/theses/forms.py +++ b/theses/forms.py @@ -28,6 +28,7 @@ class RequestThesisLinkForm(forms.ModelForm): self.fields['pub_link'].widget.attrs.update({'placeholder': 'Full URL'}) self.fields['abstract'].widget.attrs.update({'cols': 100}) + class VetThesisLinkForm(forms.Form): action_option = forms.ChoiceField(widget=forms.RadioSelect, choices=THESIS_ACTION_CHOICES, diff --git a/theses/test_views.py b/theses/test_views.py index 2e9cb5f6b..e1c9c7982 100644 --- a/theses/test_views.py +++ b/theses/test_views.py @@ -1 +1,10 @@ from django.test import TestCase +from django.test.client import Client + + +class TestThesisDetail(TestCase): + + def test_acknowledges_after_submitting_comment(self): + client = Client() + response = client.post('/theses/1') + self.assertEqual(response.get('location'), 'bladiebla') diff --git a/theses/views.py b/theses/views.py index 2f1be437a..7a2a2309d 100644 --- a/theses/views.py +++ b/theses/views.py @@ -137,8 +137,6 @@ def vet_thesislink_request_ack(request, thesislink_id): emailmessage.send(fail_silently=False) thesislink.delete() - #context = {'thesislink_id': thesislink_id } - # return render(request, 'theses/vet_thesislink_request_ack.html', context) context = {'ack_header': 'Thesis Link request vetted.', 'followup_message': 'Return to the ', 'followup_link': reverse('theses:vet_thesislink_requests'), @@ -207,7 +205,7 @@ def thesis_detail(request, thesislink_id): form = CommentForm(request.POST) if form.is_valid(): author = Contributor.objects.get(user=request.user) - newcomment = Comment( + new_comment = Comment( thesislink=thesislink, author=author, is_rem=form.cleaned_data['is_rem'], @@ -222,11 +220,12 @@ def thesis_detail(request, thesislink_id): remarks_for_editors=form.cleaned_data['remarks_for_editors'], date_submitted=timezone.now(), ) - newcomment.save() + new_comment.save() author.nr_comments = Comment.objects.filter(author=author).count() author.save() request.session['thesislink_id'] = thesislink_id - return HttpResponseRedirect(reverse('comments:comment_submission_ack')) + context = {} + return render(request, 'scipost/acknowledgement.html', context) else: form = CommentForm() -- GitLab