Replaced own country selection with django-countries package.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django_countries import Countries
|
||||||
|
|
||||||
|
|
||||||
class ChoiceSet(object):
|
class ChoiceSet(object):
|
||||||
@@ -32,6 +33,12 @@ class ChoiceSet(object):
|
|||||||
return self._labels[code]
|
return self._labels[code]
|
||||||
|
|
||||||
|
|
||||||
|
class CountryChoiceSet(Countries):
|
||||||
|
first = ['DE', 'AU', 'CH', 'FR', 'IT']
|
||||||
|
first_repeat = True
|
||||||
|
first_break = '--'
|
||||||
|
|
||||||
|
|
||||||
ACCOMMODATION_CHOICES = ChoiceSet([
|
ACCOMMODATION_CHOICES = ChoiceSet([
|
||||||
('NONE', _(u'Keine (tägliche Anreise)')),
|
('NONE', _(u'Keine (tägliche Anreise)')),
|
||||||
('biwi', _(u'Biwak')),
|
('biwi', _(u'Biwak')),
|
||||||
@@ -41,13 +48,7 @@ ACCOMMODATION_CHOICES = ChoiceSet([
|
|||||||
('OTHER', _(u'Andere Unterkunft (zusätzliches Feld)')),
|
('OTHER', _(u'Andere Unterkunft (zusätzliches Feld)')),
|
||||||
])
|
])
|
||||||
|
|
||||||
COUNTRY_CHOICES = ChoiceSet([
|
COUNTRY_CHOICES = CountryChoiceSet()
|
||||||
('DE', _(u'Deutschland')),
|
|
||||||
('AU', _(u'Österreich')),
|
|
||||||
('CH', _(u'Schweiz')),
|
|
||||||
('FR', _(u'Frankreich')),
|
|
||||||
('IT', _(u'Italien')),
|
|
||||||
])
|
|
||||||
|
|
||||||
DEADLINE_CHOICES = ChoiceSet([
|
DEADLINE_CHOICES = ChoiceSet([
|
||||||
('month', _(u'Einen Monat vorher')),
|
('month', _(u'Einen Monat vorher')),
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ BASE_SHARE_DIR = os.path.join(BASE_DIR, 'common')
|
|||||||
INSTALLED_APPS += [
|
INSTALLED_APPS += [
|
||||||
'bootstrap3',
|
'bootstrap3',
|
||||||
'datetimewidget',
|
'datetimewidget',
|
||||||
|
'django_countries',
|
||||||
'django_extensions',
|
'django_extensions',
|
||||||
# Our main app
|
# Our main app
|
||||||
'dav_events',
|
'dav_events',
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import calendar
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from babel.dates import format_date
|
from babel.dates import format_date
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth import forms as auth_forms, password_validation
|
from django.contrib.auth import forms as auth_forms, password_validation
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils.translation import get_language, ugettext, ugettext_lazy as _
|
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 datetimewidget.widgets import DateWidget, TimeWidget, DateTimeWidget
|
||||||
|
|
||||||
from . import choices
|
from . import choices
|
||||||
@@ -318,10 +318,9 @@ class LocationForm(EventCreateForm):
|
|||||||
_form_title = _(u'Ort')
|
_form_title = _(u'Ort')
|
||||||
_next_form_name = 'ApproachForm'
|
_next_form_name = 'ApproachForm'
|
||||||
|
|
||||||
country = forms.ChoiceField(choices=choices.COUNTRY_CHOICES,
|
country = LazyTypedChoiceField(choices=choices.COUNTRY_CHOICES,
|
||||||
initial='DE',
|
initial='DE',
|
||||||
label=_(u'Land'),
|
label=_(u'Land'))
|
||||||
)
|
|
||||||
|
|
||||||
terrain = forms.ChoiceField(choices=choices.TERRAIN_CHOICES,
|
terrain = forms.ChoiceField(choices=choices.TERRAIN_CHOICES,
|
||||||
initial='submountains',
|
initial='submountains',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from django.db import models
|
|||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import get_language, ugettext_lazy as _
|
from django.utils.translation import get_language, ugettext_lazy as _
|
||||||
|
from django_countries.fields import CountryField
|
||||||
|
|
||||||
from . import choices
|
from . import choices
|
||||||
from . import config
|
from . import config
|
||||||
@@ -59,8 +60,7 @@ class Event(models.Model):
|
|||||||
course_goal_6 = models.TextField(blank=True)
|
course_goal_6 = models.TextField(blank=True)
|
||||||
|
|
||||||
# LocationForm
|
# LocationForm
|
||||||
country = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
country = CountryField()
|
||||||
choices=choices.COUNTRY_CHOICES)
|
|
||||||
terrain = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
terrain = models.CharField(max_length=CHOICE_FIELD_MAX_LENGTH,
|
||||||
choices=choices.TERRAIN_CHOICES)
|
choices=choices.TERRAIN_CHOICES)
|
||||||
location = models.CharField(max_length=config.LOCATION_MAX_LENGTH)
|
location = models.CharField(max_length=config.LOCATION_MAX_LENGTH)
|
||||||
|
|||||||
Reference in New Issue
Block a user