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
SRCT
bookshare
Commits
dab012de
Commit
dab012de
authored
Apr 07, 2015
by
Daniel W Bond
Browse files
added (cpu intensive) charts page
parent
48e33740
Changes
3
Hide whitespace changes
Inline
Side-by-side
bookshare/settings/urls.py
View file @
dab012de
from
django.conf.urls
import
patterns
,
include
,
url
from
.views
import
HomepageView
from
.views
import
HomepageView
,
ChartsView
from
django.views.generic
import
TemplateView
from
django.contrib
import
admin
...
...
@@ -22,7 +22,8 @@ urlpatterns = patterns('',
url
(
r
'^search/'
,
include
(
'haystack.urls'
),
name
=
'search'
),
### static pages ###
url
(
r
'^$'
,
HomepageView
.
as_view
(
template_name
=
'index.html'
),
name
=
'homepage'
),
url
(
r
'^$'
,
HomepageView
.
as_view
(),
name
=
'homepage'
),
url
(
r
'^charts/?$'
,
ChartsView
.
as_view
(),
name
=
'charts'
),
url
(
r
'^about/?$'
,
TemplateView
.
as_view
(
template_name
=
'about.html'
),
name
=
'about'
),
url
(
r
'^privacy/?$'
,
TemplateView
.
as_view
(
template_name
=
'privacy.html'
),
name
=
'privacy'
),
url
(
r
'^privacy/opt-out/?$'
,
'core.views.privacy_opt_out'
,
name
=
'privacy_opt_out'
),
...
...
bookshare/settings/views.py
View file @
dab012de
from
lookouts.models
import
Lookout
from
trades.models
import
Listing
,
Bid
from
core.models
import
Student
from
django.views.generic
import
TemplateView
from
collections
import
Counter
class
HomepageView
(
TemplateView
):
template_name
=
'index.html'
...
...
@@ -10,3 +14,33 @@ class HomepageView(TemplateView):
if
self
.
request
.
user
.
is_authenticated
():
context
[
'lookouts'
]
=
Lookout
.
objects
.
filter
(
owner
=
self
.
request
.
user
.
student
)
return
context
class
ChartsView
(
TemplateView
):
template_name
=
'charts.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
ChartsView
,
self
).
get_context_data
(
**
kwargs
)
all_listings
=
Listing
.
objects
.
exclude
(
cancelled
=
True
)
all_isbns
=
[
listing
.
isbn
for
listing
in
all_listings
]
grossing
=
[]
# set to eliminate duplicates
for
isbn
in
set
(
all_isbns
):
# only want sold listings (not cancelled is assumed)
listings
=
Listing
.
objects
.
exclude
(
sold
=
False
).
filter
(
isbn
=
isbn
)
# make a list of all of that listing's final prices (assuming no Nones)
listing_winning_bids
=
[
listing
.
final_price
()
for
listing
in
listings
]
# add all those together
listing_gross
=
sum
(
listing_winning_bids
)
# make a tuple of the isbn and gross and add it to the list
grossing
.
append
(
(
isbn
,
listing_gross
)
)
context
[
'most_popular'
]
=
Counter
(
all_isbns
).
most_common
(
20
)
# sort by the second element of the tuple, descending
context
[
'highest_grossing'
]
=
sorted
(
grossing
,
key
=
lambda
li
:
li
[
1
],
reverse
=
True
)[:
20
]
context
[
'total_listings'
]
=
all_listings
.
count
()
context
[
'total_bids'
]
=
Bid
.
objects
.
count
()
context
[
'total_students'
]
=
Student
.
objects
.
count
()
return
context
bookshare/templates/charts.html
0 → 100644
View file @
dab012de
{% extends 'layouts/base.html' %}
{% block title %}
SRCT Bookshare
•
Charts
{% endblock %}
{% block content %}
{% load humanize %}
{% load trades_extras %}
<div
class=
"page-header"
id=
"banner"
>
<div
class=
"row"
>
<div
class=
"col-lg-12 text-center"
>
<h1><strong>
SRCT
</strong>
BOOKSHARE
</h1>
<p
class=
"lead"
><strong>
Listing Charts
</strong></p>
</div>
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-md-12 text-center"
>
<p><h2>
Featuring
<strong>
{{ total_bids|intcomma }} bids
</strong>
on
<strong>
{{ total_listings|intcomma }} listings
</strong>
from
<strong>
{{ total_students|intcomma }} students
</strong>
(so far).
</h2></p>
</div>
</div>
<legend></legend>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading text-center"
>
<h3><strong>
Most Popular
</strong></h3>
</div>
<div
class=
"panel-body"
>
<table
class=
"table table-hover text-center"
>
<thead>
<tr>
<td
class=
"col-md-8"
><h4><strong>
Title
</strong></h4></td>
<td
class=
"col-md-4"
><h4><strong>
Listings
</strong></h4></td>
</tr>
</thead>
<tbody>
{% for isbn, occurrence in most_popular %}
<tr>
<td><h5><a
href=
"/search/?q={{ isbn }}"
>
{{ isbn|isbn_name|title }}
</a></h5></td>
<td><h5>
{{ occurrence }}
</h5></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div
class=
"col-md-6"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading text-center"
>
<h3><strong>
Highest-Grossing
</strong></h3>
</div>
<div
class=
"panel-body"
>
<table
class=
"table table-hover text-center"
>
<thead>
<tr>
<td
class=
"col-md-8"
><h4><strong>
Title
</strong></h4></td>
<td
class=
"col-md-4"
><h4><strong>
Proceeds
</strong></h4></td>
</tr>
</thead>
<tbody>
{% for isbn, total_sum in highest_grossing %}
<tr>
<td><h5><a
href=
"/search/?q={{ isbn }}"
>
{{ isbn|isbn_name|title }}
</a></h5></td>
<td><h5>
${{ total_sum }}
</h5></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
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