From 01f5996b0223b339c8382dd449457563f79fb053 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 7 Aug 2012 19:59:35 +0530 Subject: [PATCH] create forms for events --- itf/events/forms.py | 30 ++++++++++++++++++++++ itf/events/models.py | 33 +++++++++++++++++-------- itf/settings.py | 1 + itf/templates/modules/events/event.html | 0 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 itf/events/forms.py create mode 100644 itf/templates/modules/events/event.html diff --git a/itf/events/forms.py b/itf/events/forms.py new file mode 100644 index 0000000..a99568b --- /dev/null +++ b/itf/events/forms.py @@ -0,0 +1,30 @@ +import floppyforms as forms +from models import * +from app.forms import * +from itfprofiles.models import Person, TheatreGroup + +class PersonEventForm(ItfForm): + person = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person)) + + class Meta: + model = PersonEvent + + +class GroupEventForm(ItfForm): + group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) + + class Meta: + model = GroupEvent + + +PersonEventInline = itf_inlineformset_factory(Event, PersonEvent, form=PersonEventForm, extra=1, title="Add / Edit people associated with this event", help_text="select the people that are connected to this event") + +GroupEventInline = itf_inlineformset_factory(Event, GroupEvent, form=GroupEventForm, extra=1, title="Add / Edit groups associated with this event", help_text="select the groups that are connected to this event") + + +class EventForm(ItfForm): + inlines = [PersonEventInline, GroupEventInline] + + class Meta: + model = Event + exclude = ('people', 'groups',) diff --git a/itf/events/models.py b/itf/events/models.py index d00e9e7..6c1682e 100644 --- a/itf/events/models.py +++ b/itf/events/models.py @@ -12,13 +12,14 @@ from itfprofiles.models import Location, Production, TheatreGroup, Person class Event(ItfModel): #ItfModel stuff: - #form_names = ['PersonForm', 'PopupPersonForm'] + form_names = ['EventForm'] + main_form = 'EventForm' fts_fields = ['title', 'oneliner', 'description'] title = models.CharField(max_length=1024) oneliner = models.CharField(max_length=1024,help_text="Event slogan/one liner") description = models.TextField(blank=True, null=True) - locations = generic.GenericRelation("Location") + locations = generic.GenericRelation(Location) start_date = models.DateTimeField() end_date = models.DateTimeField() booking_link = models.URLField(blank=True, null=True, help_text="Ticket booking") @@ -26,7 +27,7 @@ class Event(ItfModel): production = models.ForeignKey(Production, blank=True, null=True, help_text="If this is a showing of a production...") people = models.ManyToManyField(Person, blank=True, null=True, through="PersonEvent") image = models.ImageField(upload_to='images/', blank=True, null=True) -# groups = models.ManyToManyField(TheatreGroup, + groups = models.ManyToManyField(TheatreGroup, blank=True, null=True, through="GroupEvent") #Entities and Connections - # connections = generic.GenericRelation("Connection") @@ -39,12 +40,12 @@ class Event(ItfModel): return self.__unicode__() def get_dict(self): - links = self.connections.all().order_by('link_type') - link_keys = self.connections.all().values_list['link_type'].distinct() +# links = self.connections.all().order_by('link_type') +# link_keys = self.connections.all().values_list['link_type'].distinct() - conn = dict() - for key in link_keys: - conn[key]= [obj for obj in links if obj.type==key] +# conn = dict() +# for key in link_keys: +# conn[key]= [obj for obj in links if obj.type==key] #add conn keys to main dict return { 'title': self.title, @@ -61,8 +62,20 @@ PERSON_EVENT_CHOICES = ( class PersonEvent(models.Model): person = models.ForeignKey(Person) - event = models.ForeignKey(Event): - typ = models.CharField(choices=PERSON_EVENT_CHOICES) + event = models.ForeignKey(Event) + typ = models.CharField(choices=PERSON_EVENT_CHOICES, max_length=128) + + +GROUP_EVENT_CHOICES = ( + ('venue', 'Venue'), + ('performing', 'Performing'), +) + +class GroupEvent(models.Model): + group = models.ForeignKey(TheatreGroup) + event = models.ForeignKey(Event) + typ = models.CharField(choices=GROUP_EVENT_CHOICES, max_length=128) + class Connection(models.Model): link_type = models.CharField(max_length=255) diff --git a/itf/settings.py b/itf/settings.py index 8610c5e..b6a3f4c 100755 --- a/itf/settings.py +++ b/itf/settings.py @@ -195,6 +195,7 @@ INSTALLED_APPS = ( 'bestpractices', 'emailer', 'itfprofiles', + 'events', 'pages', 'tagging', 'app', diff --git a/itf/templates/modules/events/event.html b/itf/templates/modules/events/event.html new file mode 100644 index 0000000..e69de29