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
70b8926d
Commit
70b8926d
authored
8 years ago
by
Geert Kapteijns
Browse files
Options
Downloads
Patches
Plain Diff
Extract comment query logic to manager
parent
25151c15
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
comments/managers.py
+5
-0
5 additions, 0 deletions
comments/managers.py
comments/models.py
+24
-16
24 additions, 16 deletions
comments/models.py
theses/test_views.py
+0
-17
0 additions, 17 deletions
theses/test_views.py
theses/views.py
+5
-7
5 additions, 7 deletions
theses/views.py
with
34 additions
and
40 deletions
comments/managers.py
0 → 100644
+
5
−
0
View file @
70b8926d
from
django.db
import
models
class
CommentManager
(
models
.
Manager
):
def
vetted
(
self
):
return
self
.
filter
(
status__gte
=
1
)
This diff is collapsed.
Click to expand it.
comments/models.py
+
24
−
16
View file @
70b8926d
...
@@ -10,6 +10,8 @@ from scipost.models import TimeStampedModel, Contributor
...
@@ -10,6 +10,8 @@ from scipost.models import TimeStampedModel, Contributor
from
submissions.models
import
Submission
,
Report
from
submissions.models
import
Submission
,
Report
from
theses.models
import
ThesisLink
from
theses.models
import
ThesisLink
from
.managers
import
CommentManager
COMMENT_CATEGORIES
=
(
COMMENT_CATEGORIES
=
(
(
'
ERR
'
,
'
erratum
'
),
(
'
ERR
'
,
'
erratum
'
),
(
'
REM
'
,
'
remark
'
),
(
'
REM
'
,
'
remark
'
),
...
@@ -37,19 +39,24 @@ class Comment(TimeStampedModel):
...
@@ -37,19 +39,24 @@ class Comment(TimeStampedModel):
on a particular publication or in reply to an earlier Comment.
"""
on a particular publication or in reply to an earlier Comment.
"""
status
=
models
.
SmallIntegerField
(
default
=
0
)
status
=
models
.
SmallIntegerField
(
default
=
0
)
vetted_by
=
models
.
ForeignKey
(
Contributor
,
blank
=
True
,
null
=
True
,
vetted_by
=
models
.
ForeignKey
(
on_delete
=
models
.
CASCADE
,
Contributor
,
related_name
=
'
comment_vetted_by
'
)
blank
=
True
,
file_attachment
=
models
.
FileField
(
upload_to
=
'
uploads/comments/%Y/%m/%d/
'
,
blank
=
True
,
null
=
True
,
validators
=
[
validate_file_extension
,
on_delete
=
models
.
CASCADE
,
validate_max_file_size
])
related_name
=
'
comment_vetted_by
'
)
file_attachment
=
models
.
FileField
(
upload_to
=
'
uploads/comments/%Y/%m/%d/
'
,
blank
=
True
,
validators
=
[
validate_file_extension
,
validate_max_file_size
]
)
# a Comment is either for a Commentary or Submission or a ThesisLink.
# a Comment is either for a Commentary or Submission or a ThesisLink.
commentary
=
models
.
ForeignKey
(
Commentary
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
commentary
=
models
.
ForeignKey
(
Commentary
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
submission
=
models
.
ForeignKey
(
Submission
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
submission
=
models
.
ForeignKey
(
Submission
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
thesislink
=
models
.
ForeignKey
(
ThesisLink
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
thesislink
=
models
.
ForeignKey
(
ThesisLink
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
is_author_reply
=
models
.
BooleanField
(
default
=
False
)
is_author_reply
=
models
.
BooleanField
(
default
=
False
)
in_reply_to_comment
=
models
.
ForeignKey
(
'
self
'
,
blank
=
True
,
null
=
True
,
in_reply_to_comment
=
models
.
ForeignKey
(
'
self
'
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
on_delete
=
models
.
CASCADE
)
in_reply_to_report
=
models
.
ForeignKey
(
Report
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
in_reply_to_report
=
models
.
ForeignKey
(
Report
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Contributor
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Contributor
,
on_delete
=
models
.
CASCADE
)
anonymous
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
Publish anonymously
'
)
anonymous
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
Publish anonymously
'
)
...
@@ -64,19 +71,20 @@ class Comment(TimeStampedModel):
...
@@ -64,19 +71,20 @@ class Comment(TimeStampedModel):
is_lit
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
pointer to related literature
'
)
is_lit
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
pointer to related literature
'
)
is_sug
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
suggestion for further work
'
)
is_sug
=
models
.
BooleanField
(
default
=
False
,
verbose_name
=
'
suggestion for further work
'
)
comment_text
=
models
.
TextField
()
comment_text
=
models
.
TextField
()
remarks_for_editors
=
models
.
TextField
(
default
=
''
,
blank
=
True
,
remarks_for_editors
=
models
.
TextField
(
default
=
''
,
blank
=
True
,
verbose_name
=
'
optional remarks for the Editors only
'
)
verbose_name
=
'
optional remarks for the Editors only
'
)
date_submitted
=
models
.
DateTimeField
(
'
date submitted
'
)
date_submitted
=
models
.
DateTimeField
(
'
date submitted
'
)
# Opinions
# Opinions
nr_A
=
models
.
PositiveIntegerField
(
default
=
0
)
nr_A
=
models
.
PositiveIntegerField
(
default
=
0
)
in_agreement
=
models
.
ManyToManyField
(
Contributor
,
in_agreement
=
models
.
ManyToManyField
(
Contributor
,
related_name
=
'
in_agreement
'
,
blank
=
True
)
related_name
=
'
in_agreement
'
,
blank
=
True
)
nr_N
=
models
.
PositiveIntegerField
(
default
=
0
)
nr_N
=
models
.
PositiveIntegerField
(
default
=
0
)
in_notsure
=
models
.
ManyToManyField
(
Contributor
,
in_notsure
=
models
.
ManyToManyField
(
Contributor
,
related_name
=
'
in_notsure
'
,
blank
=
True
)
related_name
=
'
in_notsure
'
,
blank
=
True
)
nr_D
=
models
.
PositiveIntegerField
(
default
=
0
)
nr_D
=
models
.
PositiveIntegerField
(
default
=
0
)
in_disagreement
=
models
.
ManyToManyField
(
Contributor
,
in_disagreement
=
models
.
ManyToManyField
(
related_name
=
'
in_disagreement
'
,
blank
=
True
)
Contributor
,
related_name
=
'
in_disagreement
'
,
blank
=
True
)
objects
=
CommentManager
()
def
__str__
(
self
):
def
__str__
(
self
):
return
(
'
by
'
+
self
.
author
.
user
.
first_name
+
'
'
+
self
.
author
.
user
.
last_name
+
return
(
'
by
'
+
self
.
author
.
user
.
first_name
+
'
'
+
self
.
author
.
user
.
last_name
+
...
...
This diff is collapsed.
Click to expand it.
theses/test_views.py
+
0
−
17
View file @
70b8926d
...
@@ -30,23 +30,6 @@ class TestThesisDetail(TestCase):
...
@@ -30,23 +30,6 @@ class TestThesisDetail(TestCase):
response
=
client
.
post
(
target
)
response
=
client
.
post
(
target
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
# def test_submitting_comment_creates_comment(self):
# """ Valid Comment gets saved """
#
# contributor = ContributorFactory()
# thesislink = ThesisLinkFactory()
# valid_comment_data = model_form_data(CommentFactory.build(), CommentForm)
# target = reverse('theses:thesis', kwargs={'thesislink_id': thesislink.id})
#
# comment_count = Comment.objects.filter(author=contributor).count()
# self.assertEqual(comment_count, 0)
#
# request = RequestFactory().post(target, valid_comment_data)
# request.user = contributor.user
# response = thesis_detail(request, thesislink_id=thesislink.id)
#
# comment_count = Comment.objects.filter(author=contributor).count()
# self.assertEqual(comment_count, 1)
class
TestRequestThesisLink
(
TestCase
):
class
TestRequestThesisLink
(
TestCase
):
...
...
This diff is collapsed.
Click to expand it.
theses/views.py
+
5
−
7
View file @
70b8926d
...
@@ -131,14 +131,12 @@ def browse(request, discipline, nrweeksback):
...
@@ -131,14 +131,12 @@ def browse(request, discipline, nrweeksback):
def
thesis_detail
(
request
,
thesislink_id
):
def
thesis_detail
(
request
,
thesislink_id
):
thesislink
=
get_object_or_404
(
ThesisLink
,
pk
=
thesislink_id
)
thesislink
=
get_object_or_404
(
ThesisLink
,
pk
=
thesislink_id
)
comments
=
thesislink
.
comment_set
.
all
()
form
=
CommentForm
()
form
=
CommentForm
()
try
:
author_replies
=
Comment
.
objects
.
filter
(
thesislink
=
thesislink
,
is_author_reply
=
True
)
comments
=
thesislink
.
comment_set
except
Comment
.
DoesNotExist
:
author_replies
=
comments
.
filter
(
is_author_reply
=
True
)
author_replies
=
()
# TODO: make manager for horribly obfuscating 'status__gte=1'
context
=
{
'
thesislink
'
:
thesislink
,
context
=
{
'
thesislink
'
:
thesislink
,
'
comments
'
:
comments
.
filter
(
status__gte
=
1
).
order_by
(
'
date_submitted
'
),
'
comments
'
:
comments
.
vetted
(
).
order_by
(
'
date_submitted
'
),
'
author_replies
'
:
author_replies
,
'
form
'
:
form
}
'
author_replies
'
:
author_replies
,
'
form
'
:
form
}
return
render
(
request
,
'
theses/thesis_detail.html
'
,
context
)
return
render
(
request
,
'
theses/thesis_detail.html
'
,
context
)
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