From efab65b50f91ab1ccefabc54b7574cc8315cc5e8 Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 27 Jul 2012 03:16:40 +0530 Subject: [PATCH] entire chain of popups on Person form works --- itf/app/forms.py | 4 +- itf/app/views.py | 5 +- itf/itfprofiles/forms.py | 9 ++- itf/itfprofiles/models.py | 89 ++++++++++++++++++++++++++--- itf/static/js/itfSelect2.js | 47 +++++++++++++++ itf/templates/test/person_form.html | 47 +-------------- itf/templates/test/popup.html | 8 +++ 7 files changed, 151 insertions(+), 58 deletions(-) create mode 100644 itf/static/js/itfSelect2.js diff --git a/itf/app/forms.py b/itf/app/forms.py index 8b71923..924a1e8 100644 --- a/itf/app/forms.py +++ b/itf/app/forms.py @@ -36,7 +36,7 @@ class AutocompleteAddWidget(forms.Select): def get_matched_choice_title(choices, id): for choice in choices: - if choice[0] == id: + if choice[0] != '' and int(choice[0]) == int(id): return choice[1] return '' @@ -44,6 +44,8 @@ class AutocompleteAddWidget(forms.Select): #pdb.set_trace() ctx = super(AutocompleteAddWidget, self).get_context(name, value, attrs) if value: + #import pdb + #pdb.set_trace() ctx['title'] = get_matched_choice_title(self.choices, value) ctx['ctype'] = self.ctype return ctx diff --git a/itf/app/views.py b/itf/app/views.py index 0832b26..1411025 100755 --- a/itf/app/views.py +++ b/itf/app/views.py @@ -44,7 +44,10 @@ def popup_form(request, ctype_id): if request.POST: form = form_class(request.POST, request.FILES) if form.is_valid(): - instance = form.save() + instance = form.save(commit=False) + if instance.__dict__.has_key('added_by_id'): + instance.added_by = request.user + instance.save() text = instance.get_title() return HttpResponse("" % (instance.id, text,)) else: diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index 2901a3e..796ce8a 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -15,18 +15,23 @@ class PopupPersonForm(PopupForm): class Meta: model = Person - fields = ('first_name', 'last_name', 'email', 'dob',) + fields = ('first_name', 'last_name', 'email',) + class PopupGroupForm(PopupForm): class Meta: model = TheatreGroup + fields = ('name', 'email',) class PopupProductionForm(PopupForm): - + group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) + class Meta: model = Production + fields = ('name', 'group',) + class ItfAllAuthRegForm(forms.Form): firstname=forms.CharField() diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 40c556d..38f20eb 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -27,7 +27,7 @@ class Person(ItfModel): dob = models.DateField(null=True, verbose_name="Date of Birth", blank=True) is_practitioner = models.BooleanField(default=False) is_enthusiast = models.BooleanField(default=True) - is_freelancer = models.BooleanField(default=False) + is_freelancer = models.BooleanField(default=False) #Change to is_associate #Occupation info occupations = models.ManyToManyField("Occupation", through='PersonOccupation', blank=True, null=True) @@ -42,7 +42,7 @@ class Person(ItfModel): connections = models.ManyToManyField('Person', blank=True, null=True, through='PersonPerson') productions = models.ManyToManyField("Production", blank=True, null=True, through='PersonProduction') trainings = models.ManyToManyField("Training", blank=True, null=True, related_name="trainee") - +# awards = models.ManyToManyField("Award", blank=True, null=True) languages = models.ManyToManyField("Language", blank=True, null=True) #s added # photos = models.ManyToManyField("PhotoAlbum", blank=True, null=True) @@ -87,6 +87,21 @@ class Occupation(models.Model): return True return False +BUZZ_ITEM_TYPES = ( + ('review', 'Review'), + ('publicity', 'Publicity'), +) + +class PersonBuzzItem(ItfModel): + person = models.ForeignKey("Person") + link = models.URLField(verify_exists=False) + title = models.CharField(max_length=255) + blurb = models.TextField(blank=True) + typ = models.CharField(choices=BUZZ_ITEM_TYPES, max_length=128, blank=True) + + def __unicode__(self): + return self.title + STATE_CHOICES= ( ('0', 'Andaman and Nicobar'), @@ -174,7 +189,8 @@ class Play(ItfModel): title = models.CharField(max_length=512) author = models.CharField(max_length=512, blank=True) year = models.IntegerField(null=True, blank=True, max_length=4) - user = models.ForeignKey(User) + + added_by = models.ForeignKey(User) def __unicode__(self): return self.title @@ -184,11 +200,22 @@ class Production(ItfModel): # user = models.ForeignKey(User) fts_fields = ['name', 'group__name'] form_names = ['PopupProductionForm'] + added_by = models.ForeignKey(User) play = models.ForeignKey("Play", null=True, blank=True) name = models.CharField(max_length=255, db_index=True) + synopsis = models.TextField(blank=True) language = models.ForeignKey("Language", blank=True, null=True) - group = models.ForeignKey("TheatreGroup") - director = models.ForeignKey(Person) + group = models.ForeignKey("TheatreGroup", blank=True, null=True) + director = models.ForeignKey(Person, related_name='productions_directed', blank=True, null=True) + playwright = models.ForeignKey(Person, related_name='productions_authored', blank=True, null=True) + anecdotes = models.TextField(blank=True) + + def __unicode__(self): + return self.name + + + + SHOWS_NO_CHOICES = ( ('5', '0-5 Shows'), @@ -211,15 +238,25 @@ class PersonProduction(models.Model): class TheatreGroup(ItfModel): fts_fields = ['name', 'about'] form_names = ['PopupGroupForm'] + added_by = models.ForeignKey(User) 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) - tel = models.IntegerField(blank=True, null=True) email = models.EmailField(blank=True, null=True) + tel = models.IntegerField(blank=True, null=True) + nature_of_work = models.ManyToManyField("GroupOccupation", blank=True, null=True, through="GroupGroupOccupation") + languages = models.ManyToManyField("Language", blank=True, null=True) + year_founded = models.IntegerField(blank=True, null=True) + about = models.TextField(blank=True) + awards = models.ManyToManyField("Award", blank=True, null=True) + website = models.URLField(blank=True, verify_exists=False) +# resources = models.ManyToManyField("Resource", blank=True, null=True) +# city = models.CharField(max_length=255) + locations = models.ManyToManyField("Location", blank=True, null=True) + about = models.TextField(blank=True, null=True) nature_of_work = models.CharField(max_length=255) founded = models.CharField(max_length=10) + def __unicode__(self): return self.name @@ -230,6 +267,42 @@ class PersonGroup(models.Model): role = models.CharField(max_length=255, blank=True) +class GroupBuzzItem(ItfModel): + group = models.ForeignKey("TheatreGroup") + link = models.URLField(verify_exists=False) + title = models.CharField(max_length=255) + blurb = models.TextField(blank=True) + typ = models.CharField(choices=BUZZ_ITEM_TYPES, max_length=128, blank=True) + + def __unicode__(self): + return self.title + + + + + + +class Award(models.Model): + title = models.CharField(max_length=255) + year = models.IntegerField(blank=True) + link = models.URLField(verify_exists=False, blank=True, null=True) + + def __unicode__(self): + return self.title + +class GroupOccupation(models.Model): + name = models.CharField(max_length=128) + + def __unicode__(self): + return self.name + +class GroupGroupOccupation(models.Model): + theatregroup = models.ForeignKey("TheatreGroup") + groupoccupation = models.ForeignKey("GroupOccupation") + is_main = models.BooleanField(default=False) + + + class Language(models.Model): code = models.CharField(max_length=3, db_index=True) name = models.CharField(max_length=255) diff --git a/itf/static/js/itfSelect2.js b/itf/static/js/itfSelect2.js new file mode 100644 index 0000000..13a2661 --- /dev/null +++ b/itf/static/js/itfSelect2.js @@ -0,0 +1,47 @@ + +(function($) { + $.fn.itfSelect2 = function() { + return this.each(function() { + var $this = $(this); + var ctype_id = $this.attr("data-ctype"); + var url = '/autocomplete/' + ctype_id; + $this.select2({ + ajax: { + 'url': url, + dataType: 'json', + quietMillis: 100, + data: function(term, page) { + return { + q: term, + page_limit: 10, + page: page + } + }, + results: function(data, page) { + //console.log(data); + var more = data.has_next; + //console.log(data); + return {results: data.items, more: more}; + } + }, + formatResult: function(item) { + return "
" + item.title + "
" + item.text + "
" + }, + formatSelection: function(item) { + //console.log(item); + //return "
" + item.first_name + " " + item.last_name + "
" + item.about + "
"; + //console.log("foo"); + return item.title; + //return "
" + item.first_name + " " + item.last_name + "
"; + } + }); + var id = $this.attr("data-id"); + //console.log(id); + if ($.trim(id) !== '') { + var title = $this.attr("data-title"); + $this.select2("val", {'id': id, 'title': title}); + } + //return this; + }); + } +})(jQuery); diff --git a/itf/templates/test/person_form.html b/itf/templates/test/person_form.html index 4894c12..d3414ec 100644 --- a/itf/templates/test/person_form.html +++ b/itf/templates/test/person_form.html @@ -26,55 +26,10 @@ - + + + + + +