entire chain of popups on Person form works

This commit is contained in:
Sanj 2012-07-27 03:16:40 +05:30
parent ffdefbe643
commit efab65b50f
7 changed files with 151 additions and 58 deletions

View File

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

View File

@ -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("<script>opener.dismissAddAnotherPopup(window, '%s', '%s')</script>" % (instance.id, text,))
else:

View File

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

View File

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

View File

@ -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 "<div>" + item.title + "<div style='font-size:12px'><i>" + item.text + "</i></div></div>"
},
formatSelection: function(item) {
//console.log(item);
//return "<div>" + item.first_name + " " + item.last_name + "<div>" + item.about + "</div></div>";
//console.log("foo");
return item.title;
//return "<div data-id='" + item.id + "'>" + item.first_name + " " + item.last_name + "</div>";
}
});
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);

View File

@ -26,55 +26,10 @@
<script src="/static/uni_form/uni-form.jquery.js" type="text/javascript"></script>
<script src="/static/js/select2.js" type="text/javascript"></script>
<script src="/static/js/jquery.formset.js"></script>
<script src="/static/js/itfSelect2.js"></script>
<script type="text/javascript">
$.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 "<div>" + item.title + "<div style='font-size:12px'><i>" + item.text + "</i></div></div>"
},
formatSelection: function(item) {
//console.log(item);
//return "<div>" + item.first_name + " " + item.last_name + "<div>" + item.about + "</div></div>";
//console.log("foo");
return item.title;
//return "<div data-id='" + item.id + "'>" + item.first_name + " " + item.last_name + "</div>";
}
});
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;
});
}
$(function(){
$('form.uniForm').uniform();

View File

@ -1,9 +1,17 @@
<!doctype html>
<html>
<head>
<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<link rel="stylesheet" href="/static/css/reset.css" />
<link rel="stylesheet" href="/static/css/noel/main.css" />
<link rel="stylesheet" href="/static/css/register.css" />
<link rel="stylesheet" href="/static/css/select2/select2.css" />
<script type="text/javascript" src="/static/js/RelatedObjectLookups.js"></script>
<script src="/static/js/select2.js" type="text/javascript"></script>
<script src="/static/js/itfSelect2.js"></script>
<script>
$(function() { $('.select2class').itfSelect2(); });
</script>
</head>
<body>
<form action="" method="POST" id="formItf">