added popup forms and widgets for production, group

This commit is contained in:
Sanj 2012-07-19 00:25:58 +05:30
parent ab23f16047
commit 2b0d8f8df0
2 changed files with 17 additions and 49 deletions

View File

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

View File

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