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