diff --git a/src/nalodeni/people.py b/src/nalodeni/people.py index 85c2b9b..7e2b664 100644 --- a/src/nalodeni/people.py +++ b/src/nalodeni/people.py @@ -76,6 +76,72 @@ def get_AppUser_districts(request): return rslt +@ensure_csrf_cookie +@login_required(login_url="/prihlaseni") +@role_required(['sso_kodo']) +def eu2019(request, dist=None): + if dist is None: + dist = int(request.POST.get('dist', -1)) + doCsvExport = None != request.POST.get('doCsvExport', None) + + objs = models.Euro2019Interest.objects.all() + + districts = [(-1, ' -- vše dostupné -- ')] + get_AppUser_districts(request) + # filtrujeme jen povolene kraje, nebo vse pro adminy + if dist != -1 and (dist in request.session['spc']['dist'] or 'sso_admin' in request.session['site_perms']): + selDist = dist + objs = objs.filter(district=selDist) + else: + selDist = -1 + + if doCsvExport: + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename="eu2019-kraj-%s-%s.csv"' % (selDist, date.today()) + + row_headers = [ + "ID", + "Vytvořeno", + "E-mail", + "Kraj", + "PSČ", + "Chci info emailem", + "Chci rozdávat Listy", + "Chci se zapojit", + "Poznámka", + "Datum souhlasu o.ú.", + ] + col_count = len(row_headers) + row_nums = {} + + writer = csv.writer(response) + writer.writerow(row_headers) + for obj in objs: + row = len(row_headers) * [None] + row[0] = obj.id + row[1] = obj.createdStamp + row[2] = obj.email + row[3] = models.AppUser.DISTRICT_CHOICES_STR[obj.district] if obj.district else None + row[4] = obj.postcode + row[5] = 1 if obj.want_info else 0 + row[6] = 1 if obj.want_campaign else 0 + row[7] = 1 if obj.want_be_active else 0 + row[8] = obj.note + row[9] = obj.dc_stamp + + writer.writerow(row) + + return response + + + template = 'people/eu2019.html' + context = { + 'people' : objs, + 'distAvail' : districts, + 'selDist' : selDist, + } + + return render(request, template, context) + @ensure_csrf_cookie @login_required(login_url="/prihlaseni") @role_required(['sso_kodo']) diff --git a/src/nalodeni/templates/people/eu2019.html b/src/nalodeni/templates/people/eu2019.html new file mode 100644 index 0000000..489cff4 --- /dev/null +++ b/src/nalodeni/templates/people/eu2019.html @@ -0,0 +1,81 @@ +{% extends 'pirati_cz.html' %} + +{%block head%} + +{%endblock%} +{%block body%} +
Vytvořeno | +Kraj | +PSČ | +Chci info | +Chci rozdávat | +Chci se zapojit | +Poznámka | +|
---|---|---|---|---|---|---|---|
{{p.createdStamp}} | +{{p.email}} | +{{p.get_district_display}} | +{{p.postcode|default_if_none:'-'}} | +{%if p.want_info%}ano{%else%}ne{%endif%} | +{%if p.want_campaign%}ano{%else%}ne{%endif%} | +{%if p.want_be_active%}ano{%else%}ne{%endif%} | +{{p.note|default_if_none:'-'}} | +