From cb441872ecfe16fdeed869a70e786e494807b289 Mon Sep 17 00:00:00 2001 From: Jarmil Date: Thu, 12 Dec 2019 10:19:30 +0100 Subject: [PATCH] NEW: Telefon do CSV exportu lidi, FIX: KEyError pri neexistujicim kraji tamtez --- nalodeni/models.py | 13 +++++++++++-- nalodeni/people.py | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/nalodeni/models.py b/nalodeni/models.py index f1bf47f..6227131 100644 --- a/nalodeni/models.py +++ b/nalodeni/models.py @@ -249,10 +249,19 @@ class AppUser(AbstractUser, DataAudited): @consent_terms.setter def consent_terms(self, value): writeUserSetting(self, 'consent_terms', value, datetime.date) - + + # properties mimo model + + def get_district_name(self): + """ Vrat nazev kraje - textova reprezentace, muze se menit, nepouzivat jako klic """ + try: + ret = self.DISTRICT_CHOICES_STR[self.district] + except KeyError: + ret = "- Nezadán -" + return ret # Meta - + def __str__(self): return self.username diff --git a/nalodeni/people.py b/nalodeni/people.py index a782876..03348ef 100644 --- a/nalodeni/people.py +++ b/nalodeni/people.py @@ -122,7 +122,7 @@ def eu2019(request, dist=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[3] = obj.get_district_name() row[4] = obj.postcode row[5] = 1 if obj.want_info else 0 row[6] = 1 if obj.want_campaign else 0 @@ -172,6 +172,7 @@ def confirmed(request, newOnly=False, dist=None): "Příjmení", "E-mail registrační", "E-mail kontaktní", + "Telefon", "Kraj", "PSČ", "Město", @@ -202,14 +203,15 @@ def confirmed(request, newOnly=False, dist=None): 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 + row[5] = obj.phone + row[6] = obj.get_district_name() + row[7] = obj.postcode + row[8] = obj.city + row[9] = obj.KIND_CHOICES_STR[obj.kind] + row[10] = obj.interestedIn + row[11] = obj.STATUS_CHOICES_STR[obj.status] + row[12] = obj.dc_stamp + row[13] = obj.userform.skills_note if obj.userform else None if obj.userform: for abbr, mdl in [