From 3390f1e25c76b240e7f00ac2c0b3f4faaf789cfa Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 19 Jul 2012 00:26:24 +0530 Subject: [PATCH] forgot to add app/forms.py --- itf/app/forms.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 itf/app/forms.py diff --git a/itf/app/forms.py b/itf/app/forms.py new file mode 100644 index 0000000..cfd37bd --- /dev/null +++ b/itf/app/forms.py @@ -0,0 +1,39 @@ +import floppyforms as forms +from django.contrib.contenttypes.models import ContentType +from crispy_forms.helper import FormHelper + +class ItfForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + self.helper = FormHelper() + self.helper.form_tag = False + super(ItfForm, self).__init__(*args, **kwargs) + + +class PopupForm(ItfForm): + ''' + All popup forms inherit from this + ''' + pass + + + +class AutocompleteAddWidget(forms.Select): + ''' + Widget for select2 single select + Accepts model_class as an additional keyword argument + model_class should be the model class that this is an add / autocomplete widget for + ''' + template_name = 'formwidgets/select2.html' + + def __init__(self, *args, **kwargs): + model_class = kwargs.pop('model_class') + self.ctype = ContentType.objects.get_for_model(model_class) + #self.ctype = ctype + super(AutocompleteAddWidget, self).__init__(*args, **kwargs) + + def get_context(self, name, value, attrs, *args, **kwargs): + ctx = super(AutocompleteAddWidget, self).get_context(name, value, attrs) + ctx['ctype'] = self.ctype + return ctx +