Merge branch 'nilovna' into dev
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / rappels / views.py
CommitLineData
c4312cce
PP
1# -*- coding: utf-8 -*-
2
b756f9d2
PP
3import datetime
4
c4312cce
PP
5from django.shortcuts import render_to_response
6from django.template import RequestContext
7from django.db.models import Count
8from django.contrib.auth.decorators import permission_required
9from django.contrib.auth.models import User
10
b756f9d2
PP
11from chercheurs.models import Chercheur
12
c4312cce 13
e4aeae54 14@permission_required('rappels.rappels')
c4312cce
PP
15def admin_rappels(request):
16
b756f9d2
PP
17 chercheurs = User.objects.filter(is_active=True).exclude(chercheur__exact=None)
18 chercheurs_anneemois = chercheurs.extra(select={'year': "EXTRACT(year FROM last_login)", 'month': "EXTRACT(month FROM last_login)"}).values('year', 'month').annotate(total=Count('username')).order_by('year', 'month')
19
20 num_chercheurs = Chercheur.objects.all().count()
21
22 today = datetime.datetime.today()
23 last_year = today - datetime.timedelta(days=365)
24
25 num_chercheurs_lastlog_thisyear = chercheurs.filter(last_login__gte=last_year).count()
26 num_chercheurs_lastlog_beforethisyear = num_chercheurs - num_chercheurs_lastlog_thisyear
c4312cce
PP
27
28 return render_to_response('admin/rappels/rappels.html', {
b756f9d2
PP
29 'chercheurs_anneemois': chercheurs_anneemois,
30 'num_chercheurs': num_chercheurs,
31 'num_chercheurs_lastlog_thisyear': num_chercheurs_lastlog_thisyear,
32 'num_chercheurs_lastlog_beforethisyear': num_chercheurs_lastlog_beforethisyear,
c4312cce 33 }, context_instance=RequestContext(request))