SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
a500ba2d
Commit
a500ba2d
authored
6 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
comments/forms.py
+15
-1
15 additions, 1 deletion
comments/forms.py
comments/views.py
+9
-9
9 additions, 9 deletions
comments/views.py
with
24 additions
and
10 deletions
comments/forms.py
+
15
−
1
View file @
a500ba2d
...
@@ -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
This diff is collapsed.
Click to expand it.
comments/views.py
+
9
−
9
View file @
a500ba2d
...
@@ -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
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment