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
b5a6e93a
Commit
b5a6e93a
authored
8 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Commentaries list view to CBV
parent
bd6d8c23
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
commentaries/forms.py
+6
-6
6 additions, 6 deletions
commentaries/forms.py
commentaries/urls.py
+1
-1
1 addition, 1 deletion
commentaries/urls.py
commentaries/views.py
+31
-14
31 additions, 14 deletions
commentaries/views.py
comments/managers.py
+1
-0
1 addition, 0 deletions
comments/managers.py
with
39 additions
and
21 deletions
commentaries/forms.py
+
6
−
6
View file @
b5a6e93a
...
@@ -214,13 +214,13 @@ class VetCommentaryForm(forms.Form):
...
@@ -214,13 +214,13 @@ class VetCommentaryForm(forms.Form):
class
CommentarySearchForm
(
forms
.
Form
):
class
CommentarySearchForm
(
forms
.
Form
):
"""
Search for Commentary specified by user
"""
"""
Search for Commentary specified by user
"""
pub_
author
=
forms
.
CharField
(
max_length
=
100
,
required
=
False
,
label
=
"
Author(s)
"
)
author
=
forms
.
CharField
(
max_length
=
100
,
required
=
False
,
label
=
"
Author(s)
"
)
pub_
title
_keyword
=
forms
.
CharField
(
max_length
=
100
,
required
=
False
,
label
=
"
Title
"
)
title
=
forms
.
CharField
(
max_length
=
100
,
required
=
False
,
label
=
"
Title
"
)
pub_
abstract
_keyword
=
forms
.
CharField
(
max_length
=
1000
,
required
=
False
,
label
=
"
Abstract
"
)
abstract
=
forms
.
CharField
(
max_length
=
1000
,
required
=
False
,
label
=
"
Abstract
"
)
def
search_results
(
self
):
def
search_results
(
self
):
"""
Return all Commentary objects according to search
"""
"""
Return all Commentary objects according to search
"""
return
Commentary
.
objects
.
vetted
(
return
Commentary
.
objects
.
vetted
(
pub_title__icontains
=
self
.
cleaned_data
[
'
pub_
title
_keyword
'
],
pub_title__icontains
=
self
.
cleaned_data
[
'
title
'
],
pub_abstract__icontains
=
self
.
cleaned_data
[
'
pub_
abstract
_keyword
'
],
pub_abstract__icontains
=
self
.
cleaned_data
[
'
abstract
'
],
author_list__icontains
=
self
.
cleaned_data
[
'
pub_
author
'
]).
order_by
(
'
-pub_date
'
)
author_list__icontains
=
self
.
cleaned_data
[
'
author
'
]).
order_by
(
'
-pub_date
'
)
This diff is collapsed.
Click to expand it.
commentaries/urls.py
+
1
−
1
View file @
b5a6e93a
...
@@ -5,7 +5,7 @@ from . import views
...
@@ -5,7 +5,7 @@ from . import views
urlpatterns
=
[
urlpatterns
=
[
# Commentaries
# Commentaries
url
(
r
'
^$
'
,
views
.
c
ommentar
ies
,
name
=
'
commentaries
'
),
url
(
r
'
^$
'
,
views
.
C
ommentar
yListView
.
as_view
()
,
name
=
'
commentaries
'
),
url
(
r
'
^browse/(?P<discipline>[a-z]+)/(?P<nrweeksback>[0-9]+)/$
'
,
views
.
browse
,
name
=
'
browse
'
),
url
(
r
'
^browse/(?P<discipline>[a-z]+)/(?P<nrweeksback>[0-9]+)/$
'
,
views
.
browse
,
name
=
'
browse
'
),
url
(
r
'
^howto$
'
,
TemplateView
.
as_view
(
template_name
=
'
commentaries/howto.html
'
),
name
=
'
howto
'
),
url
(
r
'
^howto$
'
,
TemplateView
.
as_view
(
template_name
=
'
commentaries/howto.html
'
),
name
=
'
howto
'
),
...
...
This diff is collapsed.
Click to expand it.
commentaries/views.py
+
31
−
14
View file @
b5a6e93a
...
@@ -13,6 +13,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
...
@@ -13,6 +13,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.views.generic.edit
import
CreateView
,
FormView
from
django.views.generic.edit
import
CreateView
,
FormView
from
django.views.generic.list
import
ListView
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
.models
import
Commentary
from
.models
import
Commentary
...
@@ -267,21 +268,37 @@ def vet_commentary_request_ack(request, commentary_id):
...
@@ -267,21 +268,37 @@ def vet_commentary_request_ack(request, commentary_id):
return
render
(
request
,
'
scipost/acknowledgement.html
'
,
context
)
return
render
(
request
,
'
scipost/acknowledgement.html
'
,
context
)
def
commentaries
(
request
):
class
CommentaryListView
(
ListView
):
"""
List and search all commentaries
"""
model
=
Commentary
form
=
CommentarySearchForm
(
request
.
POST
or
None
)
form
=
CommentarySearchForm
if
form
.
is_valid
()
and
form
.
has_changed
():
paginate_by
=
10
commentary_search_list
=
form
.
search_results
()
else
:
commentary_search_list
=
[]
comment_recent_list
=
Comment
.
objects
.
filter
(
status
=
'
1
'
).
order_by
(
'
-date_submitted
'
)[:
10
]
def
get_queryset
(
self
):
commentary_recent_list
=
Commentary
.
objects
.
vetted
().
order_by
(
'
-latest_activity
'
)[:
10
]
'''
Perform search form here already to get the right pagination numbers.
'''
context
=
{
self
.
form
=
self
.
form
(
self
.
request
.
GET
)
'
form
'
:
form
,
'
commentary_search_list
'
:
commentary_search_list
,
if
self
.
form
.
is_valid
():
'
comment_recent_list
'
:
comment_recent_list
,
return
self
.
form
.
search_results
()
'
commentary_recent_list
'
:
commentary_recent_list
}
return
self
.
model
.
objects
.
vetted
().
order_by
(
'
-latest_activity
'
)
return
render
(
request
,
'
commentaries/commentaries.html
'
,
context
)
def
get_context_data
(
self
,
**
kwargs
):
# Call the base implementation first to get a context
context
=
super
().
get_context_data
(
**
kwargs
)
# Get newest comments
context
[
'
comment_list
'
]
=
Comment
.
objects
.
vetted
().
order_by
(
'
-date_submitted
'
)[:
10
]
# Form into the context!
context
[
'
form
'
]
=
self
.
form
# To customize display in the template
if
'
discipline
'
in
self
.
kwargs
:
context
[
'
discipline
'
]
=
self
.
kwargs
[
'
discipline
'
]
context
[
'
nrweeksback
'
]
=
self
.
kwargs
[
'
nrweeksback
'
]
context
[
'
browse
'
]
=
True
elif
not
any
(
argument
in
[
'
title
'
,
'
author
'
,
'
abstract
'
]
for
argument
in
self
.
request
.
GET
):
context
[
'
recent
'
]
=
True
return
context
def
browse
(
request
,
discipline
,
nrweeksback
):
def
browse
(
request
,
discipline
,
nrweeksback
):
...
...
This diff is collapsed.
Click to expand it.
comments/managers.py
+
1
−
0
View file @
b5a6e93a
from
django.db
import
models
from
django.db
import
models
class
CommentManager
(
models
.
Manager
):
class
CommentManager
(
models
.
Manager
):
def
vetted
(
self
):
def
vetted
(
self
):
return
self
.
filter
(
status__gte
=
1
)
return
self
.
filter
(
status__gte
=
1
)
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