""" Contains all the Django widgets for Select2. """ import logging from itertools import chain from django import forms from django.utils.encoding import force_unicode from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse from django.utils.datastructures import MultiValueDict, MergeDict from .util import render_js_script, convert_to_js_string_arr, JSVar, JSFunction, JSFunctionInContext, \ convert_dict_to_js_map, convert_to_js_arr from . import __RENDER_SELECT2_STATICS as RENDER_SELECT2_STATICS logger = logging.getLogger(__name__) def get_select2_js_path(): from django.conf import settings if settings.configured and settings.DEBUG: return 'js/select2.js' else: return 'js/select2.min.js' ### Light mixin and widgets ### class Select2Mixin(object): """ The base mixin of all Select2 widgets. This mixin is responsible for rendering the necessary Javascript and CSS codes which turns normal `` 'closeOnSelect': False, } """ The options listed in this are rendered as JS map and passed to Select2 JS code. The complete description of theses options are available in Select2_ JS' site. .. _Select2: http://ivaynberg.github.com/select2/#documentation. """ def __init__(self, **kwargs): """ Constructor of the class. The following additional kwarg is allowed:- :param select2_options: This is similar to standard Django way to pass extra attributes to widgets. This is meant to override values of existing :py:attr:`.options`. Example:: class MyForm(ModelForm): class Meta: model = MyModel widgets = { 'name': Select2WidgetName(select2_options={ 'minimumResultsForSearch': 10, 'closeOnSelect': True, }) } .. tip:: You cannot introduce new options using this. For that you should sub-class and overried :py:meth:`.init_options`. The reason for this is, few options are not compatible with each other or are not applicable in some scenarios. For example, when Select2 is attached to ``