From 2b0d8f8df020ef9f7cd55e067c5b32a1ef3fa502 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 19 Jul 2012 00:25:58 +0530 Subject: [PATCH] added popup forms and widgets for production, group --- itf/itfprofiles/forms.py | 62 ++++++++------------------------------- itf/itfprofiles/models.py | 4 +++ 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index 38c0571..266ee13 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -9,22 +9,7 @@ from padmavideos.models import PadmaVideo, PadmaClip from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit from django.contrib.contenttypes.models import ContentType - - -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 - +from app.forms import * class PopupPersonForm(PopupForm): @@ -32,38 +17,17 @@ class PopupPersonForm(PopupForm): model = Person -class AutocompleteAddWidget(forms.Select): - template_name = 'formwidgets/select2.html' +class PopupGroupForm(PopupForm): - def __init__(self, *args, **kwargs): - ctype = kwargs.pop('ctype') - 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 + class Meta: + model = TheatreGroup -#class ConnectionsWidget(forms.SelectMultiple): -# template_name = 'formwidgets/select2_multiple.html' - -# ''' -# def get_context_data(self): -# ctx = super(ConnectionsWidget, self).get_context_data() -# -# #ctx['data_json'] = [{'id': obj[0], 'text': obj[1]} for obj in self.choices] -# return ctx -# ''' -# -# def get_context(self, name, value, attrs, *args, **kwargs): -# ctx = super(ConnectionsWidget, self).get_context(name, value, attrs) -# ctx['popup_url'] = '/m/person/popup' #FIXME: url scheme, also, a better way to pass this context to the widget template. -# #selected_values = [{'id': obj[0], 'text': obj[1]} for obj in self.choices if obj[0] in value] -# #ctx['data_json'] = json.dumps(selected_values) # json.dumps(choices) -# return ctx +class PopupProductionForm(PopupForm): + class Meta: + model = Production + class ItfAllAuthRegForm(forms.Form): firstname=forms.CharField() lastname=forms.CharField() @@ -86,21 +50,21 @@ class ItfRegistrationForm(RegistrationForm): class ConnectionsForm(ItfForm): - ctype = ContentType.objects.get_for_model(Person) - person2 = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(ctype=ctype)) + #ctype = ContentType.objects.get_for_model(Person) + person2 = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person)) class Meta: model = PersonPerson exclude = ('disapproved',) class PersonProductionForm(ItfForm): - pass - + production = forms.ModelChoiceField(Production.objects.all(), widget=AutocompleteAddWidget(model_class=Production)) + class Meta: model = PersonProduction class PersonGroupForm(ItfForm): - pass + group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) class Meta: model = PersonGroup diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index a679dfa..aa65222 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -126,6 +126,8 @@ class Play(ItfModel): class Production(ItfModel): # user = models.ForeignKey(User) + fts_fields = ['name', 'group__name'] + form_names = ['PopupProductionForm'] play = models.ForeignKey("Play", null=True, blank=True) name = models.CharField(max_length=255, db_index=True) language = models.ForeignKey("Language", blank=True, null=True) @@ -151,6 +153,8 @@ class PersonProduction(models.Model): original_cast = models.BooleanField(default=False) class TheatreGroup(ItfModel): + fts_fields = ['name', 'about'] + form_names = ['PopupGroupForm'] name = models.CharField(max_length=255, db_index=True) # name + location is unique city = models.CharField(max_length=255) location = models.ForeignKey(Location, blank=True, null=True)