added db metrics page [deliver #26022545] /info/metrics.html

pull/1/head
eric 2012-03-07 22:06:30 -05:00
parent de4f5fcc86
commit 142fe72f93
4 changed files with 130 additions and 1 deletions

View File

@ -0,0 +1,83 @@
{% extends "basedocumentation.html" %}
{% block title %} Metrics {% endblock %}
{% block doccontent %}
<h2>Users</h2>
<dl>
<dt> How many ungluers have registered?</dt>
<dd>
<ul>
<li>{{ users.today.count }} have registered today. They are
<ul>{% for user in users.today %}
<li><a href="{% url supporter user.username %}">{{user.username}}</a></li>
{% endfor %}</ul>
<br />{{ wishlists.today.count }} of them have 1 or more items on a wishlist.
</li>
<li>{{ users.days7.count }} have registered in the past 7 days.
<br />{{ wishlists.days7.count }} of them have 1 or more items on a wishlist.
</li>
<li>{{ users.month.count }} have registered in this month.
<br />{{ wishlists.month.count }} of them have 1 or more items on a wishlist.
</li>
<li>{{ users.all.count }} have registered in total.
<br />{{ wishlists.all.count }} of them have 1 or more items on a wishlist.
</li>
</ul>
</dd>
</dl>
<h2>Works</h2>
<dl>
<dt> How many works have been added to Unglue.it?</dt>
<dd>
<ul>
<li>{{ works.today.count }} have been added today. They are
<ul>{% for work in users_today %}
<li><a href="{% url work work.id %}">{{work.title}}</a></li>
{% endfor %}</ul>
</li>
<li>{{ works.days7.count }} have been added in the past 7 days.
</li>
<li>{{ works.month.count }} have been added in this month.
</li>
<li>{{ works.all.count }} have been added in total.
</li>
</ul>
</dd>
<dt> How often have the works been wished?</dt>
<dd>
<ul>
<li>{{ works.wishedby50.count }} have been wished by more than 50 ungluers.
</li>
<li>{{ works.wishedby20.count }} have been wished by more than 20 ungluers.
</li>
<li>{{ works.wishedby10.count }} have been wished by more than 10 ungluers.
</li>
<li>{{ works.wishedby5.count }} have been wished by more than 5 ungluers.
</li>
<li>{{ works.wishedby2.count }} have been wished by more than 2 ungluers.
</li>
</ul>
</dd>
</dl>
<h2>Ebooks</h2>
<dl>
<dt> How many ebooks have been added to Unglue.it?</dt>
<dd>
<ul>
<li>{{ ebooks.today.count }} have been added today. They are
<ul>{% for work in users_today %}
<li><a href="{% url work ebook.edition.work.id %}">{{ebook.edition.work.title}}</a></li>
{% endfor %}</ul>
</li>
<li>{{ ebooks.days7.count }} have been added in the past 7 days.
</li>
<li>{{ ebooks.month.count }} have been added in this month.
</li>
<li>{{ ebooks.all.count }} have been added in total.
</li>
</ul>
</dd>
</dl>
{% endblock %}

View File

@ -64,6 +64,8 @@ class PageTests(TestCase):
self.assertEqual(r.status_code, 200)
r = anon_client.get("/search/?q=sverige")
self.assertEqual(r.status_code, 200)
r = anon_client.get("/info/metrics.html")
self.assertEqual(r.status_code, 200)
class GoogleBooksTest(TestCase):

View File

@ -7,7 +7,7 @@ from django.conf import settings
from regluit.core.models import Campaign
from regluit.frontend.views import CampaignFormView, GoodreadsDisplayView, LibraryThingView, PledgeView, PledgeCompleteView, PledgeCancelView, FAQView
from regluit.frontend.views import CampaignListView, DonateView, WorkListView, UngluedListView
from regluit.frontend.views import CampaignListView, DonateView, WorkListView, UngluedListView, InfoPageView
urlpatterns = patterns(
"regluit.frontend.views",
@ -61,6 +61,7 @@ urlpatterns = patterns(
url(r"^about/$", TemplateView.as_view(template_name="about.html"),
name="about"),
url(r"^comments/$", "comment", name="comment"),
url(r"^info/(?P<template_name>[\w\.]*)$", InfoPageView.as_view()),
)
if not settings.IS_PREVIEW:

View File

@ -1002,6 +1002,49 @@ class CampaignFormView(FormView):
logger.info("CampaignFormView paypal: Error " + str(t.reference))
return HttpResponse(response)
class InfoPageView(TemplateView):
def get_template_names(self, **kwargs):
if self.kwargs['template_name']:
return (self.kwargs['template_name'])
else:
return ('metrics.html')
def get_context_data(self, **kwargs):
users = User.objects
users.today = users.filter(date_joined__range = (datetime.date.today(), datetime.datetime.now()))
users.days7 = users.filter(date_joined__range = (datetime.date.today()-datetime.timedelta(days=7), datetime.datetime.now()))
users.year = users.filter(date_joined__year = datetime.date.today().year)
users.month = users.year.filter(date_joined__month = datetime.date.today().month)
works = models.Work.objects
works.today = works.filter(created__range = (datetime.date.today(), datetime.datetime.now()))
works.days7 = works.filter(created__range = (datetime.date.today()-datetime.timedelta(days=7), datetime.datetime.now()))
works.year = works.filter(created__year = datetime.date.today().year)
works.month = works.year.filter(created__month = datetime.date.today().month)
works.wishedby2 = works.filter(num_wishes__gte = 2)
works.wishedby20 = works.filter(num_wishes__gte = 20)
works.wishedby5 = works.filter(num_wishes__gte = 5)
works.wishedby50 = works.filter(num_wishes__gte = 50)
works.wishedby10 = works.filter(num_wishes__gte = 10)
works.wishedby100 = works.filter(num_wishes__gte = 100)
ebooks = models.Ebook.objects
ebooks.today = ebooks.filter(created__range = (datetime.date.today(), datetime.datetime.now()))
ebooks.days7 = ebooks.filter(created__range = (datetime.date.today()-datetime.timedelta(days=7), datetime.datetime.now()))
ebooks.year = ebooks.filter(created__year = datetime.date.today().year)
ebooks.month = ebooks.year.filter(created__month = datetime.date.today().month)
wishlists= models.Wishlist.objects.exclude(wishes__isnull=True)
wishlists.today = wishlists.filter(created__range = (datetime.date.today(), datetime.datetime.now()))
wishlists.days7 = wishlists.filter(created__range = (datetime.date.today()-datetime.timedelta(days=7), datetime.datetime.now()))
wishlists.year = wishlists.filter(created__year = datetime.date.today().year)
wishlists.month = wishlists.year.filter(created__month = datetime.date.today().month)
return {
'users': users,
'works': works,
'ebooks': ebooks,
'wishlists': wishlists,
}
class FAQView(TemplateView):
template_name = "faq.html"
def get_context_data(self, **kwargs):