Add subscriptions stats

This commit is contained in:
2017-06-02 15:02:28 +02:00
parent e7f7c57558
commit e97135bf47
6 changed files with 110 additions and 44 deletions

View File

@ -0,0 +1,38 @@
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}Subscription stats{% endtrans %}
{% endblock %}
{% block content %}
{% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}<br><br>
{% trans %}Subscriptions by type{% endtrans %}<br><br>
{% for location in locations %}
{{ location[1] }} {{ subscriptions_total.filter(location=location[0]).count() }}<br>
{% endfor %}
<br>
<table>
<tr>
<th>{% trans %}Subscripton type{% endtrans %}</th>
{% for location in locations %}
<th>{{ location[1] }}</th>
{% endfor %}
{% for type in subscriptions_types %}
<tr>
<td>{{ subscriptions_types[type]['name'] }}</td>
{% for location in locations %}
<td>
{% trans %}Total{% endtrans %} : {{ subscriptions_total.filter(location=location[0]).count()}}<br>
{% for p_type in payment_types %}
{{ p_type[1] }} : {{ subscriptions_total.filter(location=location[0], payment_method=p_type[0]).count()}}<br>
{% endfor %}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -22,13 +22,14 @@
#
#
from django.conf.urls import url, include
from django.conf.urls import url
from subscription.views import *
urlpatterns = [
# Subscription views
url(r'^$', NewSubscription.as_view(), name='subscription'),
url(r'stats', SubscriptionsStatsView.as_view(), name='stats'),
]

View File

@ -25,6 +25,7 @@
from django.shortcuts import render
from django.views.generic.edit import UpdateView, CreateView
from django.views.generic.base import View
from django.views.generic import TemplateView
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import PermissionDenied, ValidationError
from django.db import IntegrityError
@ -114,3 +115,22 @@ class NewSubscription(CreateView):
)
return super(NewSubscription, self).form_valid(form)
class SubscriptionsStatsView(TemplateView):
template_name = "subscription/stats.jinja"
def dispatch(self, request, *arg, **kwargs):
res = super(SubscriptionsStatsView, self).dispatch(request, *arg, **kwargs)
if request.user.is_root or request.user.is_board_member:
return res
raise PermissionDenied
def get_context_data(self, **kwargs):
from subscription.models import Subscription
import datetime
kwargs = super(SubscriptionsStatsView, self).get_context_data(**kwargs)
kwargs['subscriptions_total'] = Subscription.objects.filter(subscription_end__gte=datetime.datetime.today())
kwargs['subscriptions_types'] = settings.SITH_SUBSCRIPTIONS
kwargs['payment_types'] = settings.SITH_COUNTER_PAYMENT_METHOD
kwargs['locations'] = settings.SITH_SUBSCRIPTION_LOCATIONS
return kwargs