Skip to content

Commit

Permalink
Appended 'Mixin' to the base widget and field classes, added a forms …
Browse files Browse the repository at this point in the history
…module so that imports can be done in an analagous manner to the imports from django.forms
  • Loading branch information
fdintino committed Jul 31, 2011
1 parent 0f2bf6e commit 48b69e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions chosen/fields.py
Expand Up @@ -2,7 +2,9 @@

from widgets import ChosenSelect, ChosenSelectMultiple

class ChosenField(object):
__all__ = ['ChosenFieldMixin', 'ChosenChoiceField', 'ChosenMultipleChoiceField']

class ChosenFieldMixin(object):

def __init__(self, *args, **kwargs):
widget_kwargs = {}
Expand All @@ -14,11 +16,11 @@ def __init__(self, *args, **kwargs):
super(ChosenField, self).__init__(*args, **kwargs)


class ChosenChoiceField(ChosenField, forms.ChoiceField):
class ChosenChoiceField(ChosenFieldMixin, forms.ChoiceField):

widget = ChosenSelect

class ChosenMultipleChoiceField(ChosenField, forms.MultipleChoiceField):
class ChosenMultipleChoiceField(ChosenFieldMixin, forms.MultipleChoiceField):

widget = ChosenSelectMultiple

2 changes: 2 additions & 0 deletions chosen/forms.py
@@ -0,0 +1,2 @@
from chosen.fields import *
from chosen.widgets import *
8 changes: 5 additions & 3 deletions chosen/widgets.py
Expand Up @@ -7,7 +7,9 @@
from django.core.urlresolvers import reverse
from django.template.loader import render_to_string

class ChosenWidget(object):
__all__ = ['ChosenWidgetMixin', 'ChosenSelect', 'ChosenSelectMultiple']

class ChosenWidgetMixin(object):

def __init__(self, attrs=None, *args, **kwargs):
if attrs is not None:
Expand Down Expand Up @@ -66,8 +68,8 @@ def get_media(self):
media = property(get_media)


class ChosenSelect(ChosenWidget, forms.Select):
class ChosenSelect(ChosenWidgetMixin, forms.Select):
pass

class ChosenSelectMultiple(ChosenWidget, forms.SelectMultiple):
class ChosenSelectMultiple(ChosenWidgetMixin, forms.SelectMultiple):
pass

0 comments on commit 48b69e5

Please sign in to comment.