Add new country field with passerelle autocomplete-widget
This commit is contained in:
parent
be4e89c0be
commit
bbdf08ba52
|
@ -64,4 +64,7 @@ class Plugin(object):
|
|||
{'label': _('Phone number'),
|
||||
'name': 'phone',
|
||||
'field_class': fields.NumPhoneField, },
|
||||
{'label': _('Country'),
|
||||
'name': 'country',
|
||||
'field_class': fields.CountryField, },
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue