import types from django import forms from django.utils.safestring import mark_safe from django.core.urlresolvers import reverse class JSFunction(str): """ Flags that the string is the name of a JS function. Used by Select2Mixin.render_options() to make sure that this string is not quoted like other strings. """ pass class JSFunctionInContext(str): """ Like JSFunction, this too flags the string as JS function, but with a special requirement. The JS function needs to be invoked in the context of the current Select2 Html DOM, such that 'this' inside the function refers to the source Select2 DOM. """ pass class Select2Mixin(object): # For details on these options refer: http://ivaynberg.github.com/select2/#documentation options = { 'minimumResultsForSearch': 6, # Only applicable for single value select. 'placeholder': '', 'allowClear': True, # Not allowed when field is multiple since there each value has a clear button. 'multiple': False, # Not allowed when attached to