Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jean Michel Rouly
bookshare
Commits
54998bed
Commit
54998bed
authored
May 01, 2015
by
Daniel W Bond
Browse files
defined mod querysets
parent
3cc948c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
bookshare/mod/views.py
View file @
54998bed
# core django imports
# core django imports
from
django.views.generic
import
TemplateView
,
ListView
from
django.views.generic
import
TemplateView
,
ListView
from
django.db.models
import
Sum
from
django.db.models
import
Count
# third party imports
# third party imports
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
# imports from your apps
# imports from your apps
from
trades.models
import
Listing
from
trades.models
import
Listing
from
core.models
import
Student
class
ModLandingView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
TemplateView
):
class
ModLandingView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
TemplateView
):
template_name
=
'mod.html'
template_name
=
'mod.html'
login_url
=
'login'
class
FlagModView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
ListView
):
class
FlagModView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
ListView
):
queryset
=
Listing
.
objects
.
annotate
(
num_flags
=
Count
(
'flag'
)).
order_by
(
'-num_flags'
)[:
20
]
queryset
=
Listing
.
objects
.
annotate
(
num_flags
=
Count
(
'flag'
)).
order_by
(
'-num_flags'
)[:
20
]
context_object_name
=
'listings'
context_object_name
=
'listings'
...
@@ -17,8 +20,8 @@ class FlagModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
...
@@ -17,8 +20,8 @@ class FlagModView(LoginRequiredMixin, SuperuserRequiredMixin, ListView):
login_url
=
'login'
login_url
=
'login'
class
ListingNumModView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
ListView
):
class
ListingNumModView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
ListView
):
queryset
=
Listing
.
objects
.
a
ll
(
)[:
20
]
queryset
=
Student
.
objects
.
a
nnotate
(
num_books
=
Count
(
'listing'
)).
order_by
(
'-num_books'
)[:
20
]
context_object_name
=
'
user
s'
context_object_name
=
'
student
s'
template_name
=
'listing_num_mod.html'
template_name
=
'listing_num_mod.html'
login_url
=
'login'
login_url
=
'login'
...
@@ -26,5 +29,10 @@ class UserEmailRatioModView(LoginRequiredMixin, SuperuserRequiredMixin, Template
...
@@ -26,5 +29,10 @@ class UserEmailRatioModView(LoginRequiredMixin, SuperuserRequiredMixin, Template
template_name
=
'email_ratio_mod.html'
template_name
=
'email_ratio_mod.html'
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
UserEmailRatioView
,
self
).
get_context_data
(
**
kwargs
)
context
=
super
(
UserEmailRatioModView
,
self
).
get_context_data
(
**
kwargs
)
students_by_emails
=
Student
.
objects
.
order_by
(
'-emails_sent'
)[:
20
]
students_listings
=
students_by_emails
.
annotate
(
num_books
=
Count
(
'listing'
))
context
[
'email_happy_students'
]
=
students_listings
return
context
return
context
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment