From 7913e231acbfb8fcebbf579c8da1400c0bc07f2a Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Tue, 23 Oct 2012 13:50:09 +0200 Subject: [PATCH 1/2] email invitation work, forms tweaks --- itf/itfprofiles/admin.py | 9 +++++++++ itf/itfprofiles/forms.py | 36 ++++++++++++++++++++++++++++++------ itf/itfprofiles/models.py | 27 +++++++++++++++++---------- itf/itfprofiles/views.py | 23 ++++++++++++----------- itf/urls.py | 2 +- 5 files changed, 69 insertions(+), 28 deletions(-) diff --git a/itf/itfprofiles/admin.py b/itf/itfprofiles/admin.py index 6fb5871..ad2a0df 100755 --- a/itf/itfprofiles/admin.py +++ b/itf/itfprofiles/admin.py @@ -39,6 +39,13 @@ class TheatreGroupAdmin(admin.ModelAdmin): save_on_top = True +#class LocationAdmin(admin.ModelAdmin): +# save_on_top = True + +class CityAdmin(admin.ModelAdmin): + pass + + admin.site.register(Occupation, OccupationAdmin) admin.site.register(Relation, RelationAdmin) admin.site.register(TheatreGroup, TheatreGroupAdmin) @@ -46,6 +53,8 @@ admin.site.register(Person) admin.site.register(Language) admin.site.register(Training) admin.site.register(Production) +#admin.site.register(Location,LocationAdmin) +admin.site.register(City,CityAdmin) #class TalkAdmin(admin.ModelAdmin): # inlines = [PadmaVideoInline, AudioInline, ImageInline, DocumentInline] diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index de9ca3a..d3c6554 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -29,7 +29,6 @@ class LocationForm(ItfForm): LocationsInline = itf_inlineformset_factory(Location, form=LocationForm, title="Locations", is_generic=True) - class BuzzItemsForm(ItfForm): class Meta: @@ -92,7 +91,7 @@ class PopupProductionForm(PopupForm): class Meta: model = Production - fields = ('name', 'group',) + fields = ('name', 'group',) #Inline form definitions and inlines for Person form @@ -115,6 +114,15 @@ class PersonProductionForm(ItfForm): class Meta: model = PersonProduction +class TheatreGroupProductionForm(ItfForm): + #j pass an empty list, + #production = forms.ModelChoiceField([], widget=AutocompleteAddWidget(model_class=Production)) + + class Meta: + model = Production + +ProductionsTheatreGroupInline = itf_inlineformset_factory(TheatreGroup, Production, form=TheatreGroupProductionForm, extra=1, title="Productions") + class PersonGroupForm(ItfForm): group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) @@ -123,6 +131,7 @@ class PersonGroupForm(ItfForm): ConnectionsInline = itf_inlineformset_factory(Person, PersonPerson, fk_name='person1', form=ConnectionsForm, extra=1, title="Add / Edit Connections", help_text="select the people you are connected with and how you are related in the theatre world") ProductionsInline = itf_inlineformset_factory(Person, PersonProduction, form=PersonProductionForm, extra=1, title="Productions you have worked in") + GroupsInline = itf_inlineformset_factory(Person, PersonGroup, extra=1, form=PersonGroupForm, title="Theatre groups you are a part of or have worked with") PersonOccupationsInline = itf_inlineformset_factory(Person, PersonOccupation, extra=1, form=PersonOccupationForm, title="Select your occupation / you can add as many as you like") @@ -176,7 +185,7 @@ GroupOccupationInline = itf_inlineformset_factory(TheatreGroup, GroupGroupOccupa class TheatreGroupForm(ItfForm): languages = forms.ModelMultipleChoiceField(Language.objects.all(), widget=forms.CheckboxSelectMultiple()) - inlines = [GroupOccupationInline, PersonGroupInline, ResourcesInline, BuzzItemsInline, AwardsInline, TrainingsInline, LocationsInline] + inlines = [GroupOccupationInline, PersonGroupInline, ResourcesInline, BuzzItemsInline, AwardsInline, TrainingsInline, LocationsInline, ProductionsTheatreGroupInline] class Meta: model = TheatreGroup @@ -213,11 +222,26 @@ class ItfAllAuthRegForm(forms.Form): firstname=forms.CharField() lastname=forms.CharField() - def save(self, user): + #def __init__(self, request=None): + + + + def save(self, user, request=None): first_name = self.cleaned_data['firstname'] last_name = self.cleaned_data['lastname'] - p = Person(user=user, first_name=first_name, last_name=last_name, email=user.email) - p.save() + if request.session['invite_code']: + invite_code = request.session['invite_code'] + pi = PersonInvitation.objects.get(invite_code=invite_code) + inviter = pi.inviter + invitee = pi.invitee + invitee.user=user + invitee.save() + else: + p = Person(user=user, first_name=first_name, last_name=last_name, email=user.email) + p.save() + user.first_name = first_name + user.last_name = last_name + user.save() return self diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index cf81162..627b501 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -138,19 +138,18 @@ class PersonInvitation(models.Model): invitee = models.ForeignKey(Person, related_name='was_invited_by', null=True, blank=True) is_validated=models.BooleanField(default=False) sent_date = models.DateTimeField() - - def __unicode__(self): - return u'%s, %s' % (self.invitee.first_name, self.invitee.email) - def send(self): + def send_mail(self): + #import pdb ; pdb.set_trace() + #from django.template.loader import get_template + template = get_template('modules/itfprofiles/invitation_email.txt') subject = 'Invitation to join the India Theatre Forum' - template = get_template('/itfprofiles/invitation_email.txt') link = 'http://%s/invitation/accept/%s/' % ( "test.theatreforum.in", self.invite_code, ) context = Context({ 'name': str(self.invitee.first_name) + str(self.invitee.last_name), 'link': link, - 'sender': str(self.inviter.first_name) + str(self.inviter.last_name), + 'sender': str(self.inviter.first_name) + str(self.inviter.last_name) }) message = template.render(context) send_mail( @@ -158,6 +157,11 @@ class PersonInvitation(models.Model): DEFAULT_FROM_MAIL, [self.invitee.email] ) + + def __unicode__(self): + return u'%s, %s' % (self.invitee.first_name, self.invitee.email) + + class BuzzItem(ItfModel): link = models.URLField(verify_exists=False) @@ -207,18 +211,20 @@ STATE_CHOICES= ( ('31', 'Tripura'), ('32', 'Uttarakhand (Uttaranchal)'), ('33', 'Uttar Pradesh'), - ('34', 'West Bengal') + ('34', 'West Bengal'), + ('35', 'Not Applicable'), ) class City(models.Model): name = models.CharField(max_length=255) state = models.CharField(choices = STATE_CHOICES, max_length=255) - + def __unicode__(self): + return self.name from django.contrib.localflavor.in_.forms import INZipCodeField class Location(models.Model): - lat= models.FloatField(blank=True, null=True) - lon= models.FloatField(blank=True, null=True) + #lat= models.FloatField(blank=True, null=True) + #lon= models.FloatField(blank=True, null=True) city = models.ForeignKey(City) pincode= INZipCodeField() address= models.TextField() @@ -254,6 +260,7 @@ class Training(models.Model): person = models.ForeignKey("Person") area = models.CharField(max_length=255) with_whom = models.CharField(max_length=255) # Is this a foreign key to person, or group, or just text field like now? + #trained_by=models.ManyToManyField('Person', related_name='trained') where = models.ForeignKey("TheatreGroup") from_when = models.DateField(blank=True, null=True) until_when = models.DateField(blank=True, null=True) diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index bc87b64..2c54b39 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -1,13 +1,13 @@ # Create your views here. from models import * from forms import * -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, get_object_or_404 from ox.django.shortcuts import render_to_json_response from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required - +from django.views.decorators.csrf import csrf_exempt from datetime import datetime def person_form(request): @@ -49,7 +49,8 @@ def edit_profile(request): }) return render_to_response("test/person_form.html", context) -@login_required +@csrf_exempt +@login_required def friend_invite(request): if request.method == 'POST': form = PersonForm(request.POST, request.FILES) @@ -62,11 +63,11 @@ def friend_invite(request): inviter=Person.objects.get(user=request.user), sent_date=datetime.now() ) - invitation.send() - try: - invitation.save() - except: - return HttpResponse("Not Invited!!") + invitation.save() + #try: + invitation.send_mail() + #except: + # return HttpResponse("Not Invited!!") return HttpResponse("Invited!!") #return HttpResponseRedirect('/invitation/invite/') @@ -83,9 +84,9 @@ def friend_invite(request): def invitation_accept(request,invite_code): - invitation = get_object_or_404(PersonInvitation, invite_code__exact=invite_code) - request.session['invitation'] = invitation.id - return HttpResponseRedirect('/accounts/madd') + #invitation = get_object_or_404(PersonInvitation, invite_code__exact=invite_code) + request.session['invite_code'] = invite_code + return HttpResponseRedirect('/accounts/signup') diff --git a/itf/urls.py b/itf/urls.py index 20936d3..4702ccd 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -57,7 +57,7 @@ urlpatterns = patterns('', (r'emailsignuplist', 'festival.views.email_signups'), (r'^favicon.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/images/favicon.ico'}), - (r'^invitation/(w+)/$','itfprofiles.views.invitation_accept'), + (r'^invitation/accept/(?P\w+)/','itfprofiles.views.invitation_accept'), #(r'^invitation/add/$', 'itfprofiles.views.friend_add'), (r'^invitation/invite/$', 'itfprofiles.views.friend_invite'), ) From 8e1ddb7dc9315e1b0985b6489c0eaaa2c562d7e9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Wed, 24 Oct 2012 15:44:25 +0530 Subject: [PATCH 2/2] test template scriptarchive --- .../{scriptarchive/synopsis.html => scriptarchive.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename itf/templates/test_static_templates/{scriptarchive/synopsis.html => scriptarchive.html} (100%) diff --git a/itf/templates/test_static_templates/scriptarchive/synopsis.html b/itf/templates/test_static_templates/scriptarchive.html similarity index 100% rename from itf/templates/test_static_templates/scriptarchive/synopsis.html rename to itf/templates/test_static_templates/scriptarchive.html