From f47306581aaca6616d18a57b36eb44116176cc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org> Date: Wed, 18 Aug 2021 16:34:55 +0200 Subject: [PATCH] elections2021: Improve banner orders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix legalese - Add a note field - Use stable export ordering Signed-off-by: Jan Hamal Dvořák <mordae@anilinux.org> --- ...me_place_of_birth_bannerorder_residency.py | 8 ++-- elections2021/migrations/0041_token.py | 20 ++++++--- .../migrations/0042_bannerorder_note.py | 18 ++++++++ elections2021/models.py | 2 + .../elections2021/banner_order_form.html | 21 +++++++--- elections2021/views.py | 41 +++++++++++++++---- 6 files changed, 88 insertions(+), 22 deletions(-) create mode 100644 elections2021/migrations/0042_bannerorder_note.py diff --git a/elections2021/migrations/0040_rename_place_of_birth_bannerorder_residency.py b/elections2021/migrations/0040_rename_place_of_birth_bannerorder_residency.py index 53644f90..35b19212 100644 --- a/elections2021/migrations/0040_rename_place_of_birth_bannerorder_residency.py +++ b/elections2021/migrations/0040_rename_place_of_birth_bannerorder_residency.py @@ -6,13 +6,13 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('elections2021', '0039_elections2021mappage_subtitle'), + ("elections2021", "0039_elections2021mappage_subtitle"), ] operations = [ migrations.RenameField( - model_name='bannerorder', - old_name='place_of_birth', - new_name='residency', + model_name="bannerorder", + old_name="place_of_birth", + new_name="residency", ), ] diff --git a/elections2021/migrations/0041_token.py b/elections2021/migrations/0041_token.py index c0a22302..da84ae31 100644 --- a/elections2021/migrations/0041_token.py +++ b/elections2021/migrations/0041_token.py @@ -6,17 +6,25 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('elections2021', '0040_rename_place_of_birth_bannerorder_residency'), + ("elections2021", "0040_rename_place_of_birth_bannerorder_residency"), ] operations = [ migrations.CreateModel( - name='Token', + name="Token", fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('scope', models.CharField(max_length=127)), - ('bearer', models.CharField(max_length=40)), - ('comment', models.CharField(max_length=255)), + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("scope", models.CharField(max_length=127)), + ("bearer", models.CharField(max_length=40)), + ("comment", models.CharField(max_length=255)), ], ), ] diff --git a/elections2021/migrations/0042_bannerorder_note.py b/elections2021/migrations/0042_bannerorder_note.py new file mode 100644 index 00000000..abcf554d --- /dev/null +++ b/elections2021/migrations/0042_bannerorder_note.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2021-08-18 14:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections2021", "0041_token"), + ] + + operations = [ + migrations.AddField( + model_name="bannerorder", + name="note", + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/elections2021/models.py b/elections2021/models.py index 0a261c67..80c257f7 100644 --- a/elections2021/models.py +++ b/elections2021/models.py @@ -2477,6 +2477,7 @@ class BannerOrder(models.Model): date_of_birth = models.DateField() phone = models.CharField(max_length=20) email = models.EmailField(max_length=70) + note = models.CharField(max_length=255, blank=True) class BannerForm(forms.ModelForm): @@ -2490,6 +2491,7 @@ class BannerForm(forms.ModelForm): "date_of_birth", "phone", "email", + "note", ] diff --git a/elections2021/templates/elections2021/banner_order_form.html b/elections2021/templates/elections2021/banner_order_form.html index c9942e8d..675ad224 100644 --- a/elections2021/templates/elections2021/banner_order_form.html +++ b/elections2021/templates/elections2021/banner_order_form.html @@ -70,8 +70,9 @@ <p class="my-5"> Pokud nám pomĹŻĹľete v kampani vyvěšenĂm venkovnĂ reklamy, - musĂme o tomto Vašem nefinanÄŤnĂm daru informovat stát, - kterĂ˝ vaše Ăşdaje uveĹ™ejnĂ. + jedná se o nefinaÄŤnĂ dar. Výše uvedenĂ© informace o vás + uveĹ™ejnĂme, abychom splnili svou zákonnou povinnost. + Tato data budeme uchovávat 10 let od poskytnutĂ daru. </p> <h2 class="head-alt-sm my-5">KontaktnĂ Ăşdaje</h2> @@ -95,12 +96,22 @@ <div class="form-field__error">{{error}}</div> {% endfor %} </div> + <div class="form-field col-span-4 form-field-required {% if request.banner_form.errors.note %}form-field--error{% endif %}"> + <label class="form-field__label" for="note">Poznámka</label> + <div class="form-field__wrapper form-field__wrapper--shadowed"> + <input type="text" class="text-input form-field__control text-black" id="note" name="note" value="{{request.banner_form.note.value|default_if_none:""}}" placeholder="" /> + </div> + {% for error in request.banner_form.errors.note %} + <div class="form-field__error">{{error}}</div> + {% endfor %} + </div> </div> <p class="my-5"> - KontaktnĂ Ăşdaje vyuĹľijĂ naši koordinátoĹ™i k tomu, aby se s vámi - domluvili na podrobnostech pĹ™edánĂ. Po skonÄŤenĂ tĂ©to volebnĂ kampanÄ› - vaše kontaktnĂ Ăşdaje vymaĹľeme. + KontaktnĂ Ăşdaje vyuĹľijĂ našà koordinátoĹ™i k tomu, + aby se s Vámi domluvili na podrobnostech pĹ™edánĂ. + Po skonÄŤenĂ tĂ©to volebnĂ kampanÄ› Vaše kontaktnĂ Ăşdaje vymaĹľeme + a to nejpozdÄ›ji k 1. 1. 2022. </p> <div class="mt-5 text-center lg:text-right"> diff --git a/elections2021/views.py b/elections2021/views.py index 7ef2e82b..37251172 100644 --- a/elections2021/views.py +++ b/elections2021/views.py @@ -1,20 +1,47 @@ import csv -from .models import BannerOrder, Token + from django.http import HttpResponse, HttpResponseForbidden +from .models import BannerOrder, Token + def banner_orders_csv(request): - response = HttpResponse(content_type='text/csv;charset=utf-8') + response = HttpResponse(content_type="text/csv;charset=utf-8") - tokens = Token.objects.filter(bearer=request.GET.get('token'), scope="banner-orders") + tokens = Token.objects.filter( + bearer=request.GET.get("token"), scope="banner-orders" + ) if not tokens: return HttpResponseForbidden() w = csv.writer(response) - w.writerow(["ID", "Plachta", "JmĂ©no", "PĹ™ĂjmenĂ", "BydlištÄ›", "Narozen", "Telefon", "Mail"]) + w.writerow( + [ + "ID", + "Plachta", + "JmĂ©no", + "PĹ™ĂjmenĂ", + "BydlištÄ›", + "Narozen", + "Telefon", + "Mail", + "Poznámka", + ] + ) - for row in BannerOrder.objects.all(): - w.writerow([str(row.id), row.code, row.name, row.surname, row.residency, - str(row.date_of_birth), row.phone, row.email]) + for row in BannerOrder.objects.order_by("id").all(): + w.writerow( + [ + str(row.id), + row.code, + row.name, + row.surname, + row.residency, + str(row.date_of_birth), + row.phone, + row.email, + row.note, + ] + ) return response -- GitLab