mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add subscriptions stats
This commit is contained in:
38
subscription/templates/subscription/stats.jinja
Normal file
38
subscription/templates/subscription/stats.jinja
Normal 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 %}
|
@ -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'),
|
||||
]
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user