881 lines
47 KiB
Python
881 lines
47 KiB
Python
# -*- coding: utf-8 -*-
|
|
import calendar
|
|
import datetime
|
|
import logging
|
|
from babel.dates import format_date
|
|
from django import forms
|
|
from django.apps import apps
|
|
from django.utils.translation import get_language, ugettext, ugettext_lazy as _
|
|
from django_countries.fields import LazyTypedChoiceField
|
|
from datetimewidget.widgets import DateWidget, TimeWidget, DateTimeWidget
|
|
|
|
from .. import choices
|
|
from .. import config
|
|
from .. import models
|
|
from .generic import ChainedForm, ModelMixin
|
|
|
|
app_config = apps.get_containing_app_config(__package__)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class EventListExportForm(forms.Form):
|
|
sport = forms.ChoiceField(choices=choices.SPORT_CHOICES,
|
|
required=False,
|
|
label=_(u'Spielart'),
|
|
)
|
|
begin = forms.DateField(required=False,
|
|
label=_(u'Zeitraum - Start'),
|
|
help_text=u'%s - %s' % (
|
|
_(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',
|
|
'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)
|
|
sport_choices = self.fields['sport'].widget.choices
|
|
sport_choices.append((None, u'Alle'))
|
|
sport_choices.sort()
|
|
self.fields['sport'].widget.choices = sport_choices
|
|
|
|
|
|
class EventUpdateForm(forms.ModelForm):
|
|
class Meta:
|
|
model = models.Event
|
|
fields = '__all__'
|
|
exclude = ('accepted', 'accepted_at', 'accepted_by',
|
|
'published', 'published_at', 'published_by',)
|
|
|
|
|
|
class EventCreateForm(ModelMixin, ChainedForm):
|
|
_model = models.Event
|
|
_initial_form_name = 'ModeForm'
|
|
|
|
def _get_instance_kwargs(self):
|
|
kwargs = self._session_data.copy()
|
|
if 'deadline' in kwargs:
|
|
buf = kwargs['deadline']
|
|
if isinstance(buf, basestring):
|
|
deadline_choice = buf.lower()
|
|
deadline_field = 'deadline_{}'.format(deadline_choice)
|
|
if deadline_field in kwargs:
|
|
kwargs['deadline'] = kwargs[deadline_field]
|
|
return kwargs
|
|
|
|
def _get_matrix_config(self, session_data):
|
|
mode = session_data.get('mode', None)
|
|
sport = session_data.get('sport', None)
|
|
ski_lift = session_data.get('ski_lift', False)
|
|
terrain = session_data.get('terrain', None)
|
|
country = session_data.get('country', None)
|
|
overnight = bool(session_data.get('last_day', None))
|
|
|
|
if sport == 'S' and ski_lift:
|
|
matrix_key = 'K'
|
|
elif sport == 'W' and not overnight:
|
|
matrix_key = '0'
|
|
elif sport == 'W' and terrain != 'alpine':
|
|
matrix_key = 'A'
|
|
elif sport == 'W':
|
|
matrix_key = 'B'
|
|
elif terrain != 'alpine' and not overnight:
|
|
matrix_key = 'C'
|
|
elif terrain != 'alpine':
|
|
matrix_key = 'D'
|
|
elif mode == 'training' and country in ('DE', 'AT'):
|
|
matrix_key = 'G'
|
|
elif mode == 'training':
|
|
matrix_key = 'H'
|
|
elif sport == 'K' and country in ('DE', 'AT'):
|
|
matrix_key = 'E'
|
|
elif sport == 'K':
|
|
matrix_key = 'F'
|
|
elif country in ('DE', 'AT'):
|
|
matrix_key = 'I'
|
|
else:
|
|
matrix_key = 'J'
|
|
|
|
return matrix_key, app_config.settings.matrix_config[matrix_key]
|
|
|
|
|
|
class ModeForm(EventCreateForm):
|
|
_form_title = _(u'Veranstaltungsmodus')
|
|
_next_form_name = 'LocationForm'
|
|
|
|
mode = forms.ChoiceField(choices=choices.MODE_CHOICES,
|
|
label=_(u'Veranstaltungsart'),
|
|
widget=forms.RadioSelect())
|
|
|
|
sport = forms.ChoiceField(choices=choices.SPORT_CHOICES,
|
|
label=_(u'Spielart'),
|
|
widget=forms.RadioSelect())
|
|
|
|
ski_lift = forms.BooleanField(required=False,
|
|
label=_(u'Skiliftbenutzung'),
|
|
help_text=u'%s %s' % (
|
|
_(u'Relevant für die Kostenberechnung bei Skitouren/-kursen.'),
|
|
_(u'Wird nicht veröffentlicht.'),
|
|
),
|
|
)
|
|
|
|
level = forms.ChoiceField(choices=choices.LEVEL_CHOICES,
|
|
label=_(u'Schwierigkeitsnivau'),
|
|
widget=forms.RadioSelect())
|
|
|
|
first_day = forms.DateField(required=True,
|
|
label=_(u'Erster Tag'),
|
|
help_text=_(u'Format: tt.mm.jjjj'),
|
|
widget=DateWidget(attrs={'id': 'id_first_day_widget'},
|
|
usel10n=True,
|
|
options={
|
|
# 'format': 'dd.mm.yyyy',
|
|
# 'weekStart': 1,
|
|
'clearBtn': False,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
last_day = forms.DateField(required=False,
|
|
label=_(u'Letzter Tag'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: tt.mm.jjjj'),
|
|
_(u'Bei Tagestouren frei lassen'),
|
|
),
|
|
widget=DateWidget(attrs={'id': 'id_last_day_widget',
|
|
'placeholder': _(u'Bei Tagestouren freilassen'),
|
|
},
|
|
usel10n=True,
|
|
options={
|
|
# 'format': 'dd.mm.yyyy',
|
|
# 'weekStart': 1,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
alt_first_day = forms.DateField(required=False,
|
|
label=u'%s - %s' % (_(u'Ersatztermin'), _(u'Erster Tag')),
|
|
help_text=u'%s - %s - %s' % (
|
|
_(u'Ausweichtermin bei unpassenden Bedingungen'),
|
|
_(u'Format: tt.mm.jjjj'),
|
|
_(u'Kann frei gelassen werden'),
|
|
),
|
|
widget=DateWidget(attrs={'id': 'id_alt_first_day_widget',
|
|
'placeholder': _(u'Kann frei gelassen werden'),
|
|
},
|
|
usel10n=True,
|
|
options={
|
|
# 'format': 'dd.mm.yyyy',
|
|
# 'weekStart': 1,
|
|
'clearBtn': False,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
alt_last_day = forms.DateField(required=False,
|
|
label=u'%s - %s' % (_(u'Ersatztermin'), _(u'Letzter Tag')),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: tt.mm.jjjj'),
|
|
_(u'Bei Tagestouren frei lassen'),
|
|
),
|
|
widget=DateWidget(attrs={'id': 'id_alt_last_day_widget',
|
|
'placeholder': _(u'Bei Tagestouren freilassen'),
|
|
},
|
|
usel10n=True,
|
|
options={
|
|
# 'format': 'dd.mm.yyyy',
|
|
# 'weekStart': 1,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
@property
|
|
def next_form_name(self):
|
|
if self.cleaned_data.get('mode') == 'training':
|
|
return 'TrainingForm'
|
|
return super(ModeForm, self).next_form_name
|
|
|
|
def clean(self):
|
|
cleaned_data = super(ModeForm, self).clean()
|
|
last_day = cleaned_data.get('last_day', None)
|
|
if last_day and last_day == cleaned_data.get('first_day', None):
|
|
cleaned_data['last_day'] = ''
|
|
alt_last_day = cleaned_data.get('alt_last_day', None)
|
|
if alt_last_day and alt_last_day == cleaned_data.get('alt_first_day', None):
|
|
cleaned_data['alt_last_day'] = ''
|
|
return cleaned_data
|
|
|
|
|
|
class TrainingForm(EventCreateForm):
|
|
_form_title = _(u'Kursinhalte / Kursziele')
|
|
_next_form_name = 'LocationForm'
|
|
|
|
course_topic_1 = forms.CharField(required=True,
|
|
label=u'%s - %s 1' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.Textarea(attrs={'rows': 2}))
|
|
course_topic_2 = forms.CharField(required=False,
|
|
label=u'%s - %s 2' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_topic_3 = forms.CharField(required=False,
|
|
label=u'%s - %s 3' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_topic_4 = forms.CharField(required=False,
|
|
label=u'%s - %s 4' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_topic_5 = forms.CharField(required=False,
|
|
label=u'%s - %s 5' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_topic_6 = forms.CharField(required=False,
|
|
label=u'%s - %s 6' % (_(u'Kursinhalt'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
|
|
course_goal_1 = forms.CharField(required=True,
|
|
label=u'%s - %s 1' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.Textarea(attrs={'rows': 2}))
|
|
course_goal_2 = forms.CharField(required=False,
|
|
label=u'%s - %s 2' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_goal_3 = forms.CharField(required=False,
|
|
label=u'%s - %s 3' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_goal_4 = forms.CharField(required=False,
|
|
label=u'%s - %s 4' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_goal_5 = forms.CharField(required=False,
|
|
label=u'%s - %s 5' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
course_goal_6 = forms.CharField(required=False,
|
|
label=u'%s - %s 6' % (_(u'Kursziel'), _(u'Absatz')),
|
|
widget=forms.TextInput(attrs={'placeholder': _(u'Kann frei gelassen werden')}))
|
|
|
|
|
|
class LocationForm(EventCreateForm):
|
|
_form_title = _(u'Ort')
|
|
_next_form_name = 'ApproachForm'
|
|
|
|
country = LazyTypedChoiceField(choices=choices.COUNTRY_CHOICES,
|
|
label=_(u'Land'))
|
|
|
|
terrain = forms.ChoiceField(choices=choices.TERRAIN_CHOICES,
|
|
label=_(u'Gelände'),
|
|
help_text=u'%s %s' % (
|
|
_(u'Relevant für die Vorauswahl weiterer Felder.'),
|
|
_(u'Wird nicht veröffentlicht.'),
|
|
),
|
|
)
|
|
|
|
location = forms.CharField(required=False,
|
|
max_length=config.LOCATION_MAX_LENGTH,
|
|
label=_(u'Ort oder Gebiet'),
|
|
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['location'].widget.attrs['placeholder'] = u'z.B. Chamonix, Mont-Blanc-Gruppe'
|
|
elif sport == 'K':
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Battert, Baden-Baden'
|
|
elif sport == 'M':
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Pfälzerwald'
|
|
elif sport == 'S' and last_day:
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Obergurgl, Ötztaler Alpen'
|
|
elif sport == 'S':
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Todtnau, Schwarzwald'
|
|
elif sport == 'W' and last_day:
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Ötztaler Alpen'
|
|
elif sport == 'W':
|
|
self.fields['location'].widget.attrs['placeholder'] = u'z.B. Maikammer, Pfalz'
|
|
|
|
|
|
class ApproachForm(EventCreateForm):
|
|
_form_title = _(u'An- und Abreise / Unterkunft')
|
|
_next_form_name = 'RequirementsForm'
|
|
|
|
transport = forms.ChoiceField(choices=choices.TRANSPORT_CHOICES,
|
|
label=_(u'Verkehrsmittel'),
|
|
)
|
|
transport_other = forms.CharField(required=False,
|
|
max_length=config.TRANSPORT_OTHER_MAX_LENGTH,
|
|
label=_(u'Anderes Verkehrsmittel'),
|
|
)
|
|
|
|
meeting_point = forms.ChoiceField(choices=choices.MEETING_POINT_CHOICES,
|
|
label=_(u'Treffpunkt'),
|
|
)
|
|
meeting_point_other = forms.CharField(required=False,
|
|
max_length=config.MEETING_POINT_OTHER_MAX_LENGTH,
|
|
label=_(u'Anderer Treffpunkt'),
|
|
)
|
|
|
|
meeting_time = forms.TimeField(required=False,
|
|
label=_(u'Uhrzeit am Treffpunkt'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: hh:mm'),
|
|
_(u'Kann freigelassen werden'),
|
|
),
|
|
widget=TimeWidget(attrs={'id': 'id_meeting_time_widget',
|
|
'placeholder': _(u'Kann freigelassen werden'),
|
|
},
|
|
# usel10n=True,
|
|
options={
|
|
'format': 'hh:ii',
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
arrival_previous_day = forms.BooleanField(required=False,
|
|
label=_(u'Anreise des Kurs-/Tourenleiters am Vortag'),
|
|
help_text=u'%s %s' % (
|
|
_(u'Relevant für die Kostenberechnung.'),
|
|
_(u'Wird nicht veröffentlicht.'),
|
|
),
|
|
)
|
|
|
|
return_time = forms.TimeField(required=False,
|
|
label=_(u'Uhrzeit Rückkunft'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: hh:mm'),
|
|
_(u'Kann freigelassen werden'),
|
|
),
|
|
widget=TimeWidget(attrs={'id': 'id_back_time_widget',
|
|
'placeholder': _(u'Kann freigelassen werden'),
|
|
},
|
|
# usel10n=True,
|
|
options={
|
|
'format': 'hh:ii',
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
basecamp = forms.CharField(required=False,
|
|
max_length=config.BASECAMP_MAX_LENGTH,
|
|
label=_(u'Stützpunkt'),
|
|
help_text=_(u'z.B. Name der AV-Hütte oder des Campingplatzes'),
|
|
)
|
|
|
|
accommodation = forms.ChoiceField(choices=choices.ACCOMMODATION_CHOICES,
|
|
label=_(u'Unterkunft'),
|
|
)
|
|
accommodation_other = forms.CharField(required=False,
|
|
max_length=config.ACCOMMODATION_OTHER_MAX_LENGTH,
|
|
label=_(u'Andere Unterkunft'),
|
|
)
|
|
|
|
meals = forms.ChoiceField(choices=choices.MEALS_CHOICES,
|
|
label=_(u'Verpflegung'),
|
|
)
|
|
meals_other = forms.CharField(required=False,
|
|
max_length=config.MEALS_OTHER_MAX_LENGTH,
|
|
label=_(u'Andere Verpflegung'),
|
|
)
|
|
|
|
def _proceed_session_data(self, session_data):
|
|
super(ApproachForm, self)._proceed_session_data(session_data)
|
|
|
|
first_day = session_data.get('first_day', None)
|
|
last_day = session_data.get('last_day', None)
|
|
|
|
self.fields['transport_other'].widget.attrs['placeholder'] = _(u'Nebenstehendes Feld beachten')
|
|
self.fields['meeting_point_other'].widget.attrs['placeholder'] = _(u'Nebenstehendes Feld beachten')
|
|
self.fields['basecamp'].widget.attrs['placeholder'] = _(u'Kann freigelassen werden')
|
|
self.fields['accommodation_other'].widget.attrs['placeholder'] = _(u'Nebenstehendes Feld beachten')
|
|
self.fields['meals_other'].widget.attrs['placeholder'] = _(u'Nebenstehendes Feld beachten')
|
|
|
|
self.fields['meeting_time'].widget.options['startDate'] = first_day.strftime('%Y-%m-%d 00:00:00')
|
|
self.fields['meeting_time'].widget.options['endDate'] = first_day.strftime('%Y-%m-%d 23:59:59')
|
|
|
|
return_day = last_day or first_day
|
|
self.fields['return_time'].widget.options['startDate'] = return_day.strftime('%Y-%m-%d 00:00:00')
|
|
self.fields['return_time'].widget.options['endDate'] = return_day.strftime('%Y-%m-%d 23:59:59')
|
|
|
|
if not last_day:
|
|
self.fields['basecamp'].widget = forms.HiddenInput()
|
|
self.fields['accommodation'].widget = forms.HiddenInput()
|
|
self.fields['accommodation'].initial = 'NONE'
|
|
self.fields['accommodation_other'].widget = forms.HiddenInput()
|
|
|
|
|
|
class RequirementsForm(EventCreateForm):
|
|
_form_title = _(u'Voraussetzungen / Vorbedingungen')
|
|
_next_form_name = 'DescriptionForm'
|
|
|
|
requirements = forms.CharField(required=False,
|
|
label=_(u'Anforderungen / Voraussetzungen'),
|
|
help_text=u'%s %s' % (
|
|
_(u'Was müssen Teilnehmer bereits können.'),
|
|
_(u'Schwierigkeitsgrade in arabischen Ziffern.'
|
|
u' Einheiten: Km, Hm, Stunden.'),
|
|
),
|
|
widget=forms.Textarea(attrs={'rows': 2,
|
|
'placeholder': _(u'Kann frei gelassen werden')}))
|
|
|
|
equipment = forms.CharField(required=False,
|
|
label=_(u'Ausrüstung'),
|
|
help_text=u'%s %s' % (
|
|
_(u'Was müssen Teilnehmer mitbringen.'),
|
|
_(u'Diese Liste muss nicht vollständig sein,'
|
|
u' der potenzielle Teilnehmer soll aber ein Vorstellung davon bekommen,'
|
|
u' was er sich gegebenenfalls noch leihen/beschaffen muss.'),
|
|
),
|
|
widget=forms.Textarea(attrs={'rows': 2,
|
|
'placeholder': _(u'Kann frei gelassen werden')}))
|
|
|
|
pre_meeting_1 = forms.DateTimeField(required=False,
|
|
label=u'1. %s' % _(u'Vortreffen'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: tt.mm.jjjj hh:mm'),
|
|
_(u'Kann frei gelassen werden'),
|
|
),
|
|
widget=DateTimeWidget(attrs={'id': 'id_pre_meeting_1_widget',
|
|
'placeholder': _(u'Kann frei gelassen werden')},
|
|
# usel10n=True,
|
|
options={
|
|
'format': 'dd.mm.yyyy hh:ii',
|
|
'weekStart': 1,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
pre_meeting_2 = forms.DateTimeField(required=False,
|
|
label=u'2. %s' % _(u'Vortreffen'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: tt.mm.jjjj hh:mm'),
|
|
_(u'Kann frei gelassen werden'),
|
|
),
|
|
widget=DateTimeWidget(attrs={'id': 'id_pre_meeting_2_widget',
|
|
'placeholder': _(u'Kann frei gelassen werden')},
|
|
# usel10n=True,
|
|
options={
|
|
'format': 'dd.mm.yyyy hh:ii',
|
|
'weekStart': 1,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
|
|
class DescriptionForm(EventCreateForm):
|
|
_form_title = _(u'Titel / Beschreibung')
|
|
_next_form_name = 'TrainerForm'
|
|
|
|
title = forms.CharField(max_length=config.TITLE_MAX_LENGTH,
|
|
label=_(u'Name bzw. Titel der Veranstaltung'),
|
|
)
|
|
description = forms.CharField(label=_(u'Beschreibung'),
|
|
widget=forms.Textarea(attrs={'rows': 5}))
|
|
|
|
def get_initial_for_field(self, field, field_name):
|
|
value = super(DescriptionForm, self).get_initial_for_field(field, field_name)
|
|
if field_name == 'title' and value is None:
|
|
mode = self._session_data.get('mode', None)
|
|
sport = self._session_data.get('sport', None)
|
|
level = self._session_data.get('level', None)
|
|
terrain = self._session_data.get('terrain', None)
|
|
last_day = self._session_data.get('last_day', None)
|
|
|
|
value = u''
|
|
if mode == 'training':
|
|
if level == 'beginner':
|
|
value += u'%s ' % ugettext(u'Grundkurs')
|
|
else:
|
|
value += u'%s ' % ugettext(u'Aufbaukurs')
|
|
|
|
if sport == 'B':
|
|
value += u'%s' % ugettext(u'Alpin')
|
|
elif sport == 'K':
|
|
if terrain == 'gym':
|
|
value += ugettext(u'Indoorklettern')
|
|
elif terrain == 'crag':
|
|
value += ugettext(u'Fels')
|
|
elif terrain == 'alpine':
|
|
value += ugettext(u'Alpinklettern')
|
|
|
|
value += u': ...'
|
|
elif sport == 'W' and not last_day:
|
|
value += u'%s ...' % ugettext(u'Tageswanderung')
|
|
|
|
if app_config.settings.forms_development_init:
|
|
if not value:
|
|
value = u'%s' % choices.SPORT_CHOICES.get_label(sport)
|
|
|
|
return value
|
|
|
|
|
|
class TrainerForm(EventCreateForm):
|
|
_form_title = _(u'Tourenleitung')
|
|
_next_form_name = 'RegistrationForm'
|
|
|
|
trainer_firstname = forms.CharField(label=_(u'Vorname'),
|
|
max_length=config.TRAINER_NAME_MAX_LENGTH)
|
|
trainer_familyname = forms.CharField(label=_(u'Familienname'),
|
|
max_length=config.TRAINER_NAME_MAX_LENGTH)
|
|
trainer_email = forms.EmailField(label=_(u'E-Mail-Adresse'))
|
|
trainer_phone = forms.CharField(required=False,
|
|
max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
|
label=_(u'Telefonnummer'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
|
|
trainer_2_fullname = forms.CharField(required=False,
|
|
max_length=config.TRAINER_NAME_MAX_LENGTH,
|
|
label=_(u'Name'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
trainer_2_email = forms.EmailField(required=False,
|
|
label=_(u'E-Mail-Adresse'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
trainer_2_phone = forms.CharField(required=False,
|
|
max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
|
label=_(u'Telefonnummer'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
|
|
trainer_3_fullname = forms.CharField(required=False,
|
|
max_length=config.TRAINER_NAME_MAX_LENGTH,
|
|
label=_(u'Name'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
trainer_3_email = forms.EmailField(required=False,
|
|
label=_(u'E-Mail-Adresse'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
trainer_3_phone = forms.CharField(required=False,
|
|
max_length=config.PHONE_NUMBER_MAX_LENGTH,
|
|
label=_(u'Telefonnummer'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
|
|
def _proceed_session_data(self, session_data):
|
|
super(TrainerForm, self)._proceed_session_data(session_data)
|
|
|
|
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'--'
|
|
self.fields['trainer_3_fullname'].widget.attrs['placeholder'] = _(u'Kann freigelassen werden')
|
|
self.fields['trainer_3_email'].widget.attrs['placeholder'] = u'--'
|
|
self.fields['trainer_3_phone'].widget.attrs['placeholder'] = u'--'
|
|
|
|
if hasattr(self._request, 'user') and self._request.user.is_authenticated:
|
|
self.fields['trainer_firstname'].initial = self._request.user.first_name
|
|
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 = _(u'Jens')
|
|
self.fields['trainer_familyname'].initial = _(u'Kleineheismann')
|
|
self.fields['trainer_email'].initial = _(u'heinzel@alpenverein-karlsruhe.de')
|
|
|
|
|
|
class RegistrationForm(EventCreateForm):
|
|
_form_title = _(u'Teilnehmer / Anmeldung')
|
|
_next_form_name = 'ChargesForm'
|
|
|
|
min_participants = forms.IntegerField(initial=0,
|
|
min_value=0,
|
|
label=_(u'Min. Teilnehmer'))
|
|
max_participants = forms.IntegerField(initial=0,
|
|
min_value=0,
|
|
label=_(u'Max. Teilnehmer'))
|
|
|
|
deadline = forms.ChoiceField(choices=choices.DEADLINE_CHOICES,
|
|
label=_(u'Anmeldeschluss'),
|
|
widget=forms.RadioSelect())
|
|
|
|
deadline_month = forms.DateField(widget=forms.HiddenInput())
|
|
deadline_quarter = forms.DateField(widget=forms.HiddenInput())
|
|
|
|
deadline_other = forms.DateField(required=False,
|
|
label=_(u'Anderer Anmeldeschluss'),
|
|
help_text=u'%s - %s' % (
|
|
_(u'Format: tt.mm.jjjj'),
|
|
_(u'Kann freigelassen werden'),
|
|
),
|
|
widget=DateWidget(attrs={'id': 'id_deadline_other_widget',
|
|
'placeholder': _(u'Kann freigelassen werden'),
|
|
},
|
|
usel10n=True,
|
|
options={
|
|
# 'format': 'dd.mm.yyyy',
|
|
# 'weekStart': 1,
|
|
'pickerPosition': 'bottom-left',
|
|
},
|
|
bootstrap_version=3))
|
|
|
|
registration_howto = forms.CharField(disabled=True,
|
|
required=False,
|
|
label=_(u'Anmeldungshinweis'),
|
|
help_text=_(u'Dieser Text kann absichtlich nicht geändert werden.'),
|
|
widget=forms.Textarea(attrs={'rows': 2}),
|
|
)
|
|
|
|
def _proceed_session_data(self, session_data):
|
|
super(RegistrationForm, self)._proceed_session_data(session_data)
|
|
|
|
first_day = session_data.get('first_day', None)
|
|
trainer_fullname = u'%s %s' % (session_data.get('trainer_firstname'), session_data.get('trainer_familyname'))
|
|
trainer_email = session_data.get('trainer_email')
|
|
trainer_2_fullname = session_data.get('trainer_2_fullname', None)
|
|
trainer_3_fullname = session_data.get('trainer_3_fullname', None)
|
|
|
|
matrix_key, matrix_config = self._get_matrix_config(session_data)
|
|
|
|
n_trainer = 1
|
|
if trainer_2_fullname:
|
|
n_trainer += 1
|
|
if trainer_3_fullname:
|
|
n_trainer += 1
|
|
|
|
self.fields['min_participants'].initial = matrix_config['min_participants'] * n_trainer
|
|
self.fields['max_participants'].initial = matrix_config['max_participants'] * n_trainer
|
|
|
|
if first_day:
|
|
new_choices = []
|
|
for key, desc in self.fields['deadline'].choices:
|
|
if key == 'month':
|
|
m = first_day.month - 1 - 1
|
|
y = first_day.year + m / 12
|
|
m = m % 12 + 1
|
|
d = min(first_day.day, calendar.monthrange(y, m)[1])
|
|
date = datetime.date(y, m, d)
|
|
desc += u' ({})'.format(format_date(date, 'EEEE, d. MMMM yyyy', locale=get_language()[0:2]))
|
|
self.fields['deadline_month'].initial = date.isoformat()
|
|
elif key == 'quarter':
|
|
m = first_day.month - 1 - 3
|
|
y = first_day.year + m / 12
|
|
m = m % 12 + 1
|
|
d = min(first_day.day, calendar.monthrange(y, m)[1])
|
|
date = datetime.date(y, m, d)
|
|
desc += u' ({})'.format(format_date(date, 'EEEE, d. MMMM yyyy', locale=get_language()[0:2]))
|
|
self.fields['deadline_quarter'].initial = date.isoformat()
|
|
new_choices.append((key, desc))
|
|
self.fields['deadline'].choices = new_choices
|
|
|
|
if self.fields['registration_howto'].initial:
|
|
initial = self.fields['registration_howto'].initial % {'name': trainer_fullname,
|
|
'emailaddr': trainer_email}
|
|
self.fields['registration_howto'].initial = initial
|
|
else:
|
|
self.fields['registration_howto'].widget = forms.HiddenInput()
|
|
|
|
|
|
class ChargesForm(EventCreateForm):
|
|
_form_title = _(u'Kosten')
|
|
_next_form_name = 'SummaryForm'
|
|
|
|
charge_key = forms.CharField(disabled=True,
|
|
label=_(u'Kostenschlüssel'),
|
|
)
|
|
trainer_fee = forms.FloatField(disabled=True,
|
|
label=_(u'Pauschale Trainer*in'),
|
|
)
|
|
pre_meeting_fee = forms.FloatField(disabled=True,
|
|
label=_(u'Pauschale Vortreffen'),
|
|
)
|
|
trainer_day_fee = forms.FloatField(disabled=True,
|
|
label=_(u'Tagespauschale Trainer*in'),
|
|
)
|
|
participant_fee = forms.FloatField(disabled=True,
|
|
label=_(u'Pauschale Teilnehmer*in'),
|
|
)
|
|
participant_day_fee = forms.FloatField(disabled=True,
|
|
label=_(u'Tagepauschale Teilnehmer*in'),
|
|
)
|
|
|
|
trainer_reward = forms.FloatField(disabled=True,
|
|
label=_(u'Aufwandsentschädigung Trainer*in'),
|
|
)
|
|
|
|
charge = forms.FloatField(min_value=0,
|
|
label=_(u'Teilnahmegebühr in Euro'))
|
|
|
|
additional_costs = forms.CharField(required=False,
|
|
max_length=config.ADDITIONAL_COSTS_MAX_LENGTH,
|
|
label=_(u'Zusätzliche Kosten (Text)'),
|
|
help_text=_(u'Kann freigelassen werden'),
|
|
)
|
|
|
|
def _proceed_session_data(self, session_data):
|
|
super(ChargesForm, self)._proceed_session_data(session_data)
|
|
|
|
first_day = session_data.get('first_day', None)
|
|
arrival_previous_day = session_data.get('arrival_previous_day', False)
|
|
last_day = session_data.get('last_day', None)
|
|
transport = session_data.get('transport', None)
|
|
accommodation = session_data.get('accommodation', None)
|
|
pre_meeting_1 = session_data.get('pre_meeting_1', None)
|
|
pre_meeting_2 = session_data.get('pre_meeting_2', None)
|
|
|
|
matrix_key, matrix_config = self._get_matrix_config(session_data)
|
|
|
|
additional_costs_text = u''
|
|
if transport != 'coach':
|
|
additional_costs_text += ugettext(u'Fahrtkosten')
|
|
|
|
if last_day:
|
|
timedelta = last_day - first_day
|
|
ndays = timedelta.days + 1
|
|
if accommodation != 'NONE':
|
|
if additional_costs_text:
|
|
additional_costs_text += u', '
|
|
additional_costs_text += ugettext(u'Unterkunft und Verpflegung')
|
|
else:
|
|
ndays = 1
|
|
|
|
if pre_meeting_2:
|
|
n_pre_meetings = 2
|
|
elif pre_meeting_1:
|
|
n_pre_meetings = 1
|
|
else:
|
|
n_pre_meetings = 0
|
|
|
|
trainer_reward = (
|
|
matrix_config['trainer_fee']
|
|
+ ndays * matrix_config['trainer_day_fee']
|
|
+ n_pre_meetings * matrix_config['pre_meeting_fee']
|
|
)
|
|
charge = (
|
|
matrix_config['participant_fee']
|
|
+ ndays * matrix_config['participant_day_fee']
|
|
)
|
|
if arrival_previous_day:
|
|
trainer_reward += matrix_config['trainer_day_fee'] / 2.0
|
|
charge += matrix_config['participant_day_fee'] / 2.0
|
|
|
|
self.fields['charge_key'].initial = matrix_config['description'] or matrix_key
|
|
self.fields['trainer_fee'].initial = matrix_config['trainer_fee']
|
|
self.fields['pre_meeting_fee'].initial = matrix_config['pre_meeting_fee']
|
|
self.fields['trainer_day_fee'].initial = matrix_config['trainer_day_fee']
|
|
self.fields['participant_fee'].initial = matrix_config['participant_day_fee']
|
|
self.fields['participant_day_fee'].initial = matrix_config['participant_day_fee']
|
|
self.fields['trainer_reward'].initial = trainer_reward
|
|
self.fields['trainer_reward'].widget.attrs['title'] = (u'%d € Pauschale \n'
|
|
u'+ %d Tage * %d € Tagespauschale \n'
|
|
u'+ %d halben Anreisetag * %d € Tagespauschale / 2 \n'
|
|
u'+ %d Vortreffen * %d € Vortreffenpauschale'
|
|
% (
|
|
matrix_config['trainer_fee'],
|
|
ndays, matrix_config['trainer_day_fee'],
|
|
int(arrival_previous_day), matrix_config['trainer_day_fee'],
|
|
n_pre_meetings, matrix_config['pre_meeting_fee']
|
|
)
|
|
)
|
|
|
|
self.fields['charge'].initial = charge
|
|
self.fields['charge'].widget.attrs['title'] = (u'%d € Pauschale \n'
|
|
u'+ %d Tage * %d € Tagespauschale \n'
|
|
u'+ %d halben Anreisetag * %d € Tagespauschale / 2'
|
|
% (
|
|
matrix_config['participant_fee'],
|
|
ndays, matrix_config['participant_day_fee'],
|
|
int(arrival_previous_day), matrix_config['participant_day_fee'],
|
|
)
|
|
)
|
|
|
|
self.fields['additional_costs'].widget.attrs['placeholder'] = ugettext(u'Kann freigelassen werden')
|
|
self.fields['additional_costs'].initial = additional_costs_text
|
|
|
|
|
|
class SummaryForm(EventCreateForm):
|
|
_form_title = _(u'Zusammenfassung')
|
|
|
|
publish_date = forms.CharField(disabled=True,
|
|
initial=_(u'Unverzüglich'),
|
|
label=_(u'Voraussichtliche Veröffentlichung'),
|
|
)
|
|
|
|
def get_initial_for_field(self, field, field_name):
|
|
value = super(SummaryForm, self).get_initial_for_field(field, field_name)
|
|
if field_name == 'publish_date':
|
|
max_participants = self._session_data.get('max_participants', 0)
|
|
if max_participants:
|
|
deadline = self._session_data.get('deadline', None)
|
|
if deadline == 'OTHER':
|
|
deadline = self._session_data.get('deadline_other', None)
|
|
else:
|
|
deadline_field_name = 'deadline_%s' % deadline
|
|
if deadline_field_name in self._session_data:
|
|
deadline = self._session_data.get(deadline_field_name)
|
|
else:
|
|
raise Exception(deadline)
|
|
|
|
if deadline:
|
|
publish_deadline = deadline - datetime.timedelta(app_config.settings.publish_before_deadline_days)
|
|
else:
|
|
first_day = self._session_data.get('first_day')
|
|
publish_deadline = first_day - datetime.timedelta(app_config.settings.publish_before_begin_days)
|
|
|
|
today = datetime.date.today()
|
|
|
|
break_outer_loop = False
|
|
for year in (today.year, today.year + 1):
|
|
for issue in app_config.settings.publish_issues:
|
|
if not ('issue' in issue and 'release' in issue and 'deadline' in issue):
|
|
continue
|
|
issue_name = issue['issue']
|
|
issue_release_day = issue['release'][0]
|
|
issue_release_month = issue['release'][1]
|
|
issue_deadline_day = issue['deadline'][0]
|
|
issue_deadline_month = issue['deadline'][1]
|
|
|
|
issue_release_date = datetime.date(year, issue_release_month, issue_release_day)
|
|
if issue_release_date < today:
|
|
continue
|
|
|
|
issue_deadline_date = datetime.date(year, issue_deadline_month, issue_deadline_day)
|
|
if issue_deadline_date > issue_release_date:
|
|
issue_deadline_date = datetime.date(year - 1, issue_deadline_month, issue_deadline_day)
|
|
|
|
if publish_deadline > issue_release_date and today < issue_deadline_date:
|
|
value = u'{issue} / {year} - {date}'.format(issue=issue_name,
|
|
year=year,
|
|
date=format_date(issue_release_date,
|
|
'EEEE, d. MMMM yyyy',
|
|
locale=get_language()[0:2]))
|
|
break_outer_loop = True
|
|
break
|
|
|
|
if break_outer_loop:
|
|
break
|
|
|
|
return value
|