From 114272df2fc634b3d1d4d02b70b9c77a9f2ff725 Mon Sep 17 00:00:00 2001 From: Skia Date: Fri, 25 Nov 2016 15:26:45 +0100 Subject: [PATCH] Add simple club stats --- club/templates/club/stats.jinja | 49 +++++++++++++++++++++++++++++++++ club/urls.py | 1 + club/views.py | 10 ++++++- core/models.py | 17 ++---------- sith/settings.py | 16 +++++++++++ 5 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 club/templates/club/stats.jinja diff --git a/club/templates/club/stats.jinja b/club/templates/club/stats.jinja new file mode 100644 index 00000000..cf6c3358 --- /dev/null +++ b/club/templates/club/stats.jinja @@ -0,0 +1,49 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}Club stats{% endtrans %} +{% endblock %} + +{% block content %} + {% if club_list %} +

{% trans %}Club stats{% endtrans %}

+
+ {% csrf_token %} +

+ +

+

+
+ + + + + + + + + + {% for c in club_list.order_by('id') %} + {% set members = c.members.all() %} + {% if request.GET['branch'] %} + {% set members = members.filter(user__department=request.GET['branch']) %} + {% endif %} + + + + + + {% endfor %} + +
ClubMember numberOld member number
{{ c.get_display_name() }}{{ members.filter(end_date=None, role__gt=settings.SITH_MAXIMUM_FREE_ROLE).count() }}{{ members.exclude(end_date=None, role__gt=settings.SITH_MAXIMUM_FREE_ROLE).count() }}
+ {% else %} + {% trans %}There is no club in this website.{% endtrans %} + {% endif %} +{% endblock %} + + + diff --git a/club/urls.py b/club/urls.py index 7884df0b..bc0ccc3d 100644 --- a/club/urls.py +++ b/club/urls.py @@ -5,6 +5,7 @@ from club.views import * urlpatterns = [ url(r'^$', ClubListView.as_view(), name='club_list'), url(r'^new$', ClubCreateView.as_view(), name='club_new'), + url(r'^stats$', ClubStatView.as_view(), name='club_stats'), url(r'^(?P[0-9]+)/$', ClubView.as_view(), name='club_view'), url(r'^(?P[0-9]+)/edit$', ClubEditView.as_view(), name='club_edit'), url(r'^(?P[0-9]+)/members$', ClubMembersView.as_view(), name='club_members'), diff --git a/club/views.py b/club/views.py index 547f8103..9e217fa0 100644 --- a/club/views.py +++ b/club/views.py @@ -1,6 +1,6 @@ from django import forms from django.shortcuts import render -from django.views.generic import ListView, DetailView +from django.views.generic import ListView, DetailView, TemplateView from django.views.generic.edit import UpdateView, CreateView from django.forms import CheckboxSelectMultiple from django.core.exceptions import ValidationError @@ -17,6 +17,7 @@ from datetime import timedelta from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin from core.views.forms import SelectDate, SelectSingle, SelectDateTime from club.models import Club, Membership +from core.models import User from sith.settings import SITH_MAXIMUM_FREE_ROLE, SITH_MAIN_BOARD_GROUP from counter.models import Product, Selling, Counter @@ -283,3 +284,10 @@ class MembershipSetOldView(CanEditMixin, DetailView): self.object = self.get_object() return HttpResponseRedirect(reverse('club:club_members', args=self.args, kwargs={'club_id': self.object.club.id})) +class ClubStatView(TemplateView): + template_name="club/stats.jinja" + + def get_context_data(self, **kwargs): + kwargs = super(ClubStatView, self).get_context_data(**kwargs) + kwargs['club_list'] = Club.objects.all() + return kwargs diff --git a/core/models.py b/core/models.py index 5df983d2..1ddf9cd9 100644 --- a/core/models.py +++ b/core/models.py @@ -143,21 +143,8 @@ class User(AbstractBaseUser): ("FORMER STUDENT", _("Former student")), ("SERVICE", _("Service")), ], blank=True, default="") - department = models.CharField(_("department"), max_length=15, choices=[ - ("TC", _("TC")), - ("IMSI", _("IMSI")), - ("IMAP", _("IMAP")), - ("INFO", _("INFO")), - ("GI", _("GI")), - ("E", _("E")), - ("EE", _("EE")), - ("GESC", _("GESC")), - ("GMC", _("GMC")), - ("MC", _("MC")), - ("EDIM", _("EDIM")), - ("HUMA", _("Humanities")), - ("NA", _("N/A")), - ], default="NA", blank=True) + department = models.CharField(_("department"), max_length=15, choices=settings.SITH_PROFILE_DEPARTMENTS, + default="NA", blank=True) dpt_option = models.CharField(_("dpt option"), max_length=32, blank=True, default="") semester = models.CharField(_("semester"), max_length=5, blank=True, default="") quote = models.CharField(_("quote"), max_length=256, blank=True, default="") diff --git a/sith/settings.py b/sith/settings.py index c1680fbd..c88b1f24 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -282,6 +282,22 @@ SITH_MEMBER_SUFFIX="-membres" SITH_MAIN_BOARD_GROUP=SITH_MAIN_CLUB['unix_name']+SITH_BOARD_SUFFIX SITH_MAIN_MEMBERS_GROUP=SITH_MAIN_CLUB['unix_name']+SITH_MEMBER_SUFFIX +SITH_PROFILE_DEPARTMENTS = [ + ("TC", _("TC")), + ("IMSI", _("IMSI")), + ("IMAP", _("IMAP")), + ("INFO", _("INFO")), + ("GI", _("GI")), + ("E", _("E")), + ("EE", _("EE")), + ("GESC", _("GESC")), + ("GMC", _("GMC")), + ("MC", _("MC")), + ("EDIM", _("EDIM")), + ("HUMA", _("Humanities")), + ("NA", _("N/A")), + ] + SITH_ACCOUNTING_PAYMENT_METHOD = [ ('CHECK', _('Check')), ('CASH', _('Cash')),