Add new country field with passerelle autocomplete-widget

This commit is contained in:
Christophe Boulanger 2016-07-13 11:39:23 +02:00
parent be4e89c0be
commit bbdf08ba52
2 changed files with 26 additions and 0 deletions

View File

@ -64,4 +64,7 @@ class Plugin(object):
{'label': _('Phone number'),
'name': 'phone',
'field_class': fields.NumPhoneField, },
{'label': _('Country'),
'name': 'country',
'field_class': fields.CountryField, },
]

View File

@ -89,6 +89,29 @@ class StreetField(forms.CharField):
widget = StreetWidget
class CountryWidget(forms.TextInput):
class Media:
css = {'all': ('xstatic/themes/smoothness/jquery-ui.css',)}
js = ('xstatic/jquery-ui.js',
'authentic2_auth_fedict/js/support.js',)
def __init__(self, attrs=None):
if not attrs:
attrs = {}
attrs['class'] = 'country-widget'
if getattr(settings, 'IMIO_COUNTRY_URL', None):
country_url = settings.IMIO_COUNTRY_URL
else:
passerelle_url = settings.KNOWN_SERVICES['passerelle'].values()[0]['url']
country_url = '%s/csvdatasource/country/data' % passerelle_url
attrs['data-autocomplete-url'] = country_url
super(forms.TextInput, self).__init__(attrs=attrs)
class CountryField(forms.CharField):
widget = CountryWidget
class NumHouseField(forms.CharField):
def validate(self, value):
super(NumHouseField, self).validate(value)