From 6e77c0b11bc1598d5ab0761e04974332471393a7 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Wed, 7 Feb 2018 12:54:16 +0100 Subject: [PATCH] 1. Made location optional, 2. Added multicountry select option, 3. Improved form labels, help texts and templates. --- dav_events/choices.py | 5 +- dav_events/forms/events.py | 92 +++++++++++-------- .../migrations/0009_auto_20180207_1118.py | 20 ++++ .../migrations/0010_auto_20180207_1138.py | 22 +++++ dav_events/models.py | 12 ++- .../dav_events/emails/event_to_publish.txt | 2 +- dav_events/templates/dav_events/event.html | 3 +- dav_events/templates/dav_events/event.txt | 2 +- 8 files changed, 111 insertions(+), 47 deletions(-) create mode 100644 dav_events/migrations/0009_auto_20180207_1118.py create mode 100644 dav_events/migrations/0010_auto_20180207_1138.py diff --git a/dav_events/choices.py b/dav_events/choices.py index 86c74ea..8451418 100644 --- a/dav_events/choices.py +++ b/dav_events/choices.py @@ -39,7 +39,10 @@ class ChoiceSet(object): class CountryChoiceSet(Countries): - first = ['DE', 'AT', 'CH', 'FR', 'IT'] + override = { + 'XX': _(u'Länderübergreifend'), + } + first = ['DE', 'AT', 'CH', 'FR', 'IT', 'XX'] first_repeat = True first_break = '--' diff --git a/dav_events/forms/events.py b/dav_events/forms/events.py index 8276d74..2a56dc7 100644 --- a/dav_events/forms/events.py +++ b/dav_events/forms/events.py @@ -29,24 +29,7 @@ class EventListExportForm(forms.Form): _(u'Format: tt.mm.jjjj'), _(u'Kann frei gelassen werden') ), - widget = DateWidget(attrs={'id': 'id_begin_widget', - 'placeholder': _(u'Kann freigelassen werden')}, - usel10n=True, - options={ - # 'format': 'dd.mm.yyyy', - # 'weekStart': 1, - 'startView': 3, - 'clearBtn': True, - 'pickerPosition': 'bottom-left', - }, - bootstrap_version=3)) - end = forms.DateField(required=False, - label=_(u'Zeitraum - Ende'), - help_text=u'%s - %s' % ( - _(u'Format: tt.mm.jjjj'), - _(u'Kann frei gelassen werden') - ), - widget = DateWidget(attrs={'id': 'id_end_widget', + widget=DateWidget(attrs={'id': 'id_begin_widget', 'placeholder': _(u'Kann freigelassen werden')}, usel10n=True, options={ @@ -57,6 +40,23 @@ class EventListExportForm(forms.Form): 'pickerPosition': 'bottom-left', }, bootstrap_version=3)) + end = forms.DateField(required=False, + label=_(u'Zeitraum - Ende'), + help_text=u'%s - %s' % ( + _(u'Format: tt.mm.jjjj'), + _(u'Kann frei gelassen werden') + ), + widget=DateWidget(attrs={'id': 'id_end_widget', + 'placeholder': _(u'Kann freigelassen werden')}, + usel10n=True, + options={ + # 'format': 'dd.mm.yyyy', + # 'weekStart': 1, + 'startView': 3, + 'clearBtn': True, + 'pickerPosition': 'bottom-left', + }, + bootstrap_version=3)) def __init__(self, *args, **kwargs): super(EventListExportForm, self).__init__(*args, **kwargs) @@ -232,32 +232,48 @@ class LocationForm(EventCreateForm): help_text=_(u'Relevant für die Vorauswahl weiterer Felder.'), ) - location = forms.CharField(max_length=config.LOCATION_MAX_LENGTH, + location = forms.CharField(required=False, + max_length=config.LOCATION_MAX_LENGTH, label=_(u'Ort'), - help_text=_(u'z.B. Orts- und Fels- bzw. Bergname, evtl. auch Region,' - u' so dass man mindestens eine grobe Vorstellung bekommt,' - u' wo das ganze stattfindet.'), - widget=forms.TextInput(attrs={'placeholder': u'Karlsruhe'})) + help_text=u'%s - %s' % ( + _(u'Orts- und Fels- bzw. Bergname, evtl. auch Gebirgsgruppe bzw. Region,' + u' so dass man mindestens eine grobe Vorstellung bekommt,' + u' wo das ganze stattfindet.'), + _(u'Kann in Ausnahmefällen (z.B. Streckenwanderung) freigelassen werden') + ), + widget=forms.TextInput( + attrs={'placeholder': _(u'Kann in Ausnahmefällen frei gelassen werden')} + )) def _proceed_session_data(self, session_data): super(LocationForm, self)._proceed_session_data(session_data) sport = session_data.get('sport', None) + last_day = session_data.get('last_day', None) if sport == 'B': self.fields['terrain'].initial = 'alpine' - self.fields['location'].widget.attrs['placeholder'] = u'Ramsau, Berchtesgadener Alpen' + self.fields['country'].initial = 'FR' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Chamonix, Mont-Blanc-Gruppe' elif sport == 'K': self.fields['terrain'].initial = 'crag' - self.fields['location'].widget.attrs['placeholder'] = u'Battert, Baden-Baden' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Battert, Baden-Baden' elif sport == 'M': - self.fields['location'].widget.attrs['placeholder'] = u'Pfälzerwald' + self.fields['terrain'].initial = 'submountains' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Pfälzerwald' + elif sport == 'S' and last_day: + self.fields['terrain'].initial = 'alpine' + self.fields['country'].initial = 'AT' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Obergurgl, Ötztaler Alpen' elif sport == 'S': - self.fields['location'].widget.attrs['placeholder'] = u'Todtnau, Schwarzwald' + self.fields['terrain'].initial = 'submountains' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Todtnau, Schwarzwald' + elif sport == 'W' and last_day: + self.fields['terrain'].initial = 'alpine' + self.fields['country'].initial = 'AT' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Ötztaler Alpen' elif sport == 'W': - self.fields['location'].widget.attrs['placeholder'] = u'Maikammer, Pfalz' - - if app_config.settings.forms_development_init: - self.fields['location'].initial = self.fields['location'].widget.attrs['placeholder'] + self.fields['terrain'].initial = 'submountains' + self.fields['location'].widget.attrs['placeholder'] = u'z.B. Maikammer, Pfalz' class ApproachForm(EventCreateForm): @@ -643,10 +659,10 @@ class TrainerForm(EventCreateForm): def _proceed_session_data(self, session_data): super(TrainerForm, self)._proceed_session_data(session_data) - self.fields['trainer_firstname'].widget.attrs['placeholder'] = _(u'Jens') - self.fields['trainer_familyname'].widget.attrs['placeholder'] = _(u'Kleineheismann') - self.fields['trainer_email'].widget.attrs['placeholder'] = _(u'heinzel@alpenverein-karlsruhe.de') - self.fields['trainer_phone'].widget.attrs['placeholder'] = _(u'0150 150 15 01') + self.fields['trainer_firstname'].widget.attrs['placeholder'] = _(u'Vorname') + self.fields['trainer_familyname'].widget.attrs['placeholder'] = _(u'Nachname') + self.fields['trainer_email'].widget.attrs['placeholder'] = _(u'E-Mail-Adresse') + self.fields['trainer_phone'].widget.attrs['placeholder'] = _(u'z.B. 0150 150 15 01') self.fields['trainer_2_fullname'].widget.attrs['placeholder'] = _(u'Kann freigelassen werden') self.fields['trainer_2_email'].widget.attrs['placeholder'] = u'--' self.fields['trainer_2_phone'].widget.attrs['placeholder'] = u'--' @@ -659,9 +675,9 @@ class TrainerForm(EventCreateForm): self.fields['trainer_familyname'].initial = self._request.user.last_name self.fields['trainer_email'].initial = self._request.user.email elif app_config.settings.forms_development_init: - self.fields['trainer_firstname'].initial = self.fields['trainer_firstname'].widget.attrs['placeholder'] - self.fields['trainer_familyname'].initial = self.fields['trainer_familyname'].widget.attrs['placeholder'] - self.fields['trainer_email'].initial = self.fields['trainer_email'].widget.attrs['placeholder'] + self.fields['trainer_firstname'].initial = _(u'Jens') + self.fields['trainer_familyname'].initial = _(u'Kleineheismann') + self.fields['trainer_email'].initial = _(u'heinzel@alpenverein-karlsruhe.de') class ChargesForm(EventCreateForm): diff --git a/dav_events/migrations/0009_auto_20180207_1118.py b/dav_events/migrations/0009_auto_20180207_1118.py new file mode 100644 index 0000000..f67ea6f --- /dev/null +++ b/dav_events/migrations/0009_auto_20180207_1118.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.9 on 2018-02-07 11:18 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dav_events', '0008_auto_20180129_1355'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='location', + field=models.CharField(blank=True, max_length=250), + ), + ] diff --git a/dav_events/migrations/0010_auto_20180207_1138.py b/dav_events/migrations/0010_auto_20180207_1138.py new file mode 100644 index 0000000..173f32d --- /dev/null +++ b/dav_events/migrations/0010_auto_20180207_1138.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.9 on 2018-02-07 11:38 +from __future__ import unicode_literals + +import dav_events.choices +from django.db import migrations +import django_countries.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('dav_events', '0009_auto_20180207_1118'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='country', + field=django_countries.fields.CountryField(countries=dav_events.choices.CountryChoiceSet, max_length=2), + ), + ] diff --git a/dav_events/models.py b/dav_events/models.py index 98f660e..c542d8d 100644 --- a/dav_events/models.py +++ b/dav_events/models.py @@ -82,10 +82,11 @@ class Event(models.Model): course_goal_6 = models.TextField(blank=True) # LocationForm - country = CountryField() + country = CountryField(countries=choices.CountryChoiceSet) terrain = models.CharField(max_length=choices.CHOICE_FIELD_MAX_LENGTH, choices=choices.TERRAIN_CHOICES) - location = models.CharField(max_length=config.LOCATION_MAX_LENGTH) + location = models.CharField(max_length=config.LOCATION_MAX_LENGTH, + blank=True) # ApproachForm transport = models.CharField(max_length=choices.CHOICE_FIELD_MAX_LENGTH, @@ -308,8 +309,7 @@ class Event(models.Model): 'course_goal_4': self.course_goal_4, 'course_goal_5': self.course_goal_5, 'course_goal_6': self.course_goal_6, - 'requirements': self.requirements, - 'equipment': self.equipment, + 'country': self.country, 'location': self.location, 'basecamp': self.basecamp, 'accommodation': self.accommodation, @@ -321,13 +321,15 @@ class Event(models.Model): 'meeting_time': self.meeting_time, 'meeting_point': self.meeting_point, 'meeting_point_other': self.meeting_point_other, + 'requirements': self.requirements, + 'equipment': self.equipment, 'pre_meeting_1': self.pre_meeting_1, 'pre_meeting_2': self.pre_meeting_2, + 'deadline': self.deadline, 'min_participants': self.min_participants, 'max_participants': self.max_participants, 'charge': self.charge, 'additional_costs': self.additional_costs, - 'deadline': self.deadline, 'trainer_firstname': self.trainer_firstname, 'trainer_familyname': self.trainer_familyname, 'trainer_email': self.trainer_email, diff --git a/dav_events/templates/dav_events/emails/event_to_publish.txt b/dav_events/templates/dav_events/emails/event_to_publish.txt index 6ccca6b..04ca001 100644 --- a/dav_events/templates/dav_events/emails/event_to_publish.txt +++ b/dav_events/templates/dav_events/emails/event_to_publish.txt @@ -36,7 +36,7 @@ Die Veranstaltung wurde zur Veröffentlichung frei gegeben. {% if requirements %}{% trans 'Anforderungen' %}: {{ requirements }}
{% endif %}{% if equipment %}{% trans 'Ausrüstung' %}: {{ equipment }}
-{% endif %}{% if location %}{% trans 'Ort' %}: {{ location }}
+{% endif %}{% if location %}{% trans 'Ort' %}: {{ location }} {% if country and country != 'DE' and country != 'XX' %}({{ country }}){% endif %}
{% endif %}{% if basecamp %}{% trans 'Stützpunkt' %}: {{ basecamp }}
{% endif %}{% if accommodation and accommodation != 'NONE' %}{% trans 'Unterkunft' %}: {% if accommodation == 'OTHER' %}{{ accommodation_other }}{% else %}{{ event.get_accommodation_display }}{% endif %}
{% endif %}{% if meals and meals != 'NONE' %}{% trans 'Verpflegung' %}: {% if meals == 'OTHER' %}{{ meals_other }}{% else %}{{ event.get_meals_display }}{% endif %}
diff --git a/dav_events/templates/dav_events/event.html b/dav_events/templates/dav_events/event.html index d5575a7..a22a1be 100644 --- a/dav_events/templates/dav_events/event.html +++ b/dav_events/templates/dav_events/event.html @@ -70,7 +70,8 @@
{% if requirements %}{% trans 'Anforderungen' %}: {{ requirements }}
{% endif %} {% if equipment %}{% trans 'Ausrüstung' %}: {{ equipment }}
{% endif %} - {% if location %}{% trans 'Ort' %}: {{ location }}
{% endif %} + {% if location %}{% trans 'Ort' %}: {{ location }} + {% if country and country != 'DE' and country != 'XX' %}({{ country }}){% endif %}
{% endif %} {% if basecamp %}{% trans 'Stützpunkt' %}: {{ basecamp }}
{% endif %} {% if accommodation and accommodation != 'NONE' %} {% trans 'Unterkunft' %}: diff --git a/dav_events/templates/dav_events/event.txt b/dav_events/templates/dav_events/event.txt index 90874a2..be05760 100644 --- a/dav_events/templates/dav_events/event.txt +++ b/dav_events/templates/dav_events/event.txt @@ -30,7 +30,7 @@ {% endif %} {% if requirements %}{% trans 'Anforderungen' %}: {{ requirements }} {% endif %}{% if equipment %}{% trans 'Ausrüstung' %}: {{ equipment }} -{% endif %}{% if location %}{% trans 'Ort' %}: {{ location }} +{% endif %}{% if location %}{% trans 'Ort' %}: {{ location }} {% if country and country != 'DE' and country != 'XX' %}({{ country }}){% endif %} {% endif %}{% if basecamp %}{% trans 'Stützpunkt' %}: {{ basecamp }} {% endif %}{% if accommodation and accommodation != 'NONE' %}{% trans 'Unterkunft' %}: {% if accommodation == 'OTHER' %}{{ accommodation_other }}{% else %}{{ event.get_accommodation_display }}{% endif %} {% endif %}{% if meals and meals != 'NONE' %}{% trans 'Verpflegung' %}: {% if meals == 'OTHER' %}{{ meals_other }}{% else %}{{ event.get_meals_display }}{% endif %}