Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import date
- from django.contrib.auth import get_user_model
- from django.contrib.auth.decorators import user_passes_test
- from django.db.models import Count
- from django.shortcuts import render
- from django.utils import timezone
- from organisations.models import Organisation
- User = get_user_model()
- @user_passes_test(lambda u: u.is_staff, login_url='/admin/')
- def dashboard(request, year=None, month=None):
- if not year or not month:
- now = timezone.now()
- year = now.year
- month = now.month
- report_period = date(year=int(year), month=int(month), day=1)
- organisations = Organisation.objects.filter(
- date_reached__year=report_period.year,
- date_reached__month=report_period.month,
- reviewed=True,
- ).order_by('name').distinct()
- countries = organisations.values('country').annotate(
- organisations=Count('country')
- ).order_by('-organisations')
- return render(request, 'analytics/dashboard.html', {
- 'organisations': organisations,
- 'countries': countries,
- 'num_organisations': organisations.count(),
- 'report_period': report_period,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement