SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit a500ba2d authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Try using .update and .refresh_from_db for Comment vetting

parent b54f21a4
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,8 @@ __license__ = "AGPL v3" ...@@ -4,7 +4,8 @@ __license__ = "AGPL v3"
from django import forms from django import forms
from .constants import COMMENT_ACTION_CHOICES, COMMENT_REFUSAL_CHOICES from .constants import COMMENT_ACTION_CHOICES, COMMENT_ACTION_REFUSE, \
COMMENT_REFUSAL_CHOICES, COMMENT_REFUSAL_EMPTY
from .models import Comment from .models import Comment
...@@ -35,3 +36,16 @@ class VetCommentForm(forms.Form): ...@@ -35,3 +36,16 @@ class VetCommentForm(forms.Form):
refusal_reason = forms.ChoiceField(choices=COMMENT_REFUSAL_CHOICES) refusal_reason = forms.ChoiceField(choices=COMMENT_REFUSAL_CHOICES)
email_response_field = forms.CharField(widget=forms.Textarea(), email_response_field = forms.CharField(widget=forms.Textarea(),
label='Justification (optional)', required=False) label='Justification (optional)', required=False)
def clean(self):
"""
If the comment is refused, make sure a valid refusal reason is given.
"""
data = super().clean()
print('Cleaning, action_option = %s' % data['action_option'])
if data['action_option'] == str(COMMENT_ACTION_REFUSE):
print('Refusing')
if data['refusal_reason'] == str(COMMENT_REFUSAL_EMPTY):
print('Flagging invalid reason')
self.add_error(None, 'Please choose a valid refusal reason')
return data
...@@ -73,14 +73,15 @@ def vet_submitted_comment(request, comment_id): ...@@ -73,14 +73,15 @@ def vet_submitted_comment(request, comment_id):
if form.is_valid(): if form.is_valid():
if form.cleaned_data['action_option'] == '1': if form.cleaned_data['action_option'] == '1':
# Accept the comment as is # Accept the comment as is
comment.status = 1 Comment.objects.filter(id=comment_id).update(status=1,
comment.vetted_by = request.user.contributor vetted_by=request.user.contributor)
comment.save() comment.refresh_from_db()
# Update `latest_activity` fields # Update `latest_activity` fields
content_object = comment.content_object content_object = comment.content_object
content_object.latest_activity = timezone.now() content_object.objects.filter(id=content_object.id).update(
content_object.save() latest_activity=timezone.now())
content_object.refresh_from_db()
if isinstance(content_object, Submission): if isinstance(content_object, Submission):
# Add events to Submission and send mail to author of the Submission # Add events to Submission and send mail to author of the Submission
...@@ -121,10 +122,9 @@ def vet_submitted_comment(request, comment_id): ...@@ -121,10 +122,9 @@ def vet_submitted_comment(request, comment_id):
elif form.cleaned_data['action_option'] == '2': elif form.cleaned_data['action_option'] == '2':
# The comment request is simply rejected # The comment request is simply rejected
comment.status = int(form.cleaned_data['refusal_reason']) Comment.objects.filter(id=comment.id).update(
if comment.status == 0: status=int(form.cleaned_data['refusal_reason']))
comment.status = -1 # Why's this here?? comment.refresh_from_db()
comment.save()
# Send emails # Send emails
mail_sender = DirectMailUtil( mail_sender = DirectMailUtil(
......
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