forgot to add app/forms.py

This commit is contained in:
Sanj 2012-07-19 00:26:24 +05:30
parent 2b0d8f8df0
commit 3390f1e25c

39
itf/app/forms.py Normal file
View File

@ -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