├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.rst ├── clever_selects ├── __init__.py ├── admin.py ├── form_fields.py ├── forms.py ├── static │ └── js │ │ └── clever-selects.js ├── templates │ └── clever_selects │ │ └── widgets │ │ └── chained_select.html ├── templatetags │ ├── __init__.py │ └── clever_selects_extras.py ├── views.py └── widgets.py ├── example ├── clever_selects ├── example │ ├── __init__.py │ ├── admin.py │ ├── fixtures │ │ └── initial_data.json │ ├── forms.py │ ├── helpers.py │ ├── models.py │ ├── settings.py │ ├── static │ │ └── js │ │ │ └── jquery-1.10.2.min.js │ ├── templates │ │ ├── cars.html │ │ ├── form.html │ │ └── home.html │ ├── urls.py │ ├── views.py │ └── wsgi.py ├── manage.py └── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[co] 2 | .DS_Store 3 | .sass-cache 4 | 5 | # Packages 6 | *.egg 7 | *.egg-info 8 | dist 9 | build 10 | eggs 11 | parts 12 | bin 13 | var 14 | sdist 15 | develop-eggs 16 | .installed.cfg 17 | 18 | # Installer logs 19 | pip-log.txt 20 | 21 | # Unit test / coverage reports 22 | .coverage 23 | .tox 24 | 25 | #Translations 26 | *.mo 27 | 28 | #Mr Developer 29 | .mr.developer.cfg 30 | 31 | #IDE 32 | .idea 33 | 34 | #LiClips 35 | .project 36 | .pydevproject -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Pragmatic Mates s.r.o. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | recursive-include clever_selects/static * 3 | recursive-include clever_selects/templates * -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | django-clever-selects 2 | ===================== 3 | 4 | This library is inspired by **django-chained-selectbox** from *s-block* 5 | (https://github.com/s-block/django-chained-selectbox). 6 | 7 | It serves chained select box widget for Django framework using AJAX requests for chaining select boxes together. 8 | The values change depending on the parent value. 9 | 10 | Previous mentioned library was intended for use in Django admin only. The new library has frontend functionality, 11 | improved existing instance data initialization and new ``ChainedModelChoiceField``. It also uses custom TestClient which 12 | is able pass ``request.user`` variable into AJAX view if user is logged in. It is very useful if you need to filter result queryset by 13 | user permissions for example. 14 | 15 | Tested on Django 1.4.5. 16 | 17 | 18 | Requirements 19 | ------------ 20 | - Django 21 | 22 | - jQuery 23 | 24 | 25 | Installation 26 | ------------ 27 | 28 | 1. Install python library using pip: pip install django-clever-selects 29 | 30 | 2. Add ``clever_selects`` to ``INSTALLED_APPS`` in your Django settings file 31 | 32 | 3. Add ``clever_selects_extras`` to your ``{% load %}`` statement and put ``{% clever_selects_js_import %}`` tag before closing ``
`` element. It is important to load clever-selects.js file after body content, so do not put it in the
! 33 | 34 | 35 | Usage 36 | ----- 37 | 38 | Forms 39 | ''''' 40 | 41 | Form must inherit from ``ChainedChoicesMixin`` (or from ``ChainedChoicesForm`` / ``ChainedChoicesModelForm``, depends on your needs) 42 | which loads the options when there is already an instance or initial data:: 43 | 44 | from clever_selects.form_fields import ChainedChoiceField 45 | from clever_selects.forms import ChainedChoicesForm 46 | 47 | 48 | class SimpleChainForm(ChainedChoicesForm): 49 | first_field = ChoiceField(choices=(('', '------------'), (1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), )) 50 | second_field = ChainedChoiceField(parent_field='first_field', ajax_url=reverse_lazy('ajax_chained_view')) 51 | 52 | 53 | class MultipleChainForm(ChainedChoicesForm): 54 | first_field = ChoiceField(choices=(('', '------------'), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), )) 55 | second_field = ChainedChoiceField(parent_field='first_field', ajax_url=reverse_lazy('ajax_chained_view')) 56 | third_field = ChainedChoiceField(parent_field='second_field', ajax_url=reverse_lazy('ajax_chained_view')) 57 | fourth_field = ChainedChoiceField(parent_field='third_field', ajax_url=reverse_lazy('ajax_chained_view')) 58 | fifth_field = ChainedChoiceField(parent_field='fourth_field', ajax_url=reverse_lazy('ajax_chained_view')) 59 | 60 | 61 | class ModelChainForm(ChainedChoicesModelForm): 62 | brand = forms.ModelChoiceField(queryset=CarBrand.objects.all(), required=True, 63 | empty_label=_('Select a car brand')) 64 | model = ChainedModelChoiceField(parent_field='brand', ajax_url=reverse_lazy('ajax_chained_models'), 65 | empty_label=_('Select a car model'), model=BrandModel, required=True) 66 | engine = forms.ChoiceField(choices=([('', _('All engine types'))] + Car.ENGINES), required=False) 67 | color = ChainedChoiceField(parent_field='model', ajax_url=reverse_lazy('ajax_chained_colors'), 68 | empty_label=_('Select a car model'), required=False) 69 | 70 | class Meta: 71 | model = Car 72 | 73 | 74 | Notice that ajax URLs could differ of each field for different purposes. See example project for more use cases. 75 | 76 | In order to pre-populate child fields, the form can need to have access to the current user. This can be done by passing 77 | the user to the kwargs of the form's __init__() method in the form's view. The ChainedSelectFormViewMixin takes care 78 | of this for you.:: 79 | 80 | class CreateCarView(ChainedSelectFormViewMixin, CreateView) 81 | template_name = "create_car.html" 82 | form_class = ModelChainForm 83 | model = Car 84 | 85 | Views 86 | ''''' 87 | 88 | Ajax call is made whenever the parent field is changed. You must set up the ajax URL to return json list of lists:: 89 | 90 | class AjaxChainedView(BaseDetailView): 91 | """ 92 | View to handle the ajax request for the field options. 93 | """ 94 | 95 | def get(self, request, *args, **kwargs): 96 | field = request.GET.get('field') 97 | parent_value = request.GET.get("parent_value") 98 | 99 | vals_list = [] 100 | for x in range(1, 6): 101 | vals_list.append(x*int(parent_value)) 102 | 103 | choices = tuple(zip(vals_list, vals_list)) 104 | 105 | response = HttpResponse( 106 | json.dumps(choices, cls=DjangoJSONEncoder), 107 | mimetype='application/javascript' 108 | ) 109 | add_never_cache_headers(response) 110 | return response 111 | 112 | 113 | Or you can use ``ChainedSelectChoicesView`` class helper like this:: 114 | 115 | class AjaxChainedView(ChainedSelectChoicesView): 116 | def get_choices(self): 117 | vals_list = [] 118 | for x in range(1, 6): 119 | vals_list.append(x*int(self.parent_value)) 120 | return tuple(zip(vals_list, vals_list)) 121 | 122 | or like this:: 123 | 124 | class AjaxChainedView(ChainedSelectChoicesView): 125 | def get_child_set(self): 126 | return ChildModel.object.filter(parent_id=self.parent_value) 127 | 128 | Don't forget to update your urls.py:: 129 | 130 | url(r'^ajax/custom-chained-view-url/$', AjaxChainedView.as_view(), name='ajax_chained_view'), 131 | 132 | Authors 133 | ------- 134 | 135 | Library is by `Erik Telepovsky` from `Pragmatic Mates`_. See `our other libraries`_. 136 | 137 | .. _Pragmatic Mates: http://www.pragmaticmates.com/ 138 | .. _our other libraries: https://github.com/PragmaticMates -------------------------------------------------------------------------------- /clever_selects/__init__.py: -------------------------------------------------------------------------------- 1 | VERSION='1.1.0' 2 | -------------------------------------------------------------------------------- /clever_selects/admin.py: -------------------------------------------------------------------------------- 1 | 2 | class ChainedSelectAdminMixin(object): 3 | 4 | def get_form(self, request, obj=None, **kwargs): 5 | form = super(ChainedSelectAdminMixin, self).get_form(request, obj, **kwargs) 6 | if request.user: 7 | form.user = request.user 8 | return form 9 | -------------------------------------------------------------------------------- /clever_selects/form_fields.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | from django.core import validators 4 | from django.core.exceptions import ValidationError 5 | from django.forms import ChoiceField 6 | from django.forms.models import ModelChoiceField, ModelMultipleChoiceField 7 | 8 | from .widgets import ChainedSelect, ChainedSelectMultiple 9 | 10 | 11 | class ChainedChoiceField(ChoiceField): 12 | def __init__(self, parent_field, ajax_url, choices=None, empty_label='--------', *args, **kwargs): 13 | self.parent_field = parent_field 14 | self.ajax_url = ajax_url 15 | self.choices = choices or (('', empty_label), ) 16 | self.empty_label = empty_label 17 | 18 | defaults = { 19 | 'widget': ChainedSelect(parent_field=parent_field, ajax_url=ajax_url, attrs={'empty_label': empty_label}), 20 | } 21 | defaults.update(kwargs) 22 | 23 | super(ChainedChoiceField, self).__init__(choices=self.choices, *args, **defaults) 24 | 25 | def valid_value(self, value): 26 | """Dynamic choices so just return True for now""" 27 | return True 28 | 29 | 30 | class ChainedModelChoiceField(ModelChoiceField): 31 | def __init__(self, parent_field, ajax_url, model, empty_label='--------', *args, **kwargs): 32 | self.parent_field = parent_field 33 | self.ajax_url = ajax_url 34 | self.model = model 35 | # self.queryset = model.objects.all() # Large querysets could take long time to load all values (django-cities) 36 | self.queryset = model.objects.none() 37 | self.empty_label = empty_label 38 | 39 | defaults = { 40 | 'widget': ChainedSelect(parent_field=parent_field, ajax_url=ajax_url, attrs={'empty_label': empty_label}), 41 | } 42 | defaults.update(kwargs) 43 | 44 | super(ChainedModelChoiceField, self).__init__(queryset=self.queryset, empty_label=empty_label, *args, **defaults) 45 | 46 | def valid_value(self, value): 47 | """Dynamic choices so just return True for now""" 48 | return True 49 | 50 | def to_python(self, value): 51 | empty_values = getattr(self, 'empty_values', list(validators.EMPTY_VALUES)) 52 | if value in empty_values: 53 | return None 54 | try: 55 | key = self.to_field_name or 'pk' 56 | value = self.model.objects.get(**{key: value}) 57 | except (ValueError, self.queryset.model.DoesNotExist): 58 | raise ValidationError(self.error_messages['invalid_choice'], code='invalid_choice') 59 | return value 60 | 61 | def validate(self, value): 62 | """ 63 | Validates that the input is in self.choices. 64 | """ 65 | super(ChoiceField, self).validate(value) 66 | if value and not self.valid_value(value): 67 | raise ValidationError( 68 | self.error_messages['invalid_choice'], 69 | code='invalid_choice', 70 | params={'value': value}, 71 | ) 72 | 73 | 74 | class ChainedModelMultipleChoiceField(ModelMultipleChoiceField): 75 | def __init__(self, parent_field, ajax_url, model, *args, **kwargs): 76 | self.parent_field = parent_field 77 | self.ajax_url = ajax_url 78 | self.model = model 79 | self.queryset = model.objects.all() 80 | 81 | defaults = { 82 | 'widget': ChainedSelectMultiple(parent_field=parent_field, ajax_url=ajax_url), 83 | } 84 | defaults.update(kwargs) 85 | 86 | super(ChainedModelMultipleChoiceField, self).__init__(queryset=self.queryset, *args, **defaults) 87 | -------------------------------------------------------------------------------- /clever_selects/forms.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | import json 4 | 5 | from django import forms 6 | from django.contrib.auth.models import AnonymousUser 7 | from django.core.exceptions import ObjectDoesNotExist 8 | 9 | try: 10 | from django.urls import reverse, resolve 11 | except: 12 | from django.core.urlresolvers import reverse, resolve 13 | 14 | from django.core.validators import EMPTY_VALUES 15 | from django.db import models 16 | from django.http.request import HttpRequest 17 | from django.utils.encoding import smart_str, force_str 18 | 19 | from .form_fields import ChainedChoiceField, ChainedModelChoiceField, ChainedModelMultipleChoiceField 20 | 21 | 22 | class ChainedChoicesMixin(object): 23 | """ 24 | Form Mixin to be used with ChainedChoicesForm and ChainedChoicesModelForm. 25 | It loads the options when there is already an instance or initial data. 26 | """ 27 | user = None 28 | prefix = None 29 | fields = [] 30 | chained_fields_names = [] 31 | chained_model_fields_names = [] 32 | 33 | def init_chained_choices(self, *args, **kwargs): 34 | self.chained_fields_names = self.get_fields_names_by_type(ChainedChoiceField) 35 | self.chained_model_fields_names = self.get_fields_names_by_type(ChainedModelChoiceField) + self.get_fields_names_by_type(ChainedModelMultipleChoiceField) 36 | self.user = kwargs.get('user', self.user) 37 | 38 | if kwargs.get('data', None) is not None: 39 | self.set_choices_via_ajax(kwargs['data']) 40 | 41 | elif len(args) > 0 and args[0] not in EMPTY_VALUES: 42 | self.set_choices_via_ajax(args[0]) 43 | 44 | elif kwargs.get('instance', None) is not None: 45 | oldest_parent_field_names = list(set(self.get_oldest_parent_field_names())) 46 | youngest_child_names = list(set(self.get_youngest_children_field_names())) 47 | 48 | for youngest_child_name in youngest_child_names: 49 | self.find_instance_attr(kwargs['instance'], youngest_child_name) 50 | 51 | for oldest_parent_field_name in oldest_parent_field_names: 52 | try: 53 | self.fields[oldest_parent_field_name].initial = getattr(self, '%s' % oldest_parent_field_name) 54 | except AttributeError: 55 | pass 56 | 57 | self.set_choices_via_ajax() 58 | 59 | elif 'initial' in kwargs and kwargs['initial'] not in EMPTY_VALUES: 60 | self.set_choices_via_ajax(kwargs['initial'], is_initial=True) 61 | else: 62 | for field_name in self.chained_fields_names + self.chained_model_fields_names: 63 | empty_label = self.fields[field_name].empty_label 64 | self.fields[field_name].choices = [('', empty_label)] 65 | 66 | def set_choices_via_ajax(self, kwargs=None, is_initial=False): 67 | for field_name in self.chained_fields_names + self.chained_model_fields_names: 68 | field = self.fields[field_name] 69 | 70 | try: 71 | if kwargs is not None: 72 | # initial data do not have any prefix 73 | if self.prefix in EMPTY_VALUES or is_initial: 74 | parent_value = kwargs.get(field.parent_field, None) 75 | field_value = kwargs.get(field_name, None) 76 | else: 77 | parent_value = kwargs.get('%s-%s' % (self.prefix, field.parent_field), None) 78 | field_value = kwargs.get('%s-%s' % (self.prefix, field_name), None) 79 | else: 80 | parent_value = self.initial.get(field.parent_field, None) 81 | field_value = self.initial.get(field_name, None) 82 | 83 | if parent_value is None: 84 | parent_value = getattr(self, '%s' % field.parent_field, None) 85 | 86 | if field_value is None: 87 | field_value = getattr(self, '%s' % field_name, None) 88 | 89 | field.choices = [('', field.empty_label)] 90 | 91 | # check that parent_value is valid 92 | if parent_value: 93 | parent_value = getattr(parent_value, 'pk', parent_value) 94 | 95 | url = force_str(field.ajax_url) 96 | params = { 97 | 'field_name': field_name, 98 | 'parent_value': parent_value, 99 | 'field_value': field_value 100 | } 101 | 102 | # This will get the callable from the url. 103 | # All we need to do is pass in a 'request' 104 | url_callable = resolve(url).func 105 | 106 | # Build the fake request 107 | fake_request = HttpRequest() 108 | fake_request.META["SERVER_NAME"] = "localhost" 109 | fake_request.META["SERVER_PORT"] = '80' 110 | 111 | # Add parameters and user if supplied 112 | fake_request.method = "GET" 113 | for key, value in params.items(): 114 | fake_request.GET[key] = value 115 | 116 | if hasattr(self, "user") and self.user: 117 | fake_request.user = self.user 118 | else: 119 | fake_request.user = AnonymousUser() 120 | 121 | # Get the response 122 | response = url_callable(fake_request) 123 | 124 | # Apply the data (if it's returned) 125 | if smart_str(response.content): 126 | try: 127 | field.choices += json.loads(smart_str(response.content)) 128 | except ValueError: 129 | raise ValueError('Data returned from request (url={url}, params={params}) could not be deserialized to Python object: {data}'.format( 130 | url=url, 131 | params=params, 132 | data=response.content 133 | )) 134 | 135 | field.initial = field_value 136 | 137 | except ObjectDoesNotExist: 138 | field.choices = () 139 | 140 | def get_fields_names_by_type(self, type_): 141 | result = [] 142 | for field_name in self.fields: 143 | field = self.fields[field_name] 144 | if isinstance(field, type_): 145 | result.append(field_name) 146 | return result 147 | 148 | def get_parent_fields_names(self): 149 | result = [] 150 | for field_name in self.fields: 151 | field = self.fields[field_name] 152 | if hasattr(field, 'parent_field'): 153 | result.append(field.parent_field) 154 | return result 155 | 156 | def get_children_field_names(self, parent_name): 157 | if parent_name in EMPTY_VALUES: 158 | return [] 159 | result = [] 160 | for field_name in self.fields: 161 | field = self.fields[field_name] 162 | if getattr(field, 'parent_field', None) == parent_name: 163 | result.append(field_name) 164 | return result 165 | 166 | def get_chained_fields_names(self): 167 | chained_fields_names = self.get_fields_names_by_type(ChainedChoiceField) 168 | chained_model_fields_names = self.get_fields_names_by_type(ChainedModelChoiceField) 169 | return chained_fields_names + chained_model_fields_names 170 | 171 | def get_oldest_parent_field_names(self): 172 | chained_fields_names = self.get_fields_names_by_type(ChainedChoiceField) 173 | chained_model_fields_names = self.get_fields_names_by_type(ChainedModelChoiceField) 174 | 175 | oldest_parent_field_names = [] 176 | for field_name in self.get_parent_fields_names(): 177 | if field_name not in chained_fields_names and field_name not in chained_model_fields_names: 178 | oldest_parent_field_names.append(field_name) 179 | return oldest_parent_field_names 180 | 181 | def get_youngest_children_field_names(self): 182 | result = [] 183 | chained_fields_names = self.get_fields_names_by_type(ChainedChoiceField) 184 | chained_model_fields_names = self.get_fields_names_by_type(ChainedModelChoiceField) 185 | 186 | for field_name in chained_fields_names + chained_model_fields_names: 187 | if field_name not in self.get_parent_fields_names(): 188 | result.append(field_name) 189 | return result 190 | 191 | def find_instance_attr(self, instance, attr_name): 192 | field = self.fields[attr_name] 193 | if hasattr(instance, attr_name): 194 | attribute = getattr(instance, attr_name) 195 | attr_value = getattr(attribute, 'pk', smart_str(attribute)) if attribute else None 196 | setattr(self, '%s' % attr_name, attr_value) 197 | 198 | if hasattr(field, 'parent_field'): 199 | parent_instance = attribute if isinstance(attribute, models.Model) else instance 200 | self.find_instance_attr(parent_instance, field.parent_field) 201 | 202 | 203 | class ChainedChoicesForm(forms.Form, ChainedChoicesMixin): 204 | """ 205 | Form class to be used with ChainedChoiceField and ChainedSelect widget 206 | If there is request POST data in *args (i.e. form validation was invalid) 207 | then the options will be loaded when the form is built. 208 | """ 209 | 210 | def __init__(self, language_code=None, *args, **kwargs): 211 | if kwargs.get('user'): 212 | self.user = kwargs.pop('user') # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole 213 | super(ChainedChoicesForm, self).__init__(*args, **kwargs) 214 | self.language_code = language_code 215 | self.init_chained_choices(*args, **kwargs) 216 | 217 | def is_valid(self): 218 | if self.language_code: 219 | # response is not translated to requested language code :/ 220 | # so translation is triggered manually 221 | from django.utils.translation import activate 222 | activate(self.language_code) 223 | return super(ChainedChoicesForm, self).is_valid() 224 | 225 | 226 | class ChainedChoicesModelForm(forms.ModelForm, ChainedChoicesMixin): 227 | """ 228 | Form class to be used with ChainedChoiceField and ChainedSelect widget 229 | If there is already an instance (i.e. editing) 230 | then the options will be loaded when the form is built. 231 | """ 232 | 233 | def __init__(self, *args, **kwargs): 234 | if kwargs.get('user'): 235 | self.user = kwargs.pop('user') # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole 236 | super(ChainedChoicesModelForm, self).__init__(*args, **kwargs) 237 | self.language_code = kwargs.get('language_code', None) 238 | self.init_chained_choices(*args, **kwargs) 239 | 240 | def is_valid(self): 241 | if self.language_code: 242 | # response is not translated to requested language code :/ 243 | # so translation is triggered manually 244 | from django.utils.translation import activate 245 | activate(self.language_code) 246 | return super(ChainedChoicesModelForm, self).is_valid() 247 | -------------------------------------------------------------------------------- /clever_selects/static/js/clever-selects.js: -------------------------------------------------------------------------------- 1 | function loadChildChoices(parentField, child) { 2 | var valueField = child; 3 | var ajaxUrl = valueField.getAttribute("ajax_url"); 4 | var emptyLabel = valueField.getAttribute('empty_label') || '--------'; 5 | 6 | var headers = new Headers(); 7 | headers.append("Accept", "application/json"); 8 | 9 | var request = new Request( 10 | ajaxUrl + "?field=" + valueField.getAttribute("name") + "&parent_field=" + parentField.getAttribute("name") + "&parent_value=" + parentField.value, 11 | { 12 | method: "GET", 13 | headers: headers, 14 | credentials: 'same-origin' 15 | } 16 | ); 17 | 18 | fetch(request).then(function(response) { 19 | return response.json(); 20 | }).then(function(options) { 21 | var optionsHTML = ""; 22 | 23 | if (!child[0].hasAttribute("multiple")) { 24 | optionsHTML += ''; 25 | } 26 | 27 | options.forEach(function(option) { 28 | optionsHTML += ''; 29 | }); 30 | 31 | valueField.innerHTML = optionsHTML; 32 | valueField.dispatchEvent(new Event("change")); 33 | valueField.dispatchEvent(new Event("load")); 34 | valueField.dispatchEvent(new Event("liszt:updated")); // support for chosen versions < 1.0.0 35 | valueField.dispatchEvent(new Event("chosen:updated")); // support for chosen versions >= 1.0.0 36 | }); 37 | }; 38 | 39 | function loadAllChainedChoices(parentField) { 40 | var chained_ids = parentField.getAttribute('chained_ids').split(","); 41 | 42 | chained_ids.forEach(function(chained_id) { 43 | var child = document.getElementById(chained_id); 44 | loadChildChoices(parentField, child); 45 | }); 46 | }; 47 | 48 | 49 | document.addEventListener("DOMContentLoaded", function() { 50 | var parentFields = document.querySelectorAll(".chained-parent-field"); 51 | 52 | parentFields.forEach(function(parentField) { 53 | if ( parentField.classList.contains('chzn-done') ) { 54 | $(parentField).change(function() { 55 | loadAllChainedChoices(this); 56 | }); 57 | } else { 58 | parentField.addEventListener("change", function() { loadAllChainedChoices(this); }); 59 | } 60 | }); 61 | }); -------------------------------------------------------------------------------- /clever_selects/templates/clever_selects/widgets/chained_select.html: -------------------------------------------------------------------------------- 1 | {% include "django/forms/widgets/select.html" %} 2 | 19 | -------------------------------------------------------------------------------- /clever_selects/templatetags/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'Erik Telepovsky' 2 | -------------------------------------------------------------------------------- /clever_selects/templatetags/clever_selects_extras.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from django import template 4 | from django.middleware.csrf import get_token 5 | from django.conf import settings 6 | from django.core.files.storage import get_storage_class 7 | from django.utils.safestring import mark_safe 8 | 9 | from clever_selects import VERSION 10 | 11 | staticfiles_storage = get_storage_class(settings.STATICFILES_STORAGE)() 12 | 13 | register = template.Library() 14 | 15 | log = logging.getLogger('clever_selects') 16 | 17 | 18 | @register.simple_tag(takes_context=True) 19 | def clever_selects_js_import(context, csrf=True): 20 | """ Return the js script tag for the clever-selects.js file. 21 | If the csrf argument is present and it's ``nocsrf`` clever-selects will not 22 | try to mark the request as if it need the csrf token. By default use 23 | the clever_selects_js_import template tag will make django set the csrftoken 24 | cookie on the current request.""" 25 | 26 | csrf = csrf != 'nocsrf' 27 | request = context.get('request') 28 | 29 | if request and csrf: 30 | get_token(request) 31 | elif csrf: 32 | log.warning("The 'request' object must be accessible within the context. " 33 | "You must add 'django.contrib.messages.context_processors.request' " 34 | "to your TEMPLATE_CONTEXT_PROCESSORS and render your views using a RequestContext.") 35 | 36 | url = staticfiles_storage.url('js/clever-selects.js') 37 | return mark_safe('' % (url, VERSION)) 38 | -------------------------------------------------------------------------------- /clever_selects/views.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Erik Telepovsky 3 | ''' 4 | 5 | import json 6 | 7 | from django.core.exceptions import ObjectDoesNotExist 8 | from django.core.validators import EMPTY_VALUES 9 | from django.core.serializers.json import DjangoJSONEncoder 10 | from django.http import HttpResponse 11 | from django.utils.cache import add_never_cache_headers 12 | from django.views.generic.base import View 13 | 14 | 15 | class ChainedSelectFormViewMixin(object): 16 | 17 | def get_form_kwargs(self): 18 | kwargs = super(ChainedSelectFormViewMixin, self).get_form_kwargs() 19 | kwargs.update({'user': self.request.user}) 20 | return kwargs 21 | 22 | 23 | class ChainedSelectChoicesView(View): 24 | child_set = None 25 | 26 | def dispatch(self, request, *args, **kwargs): 27 | self.field = request.GET.get("field") 28 | self.field_value = request.GET.get("field_value", None) 29 | self.parent_field = request.GET.get("parent_field") 30 | self.parent_value = request.GET.get("parent_value") 31 | if self.parent_value in EMPTY_VALUES + ('None', ): 32 | return self.empty_response() 33 | return super(ChainedSelectChoicesView, self).dispatch(request, *args, **kwargs) 34 | 35 | def get(self, request, *args, **kwargs): 36 | response = HttpResponse( 37 | json.dumps(self.get_choices(), cls=DjangoJSONEncoder), 38 | content_type='application/javascript' 39 | ) 40 | add_never_cache_headers(response) 41 | return response 42 | 43 | def empty_response(self): 44 | response = HttpResponse( 45 | json.dumps((), cls=DjangoJSONEncoder), 46 | content_type='application/javascript' 47 | ) 48 | add_never_cache_headers(response) 49 | return response 50 | 51 | def get_child_set(self): 52 | return self.child_set 53 | 54 | def get_choices(self): 55 | choices = [] 56 | if self.parent_value in EMPTY_VALUES + ('None', ) or self.get_child_set() is None: 57 | return [] 58 | try: 59 | for obj in self.get_child_set().all(): 60 | choices.append((obj.pk, str(obj))) 61 | return choices 62 | except ObjectDoesNotExist: 63 | return [] 64 | -------------------------------------------------------------------------------- /clever_selects/widgets.py: -------------------------------------------------------------------------------- 1 | from django.forms.widgets import Select, SelectMultiple 2 | 3 | 4 | class ChainedSelectMixin(object): 5 | """ 6 | A ChoiceField widget mixin where the options for the select are dependent on the value of the parent select field. 7 | When the parent field is changed, an ajax call is made to determine the options. 8 | 9 | Form must inherit from ChainedChoicesMixin (or from helper forms ChainedChoicesForm and ChainedChoicesModelForm) 10 | which loads the options when there is already an instance or initial data. 11 | """ 12 | 13 | template_name = 'clever_selects/widgets/chained_select.html' 14 | 15 | def __init__(self, parent_field=None, ajax_url=None, *args, **kwargs): 16 | self.parent_field = parent_field 17 | self.ajax_url = ajax_url 18 | super(ChainedSelectMixin, self).__init__(*args, **kwargs) 19 | 20 | def get_context(self, name, value, attrs): 21 | context = super(ChainedSelectMixin, self).get_context(name, value, attrs) 22 | 23 | field_prefix = attrs['id'][:attrs['id'].rfind('-') + 1] 24 | 25 | if not field_prefix: 26 | parent_field_id = "id_" + self.parent_field 27 | else: 28 | parent_field_id = field_prefix + self.parent_field 29 | 30 | context['widget']['attrs']['ajax_url'] = self.ajax_url 31 | context['js_parent_field_id'] = parent_field_id 32 | context['js_chained_id'] = attrs['id'] 33 | return context 34 | 35 | 36 | class ChainedSelect(ChainedSelectMixin, Select): 37 | pass 38 | 39 | 40 | class ChainedSelectMultiple(ChainedSelectMixin, SelectMultiple): 41 | pass 42 | -------------------------------------------------------------------------------- /example/clever_selects: -------------------------------------------------------------------------------- 1 | ../clever_selects -------------------------------------------------------------------------------- /example/example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PragmaticMates/django-clever-selects/6b54da0f87a2193cf1fdae4b21945ac0979411a7/example/example/__init__.py -------------------------------------------------------------------------------- /example/example/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from models import CarBrand, BrandModel, Car 4 | 5 | 6 | class ModelInlineAdmin(admin.TabularInline): 7 | model = BrandModel 8 | extra = 2 9 | 10 | 11 | class CarBrandAdmin(admin.ModelAdmin): 12 | inlines = [ModelInlineAdmin, ] 13 | 14 | 15 | class BrandModelAdmin(admin.ModelAdmin): 16 | list_display = ('brand', 'title') 17 | list_filter = ('brand', ) 18 | 19 | 20 | class CarAdmin(admin.ModelAdmin): 21 | list_display = ('__str__', 'engine', 'color', 'numberplate') 22 | list_filter = ('model', ) 23 | 24 | 25 | admin.site.register(CarBrand, CarBrandAdmin) 26 | admin.site.register(BrandModel, BrandModelAdmin) 27 | admin.site.register(Car, CarAdmin) 28 | -------------------------------------------------------------------------------- /example/example/fixtures/initial_data.json: -------------------------------------------------------------------------------- 1 | [{"pk": 2, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:10:49.752Z", "modified": "2014-01-08T10:17:33.856Z", "title": "Audi"}}, {"pk": 3, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:20:16.322Z", "modified": "2014-01-08T10:22:19.863Z", "title": "BMW"}}, {"pk": 4, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:22:56.626Z", "modified": "2014-01-08T10:22:56.626Z", "title": "Jaguar"}}, {"pk": 5, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:24:14.484Z", "modified": "2014-01-08T10:24:14.484Z", "title": "Lexus"}}, {"pk": 6, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:26:57.024Z", "modified": "2014-01-08T10:26:57.024Z", "title": "Porsche"}}, {"pk": 7, "model": "example.carbrand", "fields": {"created": "2014-01-08T10:27:55.739Z", "modified": "2014-01-08T10:27:55.739Z", "title": "\u0160koda"}}, {"pk": 12, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.755Z", "modified": "2014-01-08T10:10:49.755Z", "title": "A1"}}, {"pk": 13, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.756Z", "modified": "2014-01-08T10:10:49.756Z", "title": "A1 Sportback"}}, {"pk": 14, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.757Z", "modified": "2014-01-08T10:10:49.757Z", "title": "A3"}}, {"pk": 15, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.758Z", "modified": "2014-01-08T10:10:49.758Z", "title": "A3 Cabriolet"}}, {"pk": 16, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.759Z", "modified": "2014-01-08T10:10:49.759Z", "title": "A3 Sportback"}}, {"pk": 17, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.760Z", "modified": "2014-01-08T10:10:49.760Z", "title": "A4"}}, {"pk": 18, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.760Z", "modified": "2014-01-08T10:10:49.760Z", "title": "A4 Allroad Quattro"}}, {"pk": 19, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.761Z", "modified": "2014-01-08T10:10:49.761Z", "title": "A4 Avant"}}, {"pk": 20, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.762Z", "modified": "2014-01-08T10:10:49.762Z", "title": "A5 Cabriolet"}}, {"pk": 21, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.762Z", "modified": "2014-01-08T10:10:49.762Z", "title": "A5 Coupe"}}, {"pk": 22, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:10:49.763Z", "modified": "2014-01-08T10:10:49.763Z", "title": "A5 Sportback"}}, {"pk": 23, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.590Z", "modified": "2014-01-08T10:14:32.590Z", "title": "A6"}}, {"pk": 24, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.591Z", "modified": "2014-01-08T10:14:32.591Z", "title": "A6 Allroad quattro"}}, {"pk": 25, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.592Z", "modified": "2014-01-08T10:14:32.592Z", "title": "A6 Avant"}}, {"pk": 26, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.592Z", "modified": "2014-01-08T10:14:32.592Z", "title": "A7"}}, {"pk": 27, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.593Z", "modified": "2014-01-08T10:14:32.593Z", "title": "A7 Sportback"}}, {"pk": 28, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.593Z", "modified": "2014-01-08T10:14:32.593Z", "title": "A8"}}, {"pk": 29, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.594Z", "modified": "2014-01-08T10:14:32.594Z", "title": "A8 L"}}, {"pk": 30, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.595Z", "modified": "2014-01-08T10:14:32.595Z", "title": "A8 L W12"}}, {"pk": 31, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.595Z", "modified": "2014-01-08T10:14:32.595Z", "title": "Q3"}}, {"pk": 32, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.596Z", "modified": "2014-01-08T10:14:32.596Z", "title": "Q5"}}, {"pk": 33, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.596Z", "modified": "2014-01-08T10:14:32.596Z", "title": "Q7"}}, {"pk": 34, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.597Z", "modified": "2014-01-08T10:14:32.597Z", "title": "Q7 W12 TDI"}}, {"pk": 35, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:14:32.597Z", "modified": "2014-01-08T10:14:32.597Z", "title": "R8 Coupe"}}, {"pk": 36, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.890Z", "modified": "2014-01-08T10:17:33.890Z", "title": "R8 Spyder"}}, {"pk": 37, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.891Z", "modified": "2014-01-08T10:17:33.891Z", "title": "RS3 Sportback"}}, {"pk": 38, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.891Z", "modified": "2014-01-08T10:17:33.891Z", "title": "S3"}}, {"pk": 39, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.892Z", "modified": "2014-01-08T10:17:33.892Z", "title": "S3 Sportback"}}, {"pk": 40, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.892Z", "modified": "2014-01-08T10:17:33.892Z", "title": "S4"}}, {"pk": 41, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.893Z", "modified": "2014-01-08T10:17:33.893Z", "title": "S5 Cabriolet"}}, {"pk": 42, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.893Z", "modified": "2014-01-08T10:17:33.893Z", "title": "S5 Coupe"}}, {"pk": 43, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.894Z", "modified": "2014-01-08T10:17:33.894Z", "title": "S5 Sportback"}}, {"pk": 44, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.894Z", "modified": "2014-01-08T10:17:33.894Z", "title": "S6"}}, {"pk": 45, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.895Z", "modified": "2014-01-08T10:17:33.895Z", "title": "S6 Avant"}}, {"pk": 46, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.895Z", "modified": "2014-01-08T10:17:33.895Z", "title": "S8"}}, {"pk": 47, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.896Z", "modified": "2014-01-08T10:17:33.896Z", "title": "TT"}}, {"pk": 48, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.896Z", "modified": "2014-01-08T10:17:33.896Z", "title": "TT Coupe"}}, {"pk": 50, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.897Z", "modified": "2014-01-08T10:17:33.897Z", "title": "TT RS Coupe"}}, {"pk": 51, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.898Z", "modified": "2014-01-08T10:17:33.898Z", "title": "TT RS Roadster"}}, {"pk": 49, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.897Z", "modified": "2014-01-08T10:17:33.897Z", "title": "TT Roadster"}}, {"pk": 52, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.898Z", "modified": "2014-01-08T10:17:33.898Z", "title": "TTS Coupe"}}, {"pk": 53, "model": "example.brandmodel", "fields": {"brand": 2, "created": "2014-01-08T10:17:33.899Z", "modified": "2014-01-08T10:17:33.899Z", "title": "TTS Roadster"}}, {"pk": 54, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.324Z", "modified": "2014-01-08T10:20:16.324Z", "title": "1 3-door"}}, {"pk": 55, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.325Z", "modified": "2014-01-08T10:20:16.325Z", "title": "1 5-door"}}, {"pk": 56, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.326Z", "modified": "2014-01-08T10:20:16.326Z", "title": "1 Cabrio"}}, {"pk": 57, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.327Z", "modified": "2014-01-08T10:20:16.327Z", "title": "1 Coupe"}}, {"pk": 58, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.327Z", "modified": "2014-01-08T10:20:16.327Z", "title": "3 Cabrio"}}, {"pk": 59, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.328Z", "modified": "2014-01-08T10:20:16.328Z", "title": "3 Coupe"}}, {"pk": 60, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.328Z", "modified": "2014-01-08T10:20:16.328Z", "title": "3 Sedan"}}, {"pk": 61, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.329Z", "modified": "2014-01-08T10:20:16.329Z", "title": "3 Touring"}}, {"pk": 62, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.329Z", "modified": "2014-01-08T10:20:16.329Z", "title": "4 Cabrio"}}, {"pk": 63, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.329Z", "modified": "2014-01-08T10:20:16.330Z", "title": "4 Coupe"}}, {"pk": 64, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.330Z", "modified": "2014-01-08T10:20:16.330Z", "title": "5 ActiveHybrid"}}, {"pk": 65, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.330Z", "modified": "2014-01-08T10:20:16.330Z", "title": "5 Gran Turismo"}}, {"pk": 66, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.331Z", "modified": "2014-01-08T10:20:16.331Z", "title": "5 Sedan"}}, {"pk": 67, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.331Z", "modified": "2014-01-08T10:20:16.331Z", "title": "5 Touring"}}, {"pk": 68, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.332Z", "modified": "2014-01-08T10:20:16.332Z", "title": "6 Cabrio"}}, {"pk": 69, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.332Z", "modified": "2014-01-08T10:20:16.332Z", "title": "6 Coupe"}}, {"pk": 70, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.333Z", "modified": "2014-01-08T10:20:16.333Z", "title": "6 Gran Coupe"}}, {"pk": 71, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:20:16.333Z", "modified": "2014-01-08T10:20:16.333Z", "title": "7 ActiveHybrid"}}, {"pk": 72, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.887Z", "modified": "2014-01-08T10:22:19.887Z", "title": "7 Sedan"}}, {"pk": 73, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.888Z", "modified": "2014-01-08T10:22:19.888Z", "title": "M3 Cabrio"}}, {"pk": 74, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.889Z", "modified": "2014-01-08T10:22:19.889Z", "title": "M3 Coupe"}}, {"pk": 75, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.889Z", "modified": "2014-01-08T10:22:19.889Z", "title": "M3 Sedan"}}, {"pk": 76, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.890Z", "modified": "2014-01-08T10:22:19.890Z", "title": "M5 Sedan"}}, {"pk": 77, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.891Z", "modified": "2014-01-08T10:22:19.891Z", "title": "M6 Cabrio"}}, {"pk": 78, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.891Z", "modified": "2014-01-08T10:22:19.891Z", "title": "M6 Coupe"}}, {"pk": 79, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.892Z", "modified": "2014-01-08T10:22:19.892Z", "title": "X1"}}, {"pk": 80, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.892Z", "modified": "2014-01-08T10:22:19.892Z", "title": "X3"}}, {"pk": 81, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.893Z", "modified": "2014-01-08T10:22:19.893Z", "title": "X5"}}, {"pk": 82, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.893Z", "modified": "2014-01-08T10:22:19.893Z", "title": "X5 M"}}, {"pk": 83, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.894Z", "modified": "2014-01-08T10:22:19.894Z", "title": "X6"}}, {"pk": 84, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.895Z", "modified": "2014-01-08T10:22:19.895Z", "title": "X6 M"}}, {"pk": 85, "model": "example.brandmodel", "fields": {"brand": 3, "created": "2014-01-08T10:22:19.895Z", "modified": "2014-01-08T10:22:19.895Z", "title": "Z4"}}, {"pk": 86, "model": "example.brandmodel", "fields": {"brand": 4, "created": "2014-01-08T10:22:56.628Z", "modified": "2014-01-08T10:22:56.628Z", "title": "XF"}}, {"pk": 87, "model": "example.brandmodel", "fields": {"brand": 4, "created": "2014-01-08T10:22:56.629Z", "modified": "2014-01-08T10:22:56.629Z", "title": "XJ"}}, {"pk": 88, "model": "example.brandmodel", "fields": {"brand": 4, "created": "2014-01-08T10:22:56.630Z", "modified": "2014-01-08T10:22:56.630Z", "title": "XK"}}, {"pk": 89, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.485Z", "modified": "2014-01-08T10:24:14.485Z", "title": "CT"}}, {"pk": 90, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.487Z", "modified": "2014-01-08T10:24:14.487Z", "title": "CT Hybrid"}}, {"pk": 91, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.487Z", "modified": "2014-01-08T10:24:14.487Z", "title": "GS"}}, {"pk": 92, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.488Z", "modified": "2014-01-08T10:24:14.488Z", "title": "GS Hybrid"}}, {"pk": 93, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.488Z", "modified": "2014-01-08T10:24:14.488Z", "title": "IS"}}, {"pk": 94, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.490Z", "modified": "2014-01-08T10:24:14.490Z", "title": "IS 250 C"}}, {"pk": 95, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.490Z", "modified": "2014-01-08T10:24:14.490Z", "title": "IS F"}}, {"pk": 96, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.491Z", "modified": "2014-01-08T10:24:14.491Z", "title": "LS"}}, {"pk": 97, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.492Z", "modified": "2014-01-08T10:24:14.492Z", "title": "LS Hybrid"}}, {"pk": 98, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.492Z", "modified": "2014-01-08T10:24:14.492Z", "title": "RX"}}, {"pk": 99, "model": "example.brandmodel", "fields": {"brand": 5, "created": "2014-01-08T10:24:14.493Z", "modified": "2014-01-08T10:24:14.493Z", "title": "RX Hybrid"}}, {"pk": 100, "model": "example.brandmodel", "fields": {"brand": 6, "created": "2014-01-08T10:26:57.029Z", "modified": "2014-01-08T10:26:57.029Z", "title": "911"}}, {"pk": 101, "model": "example.brandmodel", "fields": {"brand": 6, "created": "2014-01-08T10:26:57.031Z", "modified": "2014-01-08T10:26:57.031Z", "title": "Boxter"}}, {"pk": 102, "model": "example.brandmodel", "fields": {"brand": 6, "created": "2014-01-08T10:26:57.032Z", "modified": "2014-01-08T10:26:57.032Z", "title": "Cayanne"}}, {"pk": 103, "model": "example.brandmodel", "fields": {"brand": 6, "created": "2014-01-08T10:26:57.033Z", "modified": "2014-01-08T10:26:57.033Z", "title": "Cayman"}}, {"pk": 104, "model": "example.brandmodel", "fields": {"brand": 6, "created": "2014-01-08T10:26:57.034Z", "modified": "2014-01-08T10:26:57.034Z", "title": "Panamera"}}, {"pk": 105, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.741Z", "modified": "2014-01-08T10:27:55.741Z", "title": "Citigo"}}, {"pk": 106, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.742Z", "modified": "2014-01-08T10:27:55.742Z", "title": "Fabia"}}, {"pk": 107, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.742Z", "modified": "2014-01-08T10:27:55.743Z", "title": "Octavia"}}, {"pk": 108, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.743Z", "modified": "2014-01-08T10:27:55.743Z", "title": "Rapid"}}, {"pk": 109, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.744Z", "modified": "2014-01-08T10:27:55.744Z", "title": "Rapid Spaceback"}}, {"pk": 110, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.745Z", "modified": "2014-01-08T10:27:55.745Z", "title": "Roomster"}}, {"pk": 111, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.745Z", "modified": "2014-01-08T10:27:55.745Z", "title": "Superb"}}, {"pk": 112, "model": "example.brandmodel", "fields": {"brand": 7, "created": "2014-01-08T10:27:55.746Z", "modified": "2014-01-08T10:27:55.746Z", "title": "Yeti"}}, {"pk": 2, "model": "example.car", "fields": {"engine": "DIESEL", "created": "2014-01-09T08:48:42.907Z", "color": "WHITE", "modified": "2014-01-09T09:52:14.549Z", "numberplate": "A500", "model": 32}}, {"pk": 1, "model": "example.car", "fields": {"engine": "GASOLINE", "created": "2014-01-08T15:57:31.831Z", "color": "BLACK", "modified": "2014-01-09T09:52:37.215Z", "numberplate": "BMW333", "model": 76}}, {"pk": 9, "model": "example.car", "fields": {"engine": "GASOLINE", "created": "2014-01-09T09:45:50.896Z", "color": "RED", "modified": "2014-01-09T09:51:55.037Z", "numberplate": "P911", "model": 100}}, {"pk": 10, "model": "example.car", "fields": {"engine": "GASOLINE", "created": "2014-01-09T09:47:26.909Z", "color": "WHITE", "modified": "2014-01-09T09:52:52.774Z", "numberplate": "SK666", "model": 109}}] -------------------------------------------------------------------------------- /example/example/forms.py: -------------------------------------------------------------------------------- 1 | from django.core.urlresolvers import reverse_lazy 2 | from django.forms import ChoiceField, ModelChoiceField 3 | from django.utils.translation import gettext_lazy as _ 4 | 5 | from clever_selects.form_fields import ChainedChoiceField, ChainedModelChoiceField 6 | from clever_selects.forms import ChainedChoicesForm, ChainedChoicesModelForm 7 | 8 | from helpers import CONTINENTS, GENDER 9 | from models import CarBrand, Car, BrandModel 10 | 11 | 12 | class SimpleChainForm(ChainedChoicesForm): 13 | gender = ChoiceField(choices=[('', _('Select a gender'))] + list(GENDER)) 14 | name = ChainedChoiceField(parent_field='gender', ajax_url=reverse_lazy('ajax_chained_names'), empty_label=_('Select name')) 15 | 16 | 17 | class MultipleChainForm(ChainedChoicesForm): 18 | continent = ChoiceField(choices=[('', _('Select a continent'))] + list(CONTINENTS)) 19 | country = ChainedChoiceField(parent_field='continent', ajax_url=reverse_lazy('ajax_chained_countries')) 20 | city = ChainedChoiceField(parent_field='country', ajax_url=reverse_lazy('ajax_chained_cities')) 21 | 22 | 23 | class ModelChainForm(ChainedChoicesModelForm): 24 | brand = ModelChoiceField(queryset=CarBrand.objects.all(), required=True, empty_label=_('Select a car brand')) 25 | model = ChainedModelChoiceField(parent_field='brand', ajax_url=reverse_lazy('ajax_chained_models'), 26 | empty_label=_('Select a car model'), model=BrandModel, required=True) 27 | engine = ChoiceField(choices=([('', _('All engine types'))] + Car.ENGINES), required=False) 28 | color = ChainedChoiceField(parent_field='model', ajax_url=reverse_lazy('ajax_chained_colors'), 29 | empty_label=_('Select a car model'), required=False) 30 | 31 | class Meta: 32 | model = Car 33 | fields = ['brand', 'model', 'engine', 'color', 'numberplate'] 34 | -------------------------------------------------------------------------------- /example/example/helpers.py: -------------------------------------------------------------------------------- 1 | __author__ = 'Erik Telepovsky' 2 | 3 | 4 | GENDER_MALE = 'male' 5 | GENDER_FEMALE = 'female' 6 | GENDER = ( 7 | (GENDER_MALE, 'Male'), 8 | (GENDER_FEMALE, 'Female') 9 | ) 10 | 11 | NAMES = { 12 | GENDER_MALE: ['Andrew', 'Arthur', 'Ian', 'Eric', 'Leonard', 'Lukas', 'Matt', 'Peter', 'Vincent'], 13 | GENDER_FEMALE: ['Allison', 'Angela', 'Catherine', 'Elisabeth', 'Evangeline', 'Heidi', 'Katie', 'Lilly', 'Susan'] 14 | } 15 | 16 | CONTINENT_NORTH_AMERICA = 'north_america' 17 | CONTINENT_SOUTH_AMERICA = 'south_america' 18 | CONTINENT_EUROPE = 'europe' 19 | CONTINENT_ASIA = 'asia' 20 | CONTINENT_AFRICA = 'africa' 21 | CONTINENT_AUSTRALIA = 'australia' 22 | CONTINENT_ANTARCTICA = 'antarctica' 23 | CONTINENTS = ( 24 | (CONTINENT_NORTH_AMERICA, 'North America'), 25 | (CONTINENT_SOUTH_AMERICA, 'South America'), 26 | (CONTINENT_EUROPE, 'Europe'), 27 | (CONTINENT_ASIA, 'Asia'), 28 | (CONTINENT_AFRICA, 'Africa'), 29 | (CONTINENT_AUSTRALIA, 'Australia'), 30 | (CONTINENT_ANTARCTICA, 'Antarctica') 31 | ) 32 | 33 | 34 | # North America 35 | COUNTRY_ALASKA = 'Alaska' 36 | COUNTRY_CANADA = 'Canada' 37 | COUNTRY_USA = 'USA' 38 | COUNTRY_MEXICO = 'Mexico' 39 | 40 | # South America 41 | COUNTRY_COLOMBIA = 'Colombia' 42 | COUNTRY_VENEZUELA = 'Venezuela' 43 | COUNTRY_BRAZIL = 'Brazil' 44 | COUNTRY_CHILE = 'Chile' 45 | COUNTRY_URUGUAY = 'Uruguay' 46 | COUNTRY_ARGENTINA = 'Argentina' 47 | 48 | # Europe 49 | COUNTRY_SLOVAKIA = 'Slovakia' 50 | COUNTRY_SPAIN = 'Spain' 51 | COUNTRY_BULGARIA = 'Bulgaria' 52 | COUNTRY_PORTUGAL = 'Portugal' 53 | COUNTRY_ITALY = 'Italy' 54 | COUNTRY_UNITED_KINGDOM = 'United Kingdom' 55 | 56 | # Asia 57 | COUNTRY_CHINA = 'China' 58 | COUNTRY_RUSSIA = 'Russia' 59 | COUNTRY_JAPAN = 'Japan' 60 | COUNTRY_INDIA = 'India' 61 | 62 | # Africa 63 | COUNTRY_ALGERIA = 'Algeria' 64 | COUNTRY_EGYPT = 'Egypt' 65 | COUNTRY_SUDAN = 'Sudan' 66 | COUNTRY_ETHIOPIA = 'Ethiopia' 67 | COUNTRY_SOMALIA = 'Somalia' 68 | COUNTRY_MADAGASCAR = 'Madagascar' 69 | 70 | # Australia 71 | COUNTRY_WESTERN_AUSTRALIA = 'Western Australia' 72 | COUNTRY_NORTHERN_TERRITORY = 'Northern Territory' 73 | COUNTRY_SOUTH_AUSTRALIA = 'South Australia' 74 | COUNTRY_QUEENSLAND = 'Queensland' 75 | COUNTRY_NEW_SOUTH_WALES = 'New South Wales' 76 | COUNTRY_VICTORIA = 'Victoria' 77 | COUNTRY_AUSTRALIAN_CAPITAL_TERRITORY = 'Australian Capital Territory' 78 | COUNTRY_TASMANIA = 'Tasmania' 79 | 80 | # Antarctica 81 | COUNTRY_SOUTH_ORKNEY_ISLANDS = 'South Orkney Islands' 82 | COUNTRY_GRAHAM_LAND = 'Graham Land' 83 | COUNTRY_MARIE_BYRD_LAND = 'Marie Byrd Land' 84 | COUNTRY_QEEN_MAUD_LAND = 'Queen Maud Land' 85 | COUNTRY_VICTORIA_LAND = 'Victoria Land' 86 | COUNTRY_WILKES_LAND = 'Wilkes Land' 87 | 88 | COUNTRIES = { 89 | CONTINENT_NORTH_AMERICA: [ 90 | COUNTRY_ALASKA, COUNTRY_CANADA, COUNTRY_USA, COUNTRY_MEXICO 91 | ], 92 | CONTINENT_SOUTH_AMERICA: [ 93 | COUNTRY_COLOMBIA, COUNTRY_VENEZUELA, COUNTRY_BRAZIL, COUNTRY_CHILE, COUNTRY_URUGUAY, COUNTRY_ARGENTINA 94 | ], 95 | CONTINENT_EUROPE: [ 96 | COUNTRY_SLOVAKIA, COUNTRY_SPAIN, COUNTRY_BULGARIA, COUNTRY_PORTUGAL, COUNTRY_ITALY, COUNTRY_UNITED_KINGDOM 97 | ], 98 | CONTINENT_ASIA: [ 99 | COUNTRY_CHINA, COUNTRY_RUSSIA, COUNTRY_JAPAN, COUNTRY_INDIA 100 | ], 101 | CONTINENT_AFRICA: [ 102 | COUNTRY_ALGERIA, COUNTRY_EGYPT, COUNTRY_SUDAN, COUNTRY_ETHIOPIA, COUNTRY_SOMALIA, COUNTRY_MADAGASCAR 103 | ], 104 | CONTINENT_AUSTRALIA: [ 105 | COUNTRY_WESTERN_AUSTRALIA, COUNTRY_NORTHERN_TERRITORY, COUNTRY_SOUTH_AUSTRALIA, COUNTRY_QUEENSLAND, 106 | COUNTRY_NEW_SOUTH_WALES, COUNTRY_VICTORIA, COUNTRY_TASMANIA, COUNTRY_AUSTRALIAN_CAPITAL_TERRITORY 107 | ], 108 | CONTINENT_ANTARCTICA: [ 109 | COUNTRY_SOUTH_ORKNEY_ISLANDS, COUNTRY_GRAHAM_LAND, COUNTRY_MARIE_BYRD_LAND, COUNTRY_QEEN_MAUD_LAND, 110 | COUNTRY_VICTORIA_LAND, COUNTRY_WILKES_LAND 111 | ] 112 | } 113 | 114 | CITIES = { 115 | # North America 116 | COUNTRY_ALASKA: [ 117 | 'Anchorage', 'Fairbanks', 'Juneau', 'Sitka', 'Ketchikan', 'Wasilla', 'Kenai' 118 | ], 119 | COUNTRY_CANADA: [ 120 | 'Ottawa', 'Edmonton', 'Victoria', 'Winnipeg', 'Halifax', 'Toronto', 'Charlottetown', 'Quebec City' 121 | ], 122 | COUNTRY_USA: [ 123 | 'New York', 'Los Angeles', 'Chicago', 'Houston', 'Philadelphia', 'Phoenix', 'San Antonio', 'San Diego' 124 | ], 125 | COUNTRY_MEXICO: [ 126 | 'Mexico City', 'Ecatepec', 'Guadalajara', 'Puebla', 'Leon', 'Juarez', 'Tijuana' 127 | ], 128 | 129 | # South America 130 | COUNTRY_COLOMBIA: [ 131 | 'Bogota', 'Medellin', 'Cali', 'Barranquilla', 'Cartagena' 132 | ], 133 | COUNTRY_VENEZUELA: [ 134 | 'Isla Raton', 'La Esmeralda', 'Maroa', 'Puerto Ayacucho', 'San Carlos de Rio Negro', 135 | ], 136 | COUNTRY_BRAZIL: [ 137 | 'Sao Paulo', 'Rio de Janeiro', 'Salvador', 'Fortaleza', 'Belo Horizonte' 138 | ], 139 | COUNTRY_CHILE: [ 140 | 'Puente Alto', 'Maipu', 'La Florida', 'Las Condes', 'San Bernardo' 141 | ], 142 | COUNTRY_URUGUAY: [ 143 | 'Montevideo', 'Salto', 'Ciudad de la Costa', 'Paysandu', 'Las Piedras', 'Rivera', 'Maldonado' 144 | ], 145 | COUNTRY_ARGENTINA: [ 146 | 'Buenos Aires', 'Cordoba', 'Rosario', 'Mendoza', 'La Plata' 147 | ], 148 | 149 | # Europe 150 | COUNTRY_SLOVAKIA: [ 151 | 'Bratislava', 'Kosice', 'Trebisov', 'Poprad', 'Zilina', 'Puchov', 'Banska Bystrica', 'Presov' 152 | ], 153 | COUNTRY_SPAIN: [ 154 | 'Madrid', 'Barcelona', 'Valencia', 'Seville', 'Zaragoza', 'Malaga', 'Murcia' 155 | ], 156 | COUNTRY_BULGARIA: [ 157 | 'Sofia', 'Plovdiv', 'Varna', 'Burgas', 'Ruse', 'Stara Zagora', 'Pleven', 'Sliven' 158 | ], 159 | COUNTRY_PORTUGAL: [ 160 | 'Lisbon', 'Porto', 'Vila Nova de Gaia', 'Amadora', 'Braga', 'Agualva-Cacem', 'Funchal' 161 | ], 162 | COUNTRY_ITALY: [ 163 | 'Rome', 'Milan', 'Naples', 'Turin', 'Palermo', 'Genoa', 'Bologna', 'Florence', 'Bari', 'Catania', 'Venice' 164 | ], 165 | COUNTRY_UNITED_KINGDOM: [ 166 | 'London', 'Wells', 'Ripon', 'Truro', 'Ely', 'Chichester', 'Worcester', 'Oxford' 167 | ], 168 | 169 | # Asia 170 | COUNTRY_CHINA: [ 171 | 'Beijing', 'Shanghai', 'Hong Kong', 'Jinjiang', 'Xiamen', 'Sihui' 172 | ], 173 | COUNTRY_RUSSIA: [ 174 | 'Moscow', 'Saint Petersburg', 'Novosibirsk', 'Yekaterinburg', 'Nizhny Novgorod', 'Samara', 'Omsk', 'Kazan' 175 | ], 176 | COUNTRY_JAPAN: [ 177 | 'Tokyo', 'Aichi', 'Akita', 'Chiba', 'Fukui', 'Fukushima', 'Hokkaido', 'Ishikawa', 'Kyoto', 'Osaka' 178 | ], 179 | COUNTRY_INDIA: [ 180 | 'Mumbai', 'Delhi', 'Bangalore', 'Hyderabad', 'Ahmedabad', 'Chennai', 'Kolkata', 'Jaipur' 181 | ], 182 | 183 | # Africa 184 | COUNTRY_ALGERIA: [ 185 | 'Alger', 'Oran', 'Constantine', 'Annaba', 'Blida', 'Batna', 'Djelfa' 186 | ], 187 | COUNTRY_EGYPT: [ 188 | 'Cairo', 'Alexandria', 'Giza', 'Shubra El-Kheima', 'Port Said', 'Suez', 'Luxor' 189 | ], 190 | COUNTRY_SUDAN: [ 191 | 'Omdurman', 'Khartoum', 'Khartoum Bahri', 'Nyala', 'Port Sudan', 'Kassala', 'Ubayyid', 'Kosti', 'Wad Madani' 192 | ], 193 | COUNTRY_ETHIOPIA: [ 194 | 'Addis Ababa', 'Dire Dawa', 'Mek\'ele', 'Adama', 'Gondar', 'Awasa', 'Bahir Dar', 'Jimma', 'Dessie' 195 | ], 196 | COUNTRY_SOMALIA: [ 197 | 'Mogadishu', 'Hargeisa', 'Bosaso', 'Galkayo', 'Berbera', 'Merca' 198 | ], 199 | COUNTRY_MADAGASCAR: [ 200 | 'Antananarivo', 'Toamasina', 'Antsirabe', 'Fianarantsoa', 'Mahajanga', 'Toliara', 'Antsiranana' 201 | ], 202 | 203 | # Australia 204 | COUNTRY_WESTERN_AUSTRALIA: [ 205 | 'Perth', 'Bunbury' 206 | ], 207 | COUNTRY_NORTHERN_TERRITORY: [ 208 | 'Darwin', 'Toowoomba' 209 | ], 210 | COUNTRY_SOUTH_AUSTRALIA: [ 211 | 'Adelaide' 212 | ], 213 | COUNTRY_QUEENSLAND: [ 214 | 'Brisbane', 'Gold Coast-Tweed', 'Sunshine Coast', 'Townsville', 'Cairns' 215 | ], 216 | COUNTRY_NEW_SOUTH_WALES: [ 217 | 'Sydney', 'Newcastle-Maitland', 'Wollongong', 'Albury-Wodonga' 218 | ], 219 | COUNTRY_VICTORIA: [ 220 | 'Melbourne', 'Geelong', 'Ballarat', 'Bendigo', 'Shepparton-Mooroopna' 221 | ], 222 | COUNTRY_AUSTRALIAN_CAPITAL_TERRITORY: [ 223 | 'Canberra-Queanbeyan', 224 | ], 225 | COUNTRY_TASMANIA: [ 226 | 'Hobart', 'Launceston' 227 | ], 228 | 229 | # Antarctica 230 | COUNTRY_SOUTH_ORKNEY_ISLANDS: [ 231 | 232 | ], 233 | COUNTRY_GRAHAM_LAND: [ 234 | 235 | ], 236 | COUNTRY_MARIE_BYRD_LAND: [ 237 | 238 | ], 239 | COUNTRY_QEEN_MAUD_LAND: [ 240 | 241 | ], 242 | COUNTRY_VICTORIA_LAND: [ 243 | 244 | ], 245 | COUNTRY_WILKES_LAND: [ 246 | 247 | ], 248 | } 249 | -------------------------------------------------------------------------------- /example/example/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | 5 | class CarBrand(models.Model): 6 | title = models.CharField(_('title'), max_length=128, unique=True) 7 | created = models.DateTimeField(_('created'), auto_now_add=True) 8 | modified = models.DateTimeField(_('modified'), auto_now=True) 9 | 10 | def __str__(self): 11 | return self.title 12 | 13 | class Meta: 14 | db_table = 'example_car_brands' 15 | verbose_name = _('car brand') 16 | verbose_name_plural = _('car brands') 17 | ordering = ['title', ] 18 | 19 | 20 | class BrandModel(models.Model): 21 | brand = models.ForeignKey(CarBrand, verbose_name=_('car brand')) 22 | title = models.CharField(_('title'), max_length=128) 23 | created = models.DateTimeField(_('created'), auto_now_add=True) 24 | modified = models.DateTimeField(_('modified'), auto_now=True) 25 | 26 | def __str__(self): 27 | return self.title 28 | 29 | class Meta: 30 | db_table = 'example_brand_models' 31 | verbose_name = _('brand model') 32 | verbose_name_plural = _('brand models') 33 | unique_together = (('brand', 'title'),) 34 | ordering = ['brand', 'title', ] 35 | 36 | 37 | class Car(models.Model): 38 | ENGINES = [ 39 | ('DIESEL', _('Diesel')), 40 | ('GASOLINE', _('Gasoline')) 41 | ] 42 | COLORS = [ 43 | ('RED', _('red')), 44 | ('GREEN', _('green')), 45 | ('BLUE', _('blue')), 46 | ('WHITE', _('white')), 47 | ('BLACK', _('black')), 48 | ('YELLOW', _('yellow')), 49 | ('SILVER', _('silver')), 50 | ('PINK', _('pink')) 51 | ] 52 | 53 | model = models.ForeignKey(BrandModel, verbose_name=_('car brand model')) 54 | engine = models.CharField(choices=ENGINES, max_length=8) 55 | color = models.CharField(choices=COLORS, max_length=8, blank=True, null=True, default=None) 56 | numberplate = models.CharField(max_length=16, unique=True) 57 | created = models.DateTimeField(_('created'), auto_now_add=True) 58 | modified = models.DateTimeField(_('modified'), auto_now=True) 59 | 60 | def __str__(self): 61 | return '%(brand)s %(model)s' % { 62 | 'brand': self.brand, 63 | 'model': self.model, 64 | } 65 | 66 | @property 67 | def brand(self): 68 | return self.model.brand 69 | 70 | class Meta: 71 | db_table = 'example_cars' 72 | verbose_name = _('car') 73 | verbose_name_plural = _('cars') 74 | ordering = ['model__brand', 'model', 'numberplate'] 75 | -------------------------------------------------------------------------------- /example/example/settings.py: -------------------------------------------------------------------------------- 1 | # Django settings for example project. 2 | 3 | DEBUG = True 4 | TEMPLATE_DEBUG = DEBUG 5 | 6 | ADMINS = ( 7 | # ('Your Name', 'your_email@example.com'), 8 | ) 9 | 10 | MANAGERS = ADMINS 11 | 12 | DATABASES = { 13 | 'default': { 14 | 'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 15 | 'NAME': 'example', # Or path to database file if using sqlite3. 16 | 'USER': 'example', # Not used with sqlite3. 17 | 'PASSWORD': 'example', # Not used with sqlite3. 18 | 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 19 | 'PORT': '', # Set to empty string for default. Not used with sqlite3. 20 | } 21 | } 22 | 23 | # Hosts/domain names that are valid for this site; required if DEBUG is False 24 | # See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts 25 | ALLOWED_HOSTS = [] 26 | 27 | # Local time zone for this installation. Choices can be found here: 28 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 29 | # although not all choices may be available on all operating systems. 30 | # In a Windows environment this must be set to your system time zone. 31 | TIME_ZONE = 'America/Chicago' 32 | 33 | # Language code for this installation. All choices can be found here: 34 | # http://www.i18nguy.com/unicode/language-identifiers.html 35 | LANGUAGE_CODE = 'en-us' 36 | 37 | SITE_ID = 1 38 | 39 | # If you set this to False, Django will make some optimizations so as not 40 | # to load the internationalization machinery. 41 | USE_I18N = True 42 | 43 | # If you set this to False, Django will not format dates, numbers and 44 | # calendars according to the current locale. 45 | USE_L10N = True 46 | 47 | # If you set this to False, Django will not use timezone-aware datetimes. 48 | USE_TZ = True 49 | 50 | # Absolute filesystem path to the directory that will hold user-uploaded files. 51 | # Example: "/home/media/media.lawrence.com/media/" 52 | MEDIA_ROOT = '' 53 | 54 | # URL that handles the media served from MEDIA_ROOT. Make sure to use a 55 | # trailing slash. 56 | # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" 57 | MEDIA_URL = '' 58 | 59 | # Absolute path to the directory static files should be collected to. 60 | # Don't put anything in this directory yourself; store your static files 61 | # in apps' "static/" subdirectories and in STATICFILES_DIRS. 62 | # Example: "/home/media/media.lawrence.com/static/" 63 | STATIC_ROOT = '' 64 | 65 | # URL prefix for static files. 66 | # Example: "http://media.lawrence.com/static/" 67 | STATIC_URL = '/static/' 68 | 69 | # Additional locations of static files 70 | STATICFILES_DIRS = ( 71 | # Put strings here, like "/home/html/static" or "C:/www/django/static". 72 | # Always use forward slashes, even on Windows. 73 | # Don't forget to use absolute paths, not relative paths. 74 | ) 75 | 76 | # List of finder classes that know how to find static files in 77 | # various locations. 78 | STATICFILES_FINDERS = ( 79 | 'django.contrib.staticfiles.finders.FileSystemFinder', 80 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 81 | # 'django.contrib.staticfiles.finders.DefaultStorageFinder', 82 | ) 83 | 84 | # Make this unique, and don't share it with anybody. 85 | SECRET_KEY = '3(q1o$0-wpnrx7i789c5j$5*#-rc50m^x3n!jia_cl7_k=v1(c' 86 | 87 | # List of callables that know how to import templates from various sources. 88 | TEMPLATE_LOADERS = ( 89 | 'django.template.loaders.filesystem.Loader', 90 | 'django.template.loaders.app_directories.Loader', 91 | # 'django.template.loaders.eggs.Loader', 92 | ) 93 | 94 | MIDDLEWARE_CLASSES = ( 95 | 'django.middleware.common.CommonMiddleware', 96 | 'django.contrib.sessions.middleware.SessionMiddleware', 97 | 'django.middleware.csrf.CsrfViewMiddleware', 98 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 99 | 'django.contrib.messages.middleware.MessageMiddleware', 100 | # Uncomment the next line for simple clickjacking protection: 101 | # 'django.middleware.clickjacking.XFrameOptionsMiddleware', 102 | ) 103 | 104 | 105 | ROOT_URLCONF = 'example.urls' 106 | 107 | # Python dotted path to the WSGI application used by Django's runserver. 108 | WSGI_APPLICATION = 'example.wsgi.application' 109 | 110 | TEMPLATE_DIRS = ( 111 | # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 112 | # Always use forward slashes, even on Windows. 113 | # Don't forget to use absolute paths, not relative paths. 114 | ) 115 | 116 | INSTALLED_APPS = ( 117 | 'django.contrib.auth', 118 | 'django.contrib.contenttypes', 119 | 'django.contrib.sessions', 120 | 'django.contrib.sites', 121 | 'django.contrib.messages', 122 | 'django.contrib.staticfiles', 123 | # Uncomment the next line to enable the admin: 124 | 'django.contrib.admin', 125 | # Uncomment the next line to enable admin documentation: 126 | 'django.contrib.admindocs', 127 | 128 | 'clever_selects', 129 | 130 | 'example' 131 | ) 132 | 133 | # A sample logging configuration. The only tangible logging 134 | # performed by this configuration is to send an email to 135 | # the site admins on every HTTP 500 error when DEBUG=False. 136 | # See http://docs.djangoproject.com/en/dev/topics/logging for 137 | # more details on how to customize your logging configuration. 138 | LOGGING = { 139 | 'version': 1, 140 | 'disable_existing_loggers': False, 141 | 'filters': { 142 | 'require_debug_false': { 143 | '()': 'django.utils.log.RequireDebugFalse' 144 | } 145 | }, 146 | 'handlers': { 147 | 'mail_admins': { 148 | 'level': 'ERROR', 149 | 'filters': ['require_debug_false'], 150 | 'class': 'django.utils.log.AdminEmailHandler' 151 | } 152 | }, 153 | 'loggers': { 154 | 'django.request': { 155 | 'handlers': ['mail_admins'], 156 | 'level': 'ERROR', 157 | 'propagate': True, 158 | }, 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /example/example/static/js/jquery-1.10.2.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license 2 | //@ sourceMappingURL=jquery-1.10.2.min.map 3 | */ 4 | (function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.2",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("onload",q))};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,n,r){var i,o;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof x?n[0]:n,x.merge(this,x.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:a,!0)),k.test(i[1])&&x.isPlainObject(n))for(i in n)x.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(o=a.getElementById(i[2]),o&&o.parentNode){if(o.id!==i[2])return r.find(e);this.length=1,this[0]=o}return this.context=a,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return g.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(g.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},l=2),"object"==typeof s||x.isFunction(s)||(s={}),u===l&&(s=this,--l);u>l;l++)if(null!=(o=arguments[l]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(x.isPlainObject(r)||(n=x.isArray(r)))?(n?(n=!1,a=e&&x.isArray(e)?e:[]):a=e&&x.isPlainObject(e)?e:{},s[i]=x.extend(c,a,r)):r!==t&&(s[i]=r));return s},x.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=l),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){if(e===!0?!--x.readyWait:!x.isReady){if(!a.body)return setTimeout(x.ready);x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(a,[x]),x.fn.trigger&&x(a).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray||function(e){return"array"===x.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?c[y.call(e)]||"object":typeof e},isPlainObject:function(e){var n;if(!e||"object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!v.call(e,"constructor")&&!v.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(r){return!1}if(x.support.ownLast)for(n in e)return v.call(e,n);for(n in e);return n===t||v.call(e,n)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||a;var r=k.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=x.trim(n),n&&E.test(n.replace(A,"@").replace(j,"]").replace(S,"")))?Function("return "+n)():(x.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||x.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&x.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(D,"ms-").replace(L,H)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:b&&!b.call("\ufeff\u00a0")?function(e){return null==e?"":b.call(e)}:function(e){return null==e?"":(e+"").replace(C,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(m)return m.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return d.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),x.isFunction(e)?(r=g.call(arguments,2),i=function(){return e.apply(n||this,r.concat(g.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):t},access:function(e,n,r,i,o,a,s){var l=0,u=e.length,c=null==r;if("object"===x.type(r)){o=!0;for(l in r)x.access(e,n,l,r[l],!0,a,s)}else if(i!==t&&(o=!0,x.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(x(e),n)})),n))for(;u>l;l++)n(e[l],r,s?i:i.call(e[l],l,n(e[l],r)));return o?e:c?n.call(e):u?n(e[0],r):a},now:function(){return(new Date).getTime()},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),x.ready.promise=function(t){if(!n)if(n=x.Deferred(),"complete"===a.readyState)setTimeout(x.ready);else if(a.addEventListener)a.addEventListener("DOMContentLoaded",q,!1),e.addEventListener("load",q,!1);else{a.attachEvent("onreadystatechange",q),e.attachEvent("onload",q);var r=!1;try{r=null==e.frameElement&&a.documentElement}catch(i){}r&&r.doScroll&&function o(){if(!x.isReady){try{r.doScroll("left")}catch(e){return setTimeout(o,50)}_(),x.ready()}}()}return n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){c["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=x(a),function(e,t){var n,r,i,o,a,s,l,u,c,p,f,d,h,g,m,y,v,b="sizzle"+-new Date,w=e.document,T=0,C=0,N=st(),k=st(),E=st(),S=!1,A=function(e,t){return e===t?(S=!0,0):0},j=typeof t,D=1<<31,L={}.hasOwnProperty,H=[],q=H.pop,_=H.push,M=H.push,O=H.slice,F=H.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},B="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",P="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",W=R.replace("w","w#"),$="\\["+P+"*("+R+")"+P+"*(?:([*^$|!~]?=)"+P+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+W+")|)|)"+P+"*\\]",I=":("+R+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+$.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+P+"+|((?:^|[^\\\\])(?:\\\\.)*)"+P+"+$","g"),X=RegExp("^"+P+"*,"+P+"*"),U=RegExp("^"+P+"*([>+~]|"+P+")"+P+"*"),V=RegExp(P+"*[+~]"),Y=RegExp("="+P+"*([^\\]'\"]*)"+P+"*\\]","g"),J=RegExp(I),G=RegExp("^"+W+"$"),Q={ID:RegExp("^#("+R+")"),CLASS:RegExp("^\\.("+R+")"),TAG:RegExp("^("+R.replace("w","w*")+")"),ATTR:RegExp("^"+$),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+P+"*(even|odd|(([+-]|)(\\d*)n|)"+P+"*(?:([+-]|)"+P+"*(\\d+)|))"+P+"*\\)|)","i"),bool:RegExp("^(?:"+B+")$","i"),needsContext:RegExp("^"+P+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+P+"*((?:-\\d)?\\d*)"+P+"*\\)|)(?=[^-]|$)","i")},K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,et=/^(?:input|select|textarea|button)$/i,tt=/^h\d$/i,nt=/'|\\/g,rt=RegExp("\\\\([\\da-f]{1,6}"+P+"?|("+P+")|.)","ig"),it=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{M.apply(H=O.call(w.childNodes),w.childNodes),H[w.childNodes.length].nodeType}catch(ot){M={apply:H.length?function(e,t){_.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function at(e,t,n,i){var o,a,s,l,u,c,d,m,y,x;if((t?t.ownerDocument||t:w)!==f&&p(t),t=t||f,n=n||[],!e||"string"!=typeof e)return n;if(1!==(l=t.nodeType)&&9!==l)return[];if(h&&!i){if(o=Z.exec(e))if(s=o[1]){if(9===l){if(a=t.getElementById(s),!a||!a.parentNode)return n;if(a.id===s)return n.push(a),n}else if(t.ownerDocument&&(a=t.ownerDocument.getElementById(s))&&v(t,a)&&a.id===s)return n.push(a),n}else{if(o[2])return M.apply(n,t.getElementsByTagName(e)),n;if((s=o[3])&&r.getElementsByClassName&&t.getElementsByClassName)return M.apply(n,t.getElementsByClassName(s)),n}if(r.qsa&&(!g||!g.test(e))){if(m=d=b,y=t,x=9===l&&e,1===l&&"object"!==t.nodeName.toLowerCase()){c=mt(e),(d=t.getAttribute("id"))?m=d.replace(nt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",u=c.length;while(u--)c[u]=m+yt(c[u]);y=V.test(e)&&t.parentNode||t,x=c.join(",")}if(x)try{return M.apply(n,y.querySelectorAll(x)),n}catch(T){}finally{d||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,n,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>o.cacheLength&&delete t[e.shift()],t[n]=r}return t}function lt(e){return e[b]=!0,e}function ut(e){var t=f.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function ct(e,t){var n=e.split("|"),r=e.length;while(r--)o.attrHandle[n[r]]=t}function pt(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function dt(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return lt(function(t){return t=+t,lt(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}s=at.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},r=at.support={},p=at.setDocument=function(e){var n=e?e.ownerDocument||e:w,i=n.defaultView;return n!==f&&9===n.nodeType&&n.documentElement?(f=n,d=n.documentElement,h=!s(n),i&&i.attachEvent&&i!==i.top&&i.attachEvent("onbeforeunload",function(){p()}),r.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),r.getElementsByTagName=ut(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),r.getElementsByClassName=ut(function(e){return e.innerHTML="
",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),r.getById=ut(function(e){return d.appendChild(e).id=b,!n.getElementsByName||!n.getElementsByName(b).length}),r.getById?(o.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){return e.getAttribute("id")===t}}):(delete o.find.ID,o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),o.find.TAG=r.getElementsByTagName?function(e,n){return typeof n.getElementsByTagName!==j?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},o.find.CLASS=r.getElementsByClassName&&function(e,n){return typeof n.getElementsByClassName!==j&&h?n.getElementsByClassName(e):t},m=[],g=[],(r.qsa=K.test(n.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||g.push("\\["+P+"*(?:value|"+B+")"),e.querySelectorAll(":checked").length||g.push(":checked")}),ut(function(e){var t=n.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&g.push("[*^$]="+P+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||g.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),g.push(",.*:")})),(r.matchesSelector=K.test(y=d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.msMatchesSelector))&&ut(function(e){r.disconnectedMatch=y.call(e,"div"),y.call(e,"[s!='']:x"),m.push("!=",I)}),g=g.length&&RegExp(g.join("|")),m=m.length&&RegExp(m.join("|")),v=K.test(d.contains)||d.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},A=d.compareDocumentPosition?function(e,t){if(e===t)return S=!0,0;var i=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t);return i?1&i||!r.sortDetached&&t.compareDocumentPosition(e)===i?e===n||v(w,e)?-1:t===n||v(w,t)?1:c?F.call(c,e)-F.call(c,t):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return S=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:c?F.call(c,e)-F.call(c,t):0;if(o===a)return pt(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?pt(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},n):f},at.matches=function(e,t){return at(e,null,null,t)},at.matchesSelector=function(e,t){if((e.ownerDocument||e)!==f&&p(e),t=t.replace(Y,"='$1']"),!(!r.matchesSelector||!h||m&&m.test(t)||g&&g.test(t)))try{var n=y.call(e,t);if(n||r.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(i){}return at(t,f,null,[e]).length>0},at.contains=function(e,t){return(e.ownerDocument||e)!==f&&p(e),v(e,t)},at.attr=function(e,n){(e.ownerDocument||e)!==f&&p(e);var i=o.attrHandle[n.toLowerCase()],a=i&&L.call(o.attrHandle,n.toLowerCase())?i(e,n,!h):t;return a===t?r.attributes||!h?e.getAttribute(n):(a=e.getAttributeNode(n))&&a.specified?a.value:null:a},at.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},at.uniqueSort=function(e){var t,n=[],i=0,o=0;if(S=!r.detectDuplicates,c=!r.sortStable&&e.slice(0),e.sort(A),S){while(t=e[o++])t===e[o]&&(i=n.push(o));while(i--)e.splice(n[i],1)}return e},a=at.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=a(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=a(t);return n},o=at.selectors={cacheLength:50,createPseudo:lt,match:Q,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(rt,it),e[3]=(e[4]||e[5]||"").replace(rt,it),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||at.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&at.error(e[0]),e},PSEUDO:function(e){var n,r=!e[5]&&e[2];return Q.CHILD.test(e[0])?null:(e[3]&&e[4]!==t?e[2]=e[4]:r&&J.test(r)&&(n=mt(r,!0))&&(n=r.indexOf(")",r.length-n)-r.length)&&(e[0]=e[0].slice(0,n),e[2]=r.slice(0,n)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(rt,it).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=N[e+" "];return t||(t=RegExp("(^|"+P+")"+e+"("+P+"|$)"))&&N(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=at.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[b]||(m[b]={}),u=c[e]||[],d=u[0]===T&&u[1],f=u[0]===T&&u[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[T,d,f];break}}else if(v&&(u=(t[b]||(t[b]={}))[e])&&u[0]===T)f=u[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[b]||(p[b]={}))[e]=[T,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=o.pseudos[e]||o.setFilters[e.toLowerCase()]||at.error("unsupported pseudo: "+e);return r[b]?r(t):r.length>1?(n=[e,e,"",t],o.setFilters.hasOwnProperty(e.toLowerCase())?lt(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=F.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:lt(function(e){var t=[],n=[],r=l(e.replace(z,"$1"));return r[b]?lt(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:lt(function(e){return function(t){return at(e,t).length>0}}),contains:lt(function(e){return function(t){return(t.textContent||t.innerText||a(t)).indexOf(e)>-1}}),lang:lt(function(e){return G.test(e||"")||at.error("unsupported lang: "+e),e=e.replace(rt,it).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===d},focus:function(e){return e===f.activeElement&&(!f.hasFocus||f.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!o.pseudos.empty(e)},header:function(e){return tt.test(e.nodeName)},input:function(e){return et.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},o.pseudos.nth=o.pseudos.eq;for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})o.pseudos[n]=ft(n);for(n in{submit:!0,reset:!0})o.pseudos[n]=dt(n);function gt(){}gt.prototype=o.filters=o.pseudos,o.setFilters=new gt;function mt(e,t){var n,r,i,a,s,l,u,c=k[e+" "];if(c)return t?0:c.slice(0);s=e,l=[],u=o.preFilter;while(s){(!n||(r=X.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),l.push(i=[])),n=!1,(r=U.exec(s))&&(n=r.shift(),i.push({value:n,type:r[0].replace(z," ")}),s=s.slice(n.length));for(a in o.filter)!(r=Q[a].exec(s))||u[a]&&!(r=u[a](r))||(n=r.shift(),i.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?at.error(e):k(e,l).slice(0)}function yt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function vt(e,t,n){var r=t.dir,o=n&&"parentNode"===r,a=C++;return t.first?function(t,n,i){while(t=t[r])if(1===t.nodeType||o)return e(t,n,i)}:function(t,n,s){var l,u,c,p=T+" "+a;if(s){while(t=t[r])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[r])if(1===t.nodeType||o)if(c=t[b]||(t[b]={}),(u=c[r])&&u[0]===p){if((l=u[1])===!0||l===i)return l===!0}else if(u=c[r]=[p],u[1]=e(t,n,s)||i,u[1]===!0)return!0}}function bt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,a=[],s=0,l=e.length,u=null!=t;for(;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function wt(e,t,n,r,i,o){return r&&!r[b]&&(r=wt(r)),i&&!i[b]&&(i=wt(i,o)),lt(function(o,a,s,l){var u,c,p,f=[],d=[],h=a.length,g=o||Nt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:xt(g,f,e,s,l),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,l),r){u=xt(y,d),r(u,[],s,l),c=u.length;while(c--)(p=u[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){u=[],c=y.length;while(c--)(p=y[c])&&u.push(m[c]=p);i(null,y=[],u,l)}c=y.length;while(c--)(p=y[c])&&(u=i?F.call(o,p):f[c])>-1&&(o[u]=!(a[u]=p))}}else y=xt(y===a?y.splice(h,y.length):y),i?i(null,a,y,l):M.apply(a,y)})}function Tt(e){var t,n,r,i=e.length,a=o.relative[e[0].type],s=a||o.relative[" "],l=a?1:0,c=vt(function(e){return e===t},s,!0),p=vt(function(e){return F.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;i>l;l++)if(n=o.relative[e[l].type])f=[vt(bt(f),n)];else{if(n=o.filter[e[l].type].apply(null,e[l].matches),n[b]){for(r=++l;i>r;r++)if(o.relative[e[r].type])break;return wt(l>1&&bt(f),l>1&&yt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&Tt(e.slice(l,r)),i>r&&Tt(e=e.slice(r)),i>r&&yt(e))}f.push(n)}return bt(f)}function Ct(e,t){var n=0,r=t.length>0,a=e.length>0,s=function(s,l,c,p,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,C=u,N=s||a&&o.find.TAG("*",d&&l.parentNode||l),k=T+=null==C?1:Math.random()||.1;for(w&&(u=l!==f&&l,i=n);null!=(h=N[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,l,c)){p.push(h);break}w&&(T=k,i=++n)}r&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,r&&b!==v){g=0;while(m=t[g++])m(x,y,l,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=q.call(p));y=xt(y)}M.apply(p,y),w&&!s&&y.length>0&&v+t.length>1&&at.uniqueSort(p)}return w&&(T=k,u=C),x};return r?lt(s):s}l=at.compile=function(e,t){var n,r=[],i=[],o=E[e+" "];if(!o){t||(t=mt(e)),n=t.length;while(n--)o=Tt(t[n]),o[b]?r.push(o):i.push(o);o=E(e,Ct(i,r))}return o};function Nt(e,t,n){var r=0,i=t.length;for(;i>r;r++)at(e,t[r],n);return n}function kt(e,t,n,i){var a,s,u,c,p,f=mt(e);if(!i&&1===f.length){if(s=f[0]=f[0].slice(0),s.length>2&&"ID"===(u=s[0]).type&&r.getById&&9===t.nodeType&&h&&o.relative[s[1].type]){if(t=(o.find.ID(u.matches[0].replace(rt,it),t)||[])[0],!t)return n;e=e.slice(s.shift().value.length)}a=Q.needsContext.test(e)?0:s.length;while(a--){if(u=s[a],o.relative[c=u.type])break;if((p=o.find[c])&&(i=p(u.matches[0].replace(rt,it),V.test(s[0].type)&&t.parentNode||t))){if(s.splice(a,1),e=i.length&&yt(s),!e)return M.apply(n,i),n;break}}}return l(e,f)(i,t,!h,n,V.test(e)),n}r.sortStable=b.split("").sort(A).join("")===b,r.detectDuplicates=S,p(),r.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(f.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||ct("type|href|height|width",function(e,n,r){return r?t:e.getAttribute(n,"type"===n.toLowerCase()?1:2)}),r.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||ct("value",function(e,n,r){return r||"input"!==e.nodeName.toLowerCase()?t:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||ct(B,function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&i.specified?i.value:e[n]===!0?n.toLowerCase():null}),x.find=at,x.expr=at.selectors,x.expr[":"]=x.expr.pseudos,x.unique=at.uniqueSort,x.text=at.getText,x.isXMLDoc=at.isXML,x.contains=at.contains}(e);var O={};function F(e){var t=O[e]={};return x.each(e.match(T)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?O[e]||F(e):x.extend({},e);var n,r,i,o,a,s,l=[],u=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=l.length,n=!0;l&&o>a;a++)if(l[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,l&&(u?u.length&&c(u.shift()):r?l=[]:p.disable())},p={add:function(){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this},remove:function(){return l&&x.each(arguments,function(e,t){var r;while((r=x.inArray(t,l,r))>-1)l.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?x.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=r=t,this},disabled:function(){return!l},lock:function(){return u=t,r||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!l||i&&!u||(t=t||[],t=[e,t.slice?t.slice():t],n?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var a=o[0],s=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=g.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?g.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,l,u;if(r>1)for(s=Array(r),l=Array(r),u=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(a(t,u,n)).fail(o.reject).progress(a(t,l,s)):--i;return i||o.resolveWith(u,n),o.promise()}}),x.support=function(t){var n,r,o,s,l,u,c,p,f,d=a.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="
",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="
t |
",o=d.getElementsByTagName("td"),o[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===o[0].offsetHeight,o[0].style.display="",o[1].style.display="none",t.reliableHiddenOffsets=p&&0===o[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",x.swap(l,null!=l.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===d.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(a.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(l.style.zoom=1)),l.removeChild(n),n=d=o=r=null)}),n=s=l=u=r=o=null,t 5 | }({});var B=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;function R(e,n,r,i){if(x.acceptData(e)){var o,a,s=x.expando,l=e.nodeType,u=l?x.cache:e,c=l?e[s]:e[s]&&s;if(c&&u[c]&&(i||u[c].data)||r!==t||"string"!=typeof n)return c||(c=l?e[s]=p.pop()||x.guid++:s),u[c]||(u[c]=l?{}:{toJSON:x.noop}),("object"==typeof n||"function"==typeof n)&&(i?u[c]=x.extend(u[c],n):u[c].data=x.extend(u[c].data,n)),a=u[c],i||(a.data||(a.data={}),a=a.data),r!==t&&(a[x.camelCase(n)]=r),"string"==typeof n?(o=a[n],null==o&&(o=a[x.camelCase(n)])):o=a,o}}function W(e,t,n){if(x.acceptData(e)){var r,i,o=e.nodeType,a=o?x.cache:e,s=o?e[x.expando]:x.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){x.isArray(t)?t=t.concat(x.map(t,x.camelCase)):t in r?t=[t]:(t=x.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;while(i--)delete r[t[i]];if(n?!I(r):!x.isEmptyObject(r))return}(n||(delete a[s].data,I(a[s])))&&(o?x.cleanData([e],!0):x.support.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}x.extend({cache:{},noData:{applet:!0,embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(e){return e=e.nodeType?x.cache[e[x.expando]]:e[x.expando],!!e&&!I(e)},data:function(e,t,n){return R(e,t,n)},removeData:function(e,t){return W(e,t)},_data:function(e,t,n){return R(e,t,n,!0)},_removeData:function(e,t){return W(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&x.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),x.fn.extend({data:function(e,n){var r,i,o=null,a=0,s=this[0];if(e===t){if(this.length&&(o=x.data(s),1===s.nodeType&&!x._data(s,"parsedAttrs"))){for(r=s.attributes;r.length>a;a++)i=r[a].name,0===i.indexOf("data-")&&(i=x.camelCase(i.slice(5)),$(s,i,o[i]));x._data(s,"parsedAttrs",!0)}return o}return"object"==typeof e?this.each(function(){x.data(this,e)}):arguments.length>1?this.each(function(){x.data(this,e,n)}):s?$(s,e,x.data(s,e)):null},removeData:function(e){return this.each(function(){x.removeData(this,e)})}});function $(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(P,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:B.test(r)?x.parseJSON(r):r}catch(o){}x.data(e,n,r)}else r=t}return r}function I(e){var t;for(t in e)if(("data"!==t||!x.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}x.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=x._data(e,n),r&&(!i||x.isArray(r)?i=x._data(e,n,x.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),a=function(){x.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return x._data(e,n)||x._data(e,n,{empty:x.Callbacks("once memory").add(function(){x._removeData(e,t+"queue"),x._removeData(e,n)})})}}),x.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?x.queue(this[0],e):n===t?this:this.each(function(){var t=x.queue(this,e,n);x._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=x.Deferred(),a=this,s=this.length,l=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=x._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(l));return l(),o.promise(n)}});var z,X,U=/[\t\r\n\f]/g,V=/\r/g,Y=/^(?:input|select|textarea|button|object)$/i,J=/^(?:a|area)$/i,G=/^(?:checked|selected)$/i,Q=x.support.getSetAttribute,K=x.support.input;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return e=x.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,l="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,l=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,r=0,o=x(this),a=e.match(T)||[];while(t=a[r++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===i||"boolean"===n)&&(this.className&&x._data(this,"__className__",this.className),this.className=this.className||e===!1?"":x._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(U," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=x.isFunction(e),this.each(function(n){var o;1===this.nodeType&&(o=i?e.call(this,n,x(this).val()):e,null==o?o="":"number"==typeof o?o+="":x.isArray(o)&&(o=x.map(o,function(e){return null==e?"":e+""})),r=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=x.valHooks[o.type]||x.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(V,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=x.find.attr(e,"value");return null!=t?t:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;for(;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),a=i.length;while(a--)r=i[a],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,n,r){var o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===i?x.prop(e,n,r):(1===s&&x.isXMLDoc(e)||(n=n.toLowerCase(),o=x.attrHooks[n]||(x.expr.match.bool.test(n)?X:z)),r===t?o&&"get"in o&&null!==(a=o.get(e,n))?a:(a=x.find.attr(e,n),null==a?t:a):null!==r?o&&"set"in o&&(a=o.set(e,r,n))!==t?a:(e.setAttribute(n,r+""),r):(x.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(T);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)?K&&Q||!G.test(n)?e[r]=!1:e[x.camelCase("default-"+n)]=e[r]=!1:x.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!x.isXMLDoc(e),a&&(n=x.propFix[n]||n,o=x.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var t=x.find.attr(e,"tabindex");return t?parseInt(t,10):Y.test(e.nodeName)||J.test(e.nodeName)&&e.href?0:-1}}}}),X={set:function(e,t,n){return t===!1?x.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&x.propFix[n]||n,n):e[x.camelCase("default-"+n)]=e[n]=!0,n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,n){var r=x.expr.attrHandle[n]||x.find.attr;x.expr.attrHandle[n]=K&&Q||!G.test(n)?function(e,n,i){var o=x.expr.attrHandle[n],a=i?t:(x.expr.attrHandle[n]=t)!=r(e,n,i)?n.toLowerCase():null;return x.expr.attrHandle[n]=o,a}:function(e,n,r){return r?t:e[x.camelCase("default-"+n)]?n.toLowerCase():null}}),K&&Q||(x.attrHooks.value={set:function(e,n,r){return x.nodeName(e,"input")?(e.defaultValue=n,t):z&&z.set(e,n,r)}}),Q||(z={set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},x.expr.attrHandle.id=x.expr.attrHandle.name=x.expr.attrHandle.coords=function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&""!==i.value?i.value:null},x.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&r.specified?r.value:t},set:z.set},x.attrHooks.contenteditable={set:function(e,t,n){z.set(e,""===t?!1:t,n)}},x.each(["width","height"],function(e,n){x.attrHooks[n]={set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}}})),x.support.hrefNormalized||x.each(["href","src"],function(e,t){x.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}}),x.support.style||(x.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.support.enctype||(x.propFix.enctype="encoding"),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,n){return x.isArray(n)?e.checked=x.inArray(x(e).val(),n)>=0:t}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}function at(){try{return a.activeElement}catch(e){}}x.event={global:{},add:function(e,n,r,o,a){var s,l,u,c,p,f,d,h,g,m,y,v=x._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=x.guid++),(l=v.events)||(l=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof x===i||e&&x.event.triggered===e.type?t:x.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(T)||[""],u=n.length;while(u--)s=rt.exec(n[u])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),g&&(p=x.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=x.event.special[g]||{},d=x.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&x.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=l[g])||(h=l[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),x.event.global[g]=!0);e=null}},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,f,d,h,g,m=x.hasData(e)&&x._data(e);if(m&&(c=m.events)){t=(t||"").match(T)||[""],u=t.length;while(u--)if(s=rt.exec(t[u])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=x.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),l=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));l&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||x.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)x.event.remove(e,d+t[u],n,r,!0);x.isEmptyObject(c)&&(delete m.handle,x._removeData(e,"events"))}},trigger:function(n,r,i,o){var s,l,u,c,p,f,d,h=[i||a],g=v.call(n,"type")?n.type:n,m=v.call(n,"namespace")?n.namespace.split("."):[];if(u=f=i=i||a,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+x.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),l=0>g.indexOf(":")&&"on"+g,n=n[x.expando]?n:new x.Event(g,"object"==typeof n&&n),n.isTrigger=o?2:3,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:x.makeArray(r,[n]),p=x.event.special[g]||{},o||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!o&&!p.noBubble&&!x.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(u=u.parentNode);u;u=u.parentNode)h.push(u),f=u;f===(i.ownerDocument||a)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((u=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(x._data(u,"events")||{})[n.type]&&x._data(u,"handle"),s&&s.apply(u,r),s=l&&u[l],s&&x.acceptData(u)&&s.apply&&s.apply(u,r)===!1&&n.preventDefault();if(n.type=g,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(h.pop(),r)===!1)&&x.acceptData(i)&&l&&i[g]&&!x.isWindow(i)){f=i[l],f&&(i[l]=null),x.event.triggered=g;try{i[g]()}catch(y){}x.event.triggered=t,f&&(i[l]=f)}return n.result}},dispatch:function(e){e=x.event.fix(e);var n,r,i,o,a,s=[],l=g.call(arguments),u=(x._data(this,"events")||{})[e.type]||[],c=x.event.special[e.type]||{};if(l[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((x.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,l),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],l=n.delegateCount,u=e.target;if(l&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!=this;u=u.parentNode||this)if(1===u.nodeType&&(u.disabled!==!0||"click"!==e.type)){for(o=[],a=0;l>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?x(r,this).index(u)>=0:x.find(r,this,null,[u]).length),o[r]&&o.push(i);o.length&&s.push({elem:u,handlers:o})}return n.length>l&&s.push({elem:this,handlers:n.slice(l)}),s},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,o=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new x.Event(o),t=r.length;while(t--)n=r[t],e[n]=o[n];return e.target||(e.target=o.srcElement||a),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,o):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,o,s=n.button,l=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||a,o=i.documentElement,r=i.body,e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&l&&(e.relatedTarget=l===e.target?n.toElement:l),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==at()&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===at()&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},click:{trigger:function(){return x.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=a.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},x.Event=function(e,n){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&x.extend(this,n),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,t):new x.Event(e,n)},x.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.submitBubbles||(x.event.special.submit={setup:function(){return x.nodeName(this,"form")?!1:(x.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=x.nodeName(n,"input")||x.nodeName(n,"button")?n.form:t;r&&!x._data(r,"submitBubbles")&&(x.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),x._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&x.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return x.nodeName(this,"form")?!1:(x.event.remove(this,"._submit"),t)}}),x.support.changeBubbles||(x.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(x.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),x.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),x.event.simulate("change",this,e,!0)})),!1):(x.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!x._data(t,"changeBubbles")&&(x.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||x.event.simulate("change",this.parentNode,e,!0)}),x._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return x.event.remove(this,"._change"),!Z.test(this.nodeName)}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&a.addEventListener(e,r,!0)},teardown:function(){0===--n&&a.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return x().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=x.guid++)),this.each(function(){x.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,x(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){x.event.remove(this,e,r,n)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?x.event.trigger(e,n,r,!0):t}});var st=/^.[^:#\[\.,]*$/,lt=/^(?:parents|prev(?:Until|All))/,ut=x.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t,n=x(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(x.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e||[],!0))},filter:function(e){return this.pushStack(ft(this,e||[],!1))},is:function(e){return!!ft(this,"string"==typeof e&&ut.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],a=ut.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(a?a.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return x.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(ct[e]||(i=x.unique(i)),lt.test(e)&&(i=i.reverse())),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!x(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(st.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return x.inArray(e,t)>=0!==n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/
\s*$/g,At={option:[1,""],legend:[1,""],area:[1,""],param:[1,""],thead:[1,"{% trans 'Car' %} | 10 |{% trans 'Engine' %} | 11 |{% trans 'Color' %} | 12 |{% trans 'Numberplate' %} | 13 |{% trans 'Actions' %} | 14 |
---|---|---|---|---|
{{ car }} | 20 |{{ car.engine }} | 21 |{{ car.color|default:'' }} | 22 |{{ car.numberplate }} | 23 |{% trans 'Edit' %} | {% trans 'Delete' %} | 24 |