CSV export kontaktu
This commit is contained in:
parent
5d8f40390c
commit
e1165f31cf
|
@ -77,6 +77,22 @@ class AppUser(AbstractUser, DataAudited):
|
|||
(DISTRICT_ULK, 'Ústecký kraj'),
|
||||
(DISTRICT_ZLK, 'Zlínský kraj'),
|
||||
)
|
||||
DISTRICT_CHOICES_STR = {
|
||||
DISTRICT_PHA: 'Hlavní město Praha',
|
||||
DISTRICT_JHC: 'Jihočeský kraj',
|
||||
DISTRICT_JHM: 'Jihomoravský kraj',
|
||||
DISTRICT_KVK: 'Karlovarský kraj',
|
||||
DISTRICT_VYS: 'Kraj Vysočina',
|
||||
DISTRICT_KHK: 'Královéhradecký kraj',
|
||||
DISTRICT_LBK: 'Liberecký kraj',
|
||||
DISTRICT_MSK: 'Moravskoslezský kraj',
|
||||
DISTRICT_OLK: 'Olomoucký kraj',
|
||||
DISTRICT_PAK: 'Pardubický kraj',
|
||||
DISTRICT_PLK: 'Plzeňský kraj',
|
||||
DISTRICT_STC: 'Středočeský kraj',
|
||||
DISTRICT_ULK: 'Ústecký kraj',
|
||||
DISTRICT_ZLK: 'Zlínský kraj',
|
||||
}
|
||||
DISTRICT_ROLES = {
|
||||
'sso_kraj_pha' : DISTRICT_PHA,
|
||||
'sso_kraj_jhc' : DISTRICT_JHC,
|
||||
|
@ -100,6 +116,10 @@ class AppUser(AbstractUser, DataAudited):
|
|||
(STATUS_NEW, 'nový'),
|
||||
(STATUS_REG, 'registrovaný'),
|
||||
)
|
||||
STATUS_CHOICES_STR = {
|
||||
STATUS_NEW: 'nový',
|
||||
STATUS_REG: 'registrovaný',
|
||||
}
|
||||
|
||||
KIND_NEWSLETTER = 0
|
||||
KIND_WANT_SUPPORTER = 1
|
||||
|
@ -117,6 +137,15 @@ class AppUser(AbstractUser, DataAudited):
|
|||
(KIND_ALREADY_MEMBER, _('již jsem člen')),
|
||||
(KIND_ALREADY_OTHER, _('již pirátím jinak')),
|
||||
)
|
||||
KIND_CHOICES_STR = {
|
||||
KIND_NEWSLETTER: _('dostávat novinky'),
|
||||
KIND_HELP_VOLUNTEER: _('pomáhat jako dobrovolník'),
|
||||
KIND_HELP_EXPERT: _('pomáhat jako expert'),
|
||||
KIND_WANT_SUPPORTER: _('se stát příznivcem'),
|
||||
KIND_WANT_MEMBER: _('se stát členem'),
|
||||
KIND_ALREADY_MEMBER: _('již jsem člen'),
|
||||
KIND_ALREADY_OTHER: _('již pirátím jinak'),
|
||||
}
|
||||
|
||||
##
|
||||
# User self-editable fields
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from datetime import date, datetime, timedelta # timeSlices
|
||||
from collections import OrderedDict
|
||||
import csv
|
||||
|
||||
import django
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
@ -81,6 +82,7 @@ def get_AppUser_districts(request):
|
|||
def confirmed(request, newOnly=False, dist=None):
|
||||
if dist is None:
|
||||
dist = int(request.POST.get('dist', -1))
|
||||
doCsvExport = None != request.POST.get('doCsvExport', None)
|
||||
|
||||
objs = get_AppUser_objects(request).order_by('last_name', 'first_name' ,'email')
|
||||
|
||||
|
@ -97,6 +99,67 @@ def confirmed(request, newOnly=False, dist=None):
|
|||
else:
|
||||
selDist = -1
|
||||
|
||||
if doCsvExport:
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="nalodeni-kraj-%s-%s.csv"' % (selDist, date.today())
|
||||
|
||||
row_headers = [
|
||||
"ID",
|
||||
"Jméno",
|
||||
"Příjmení",
|
||||
"E-mail registrační",
|
||||
"E-mail kontaktní",
|
||||
"Kraj",
|
||||
"PSČ",
|
||||
"Město",
|
||||
"Druh",
|
||||
"Poznámka",
|
||||
"Stav",
|
||||
"Datum souhlasu o.ú.",
|
||||
"Poznámka dovednosti",
|
||||
]
|
||||
col_count = len(row_headers)
|
||||
row_nums = {}
|
||||
|
||||
for abbr, mdl in [
|
||||
('IR',models.InterestRegion ),
|
||||
('US',models.UserSkill ),
|
||||
('UT',models.UserTopic ), ]:
|
||||
for i in mdl.objects.all():
|
||||
row_nums[abbr+'_'+str(i.id)] = col_count
|
||||
row_headers.append(i.name)
|
||||
col_count += 1
|
||||
|
||||
writer = csv.writer(response)
|
||||
writer.writerow(row_headers)
|
||||
for obj in objs:
|
||||
row = len(row_headers) * [None]
|
||||
row[0] = obj.id
|
||||
row[1] = obj.first_name
|
||||
row[2] = obj.last_name
|
||||
row[3] = obj.email
|
||||
row[4] = obj.email_contact_active
|
||||
row[5] = obj.DISTRICT_CHOICES_STR[obj.district]
|
||||
row[6] = obj.postcode
|
||||
row[7] = obj.city
|
||||
row[8] = obj.KIND_CHOICES_STR[obj.kind]
|
||||
row[9] = obj.interestedIn
|
||||
row[10] = obj.STATUS_CHOICES_STR[obj.status]
|
||||
row[11] = obj.dc_stamp
|
||||
row[12] = obj.userform.skills_note if obj.userform else None
|
||||
|
||||
if obj.userform:
|
||||
for abbr, mdl in [
|
||||
('IR', obj.userform.regions ),
|
||||
('US', obj.userform.skills ),
|
||||
('UT', obj.userform.topics ), ]:
|
||||
for i in mdl.all():
|
||||
row[row_nums[abbr+"_"+str(i.id)]] = "x"
|
||||
|
||||
writer.writerow(row)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
template = 'people/list.html'
|
||||
context = {
|
||||
|
|
|
@ -26,11 +26,9 @@ $(document).ready(function(){
|
|||
<select name="dist" onChange="this.form.submit()">{% for d in distAvail%}<option value="{{d.0}}"{%if selDist == d.0%} selected="selected"{%endif%}>{{d.1}}</option>{%endfor%}</select>
|
||||
</div>
|
||||
<div class="medium-4 large-4 columns">
|
||||
<select name="kind"><option>Všichni</option></select>
|
||||
</div>
|
||||
<div class="medium-4 large-4 columns">
|
||||
<input type="text" name="search" placeholder="Hledat ..." style="width:70%; display: inline-block; vertical-align:middle"/>
|
||||
<input type="submit" name="doSearch" value="ok" class="button" style="border: 0px; float:right;"/>
|
||||
<input type="submit" name="doCsvExport" value="CSV export" class="button" style="border: 0px; float:right;"/>
|
||||
</div>
|
||||
</form>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in New Issue