diff --git a/dav_registration/forms.py b/dav_registration/forms.py index e80d9e3..da93756 100644 --- a/dav_registration/forms.py +++ b/dav_registration/forms.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import datetime import logging from django import forms from django.utils.translation import ugettext, ugettext_lazy as _ @@ -25,6 +26,28 @@ class RegistrationForm(forms.ModelForm): 'note': forms.Textarea(attrs={'rows': 5}), } + def clean_year_of_birth(self): + now = datetime.datetime.now() + year_now = now.year + max_age = 100 + val = self.cleaned_data.get('year_of_birth') + if val > year_now: + raise forms.ValidationError( + ugettext(u'Dein Geburtsjahr liegt in der Zukunft?' + u' Das finden wir gut,' + u' aber bitte melde dich besser mal per E-Mail bei uns.'), + code='to_young', + ) + elif val < (year_now - max_age): + raise forms.ValidationError( + ugettext(u'Du bist schon über %(max_age)d Jahre alt?' + u' Das finden wir gut,' + u' aber bitte melde dich besser mal per E-Mail bei uns.'), + params={'max_age': max_age}, + code='to_old', + ) + return val + def clean_experience(self): val = self.cleaned_data.get('experience') if val == '': diff --git a/dav_registration/migrations/0009_registration_year_of_birth.py b/dav_registration/migrations/0009_registration_year_of_birth.py new file mode 100644 index 0000000..455a614 --- /dev/null +++ b/dav_registration/migrations/0009_registration_year_of_birth.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-12-09 09:20 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dav_registration', '0008_auto_20201208_1906'), + ] + + operations = [ + migrations.AddField( + model_name='registration', + name='year_of_birth', + field=models.IntegerField(default=1870, help_text='Manchmal müssen wir wissen, wie alt unsere Teilnehmer sind. Darum brauchen wir die vierstellige Jahreszahl, des Jahres in dem du geboren bist (zb. 1991).', verbose_name='Geburtsjahr'), + preserve_default=False, + ), + ] diff --git a/dav_registration/models.py b/dav_registration/models.py index 62737ef..c864e6a 100644 --- a/dav_registration/models.py +++ b/dav_registration/models.py @@ -40,6 +40,12 @@ class Registration(models.Model): phone_number = models.CharField(max_length=254, verbose_name=_('Telefonnummer'), help_text=_('Idealerweise eine Mobilfunk-Nummer')) + + year_of_birth = models.IntegerField(verbose_name=_('Geburtsjahr'), + help_text=_('Manchmal müssen wir wissen, wie alt unsere Teilnehmer sind.' + ' Darum brauchen wir die vierstellige Jahreszahl,' + ' des Jahres in dem du geboren bist (zb. 1991).')) + dav_member = models.BooleanField(default=True, verbose_name=_('DAV Mitglied')) dav_number = models.CharField(max_length=62, @@ -74,6 +80,11 @@ class Registration(models.Model): answered_obsolete = models.BooleanField(default=False, verbose_name=_('Durch Tourleitung beantwortet')) + def approx_age(self): + now = datetime.datetime.now() + year_now = now.year + return year_now - self.year_of_birth + @staticmethod def pk2hexstr(pk): return hex(pk * 113)[2:] # 113 has no meaning, but it produce nice looking hex codes. @@ -113,6 +124,7 @@ class Registration(models.Model): {address}, {postal_code} {city} DAV Mitglied: {dav_info} +Jahrgang: {year_of_birth} (ungefähres Alter: {approx_age}) Erfahrung: {experience} @@ -131,6 +143,8 @@ Anmerkung: postal_code=self.postal_code, city=self.city, dav_info=dav_info, + year_of_birth=self.year_of_birth, + approx_age=self.approx_age(), experience=self.experience, note=self.note, ) diff --git a/dav_registration/templates/dav_registration/emails/inform_self.txt b/dav_registration/templates/dav_registration/emails/inform_self.txt index dfdbfeb..ca5925e 100644 --- a/dav_registration/templates/dav_registration/emails/inform_self.txt +++ b/dav_registration/templates/dav_registration/emails/inform_self.txt @@ -22,6 +22,7 @@ Personendaten {{ registration.postal_code }} {{ registration.city }} Telefon: {{ registration.phone_number }} E-Mail: {{ registration.email_address }} +Jahrgang: {{ registration.year_of_birth }} {% if registration.dav_member %}DAV Mitgliedsnummer: {{ registration.dav_number }}{% else %}DAV Mitglied: Nein{% endif %} Notfall-Kontakt diff --git a/dav_registration/templates/dav_registration/emails/inform_trainer.txt b/dav_registration/templates/dav_registration/emails/inform_trainer.txt index 5da7483..7edd9b3 100644 --- a/dav_registration/templates/dav_registration/emails/inform_trainer.txt +++ b/dav_registration/templates/dav_registration/emails/inform_trainer.txt @@ -19,6 +19,8 @@ Notfall-Kontakt: Erfahrung: {% if registration.experience %}{{ registration.experience }}{% else %}-{% endif %} +Jahrgang: {{ registration.year_of_birth }} (ungefähres Alter: {{ registration.approx_age }}) + Anmerkung: {% if registration.note %}{{ registration.note }}{% else %}-{% endif %} diff --git a/dav_registration/templates/dav_registration/registration_form.html b/dav_registration/templates/dav_registration/registration_form.html index 473e213..322efb6 100644 --- a/dav_registration/templates/dav_registration/registration_form.html +++ b/dav_registration/templates/dav_registration/registration_form.html @@ -90,12 +90,21 @@