From 559581dd62f9c86daa8e04f7dbb3d22f011d7627 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 3 Jan 2013 03:23:11 +0530 Subject: [PATCH] add contact forms for people and group pages --- itf/itfprofiles/models.py | 2 + itf/itfprofiles/views.py | 41 +++++++++++++++++++ itf/templates/modules/itfprofiles/person.html | 34 ++++++++++++++- .../modules/itfprofiles/theatregroup.html | 36 +++++++++++++++- itf/urls.py | 2 + 5 files changed, 113 insertions(+), 2 deletions(-) diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 90b859f..4be6003 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -423,6 +423,8 @@ class Production(ItfModel): if cast_list: persons.extend(cast_list) return persons + + def get_dict(self): rel_level1 = [obj for obj in Production.objects.filter(script=self.script)] diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index c71fbba..85bc66c 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -4,6 +4,7 @@ from forms import * 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.core.mail import send_mail from django.template import RequestContext from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required @@ -141,3 +142,43 @@ def grouppopup(request): 'form': form }) return render_to_response("test/popup.html", context) + + +def contact_person(request): + frm = request.user.email + to_person = request.GET.get("to", None) + try: + to = Person.objects.get(pk=to_person) + except: + return HttpResponse("An error occurred. Please contact contact@theatreforum.in and let us know. Thanks.") + message = request.GET.get("message", None) + if not message: + return HttpResponse("Please enter a message.") + if not to.user: + return HttpResponse("Sorry, person does not have an email address associated on the site.") + else: + to_email = to.user.email + send_mail("Contact on theatreforum.in", message, frm, [to_email]) + return HttpResponse("Your message has been sent, thanks.") + + + +def contact_group(request): + frm = request.user.email + to_group = request.GET.get("to", None) + try: + to = TheatreGroup.objects.get(pk=to_group) + except: + return HttpResponse("An error occurred. Please contact contact@theatreforum.in and let us know. Thanks.") + message = request.GET.get("message", None) + if not message: + return HttpResponse("Please enter a message.") + if not to.added_by: + return HttpResponse("Sorry, group does not have an email address associated on the site.") + else: + #FIXME: also get email addresses of all group admins + to_email = to.added_by.email + send_mail("Contact on theatreforum.in", message, frm, [to_email]) + return HttpResponse("Your message has been sent, thanks.") + + diff --git a/itf/templates/modules/itfprofiles/person.html b/itf/templates/modules/itfprofiles/person.html index 034471e..d0afee5 100644 --- a/itf/templates/modules/itfprofiles/person.html +++ b/itf/templates/modules/itfprofiles/person.html @@ -35,7 +35,39 @@
Gender: {{ gender }}
Contact -
Some text
+ + +


diff --git a/itf/templates/modules/itfprofiles/theatregroup.html b/itf/templates/modules/itfprofiles/theatregroup.html index 2746654..347beef 100644 --- a/itf/templates/modules/itfprofiles/theatregroup.html +++ b/itf/templates/modules/itfprofiles/theatregroup.html @@ -42,7 +42,41 @@ {% endif %}
- Contact + Contact + + +

diff --git a/itf/urls.py b/itf/urls.py index 658c327..f5d72a1 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -63,6 +63,8 @@ urlpatterns = patterns('', (r'^invitation/accept/(?P\w+)/','itfprofiles.views.invitation_accept'), #(r'^invitation/add/$', 'itfprofiles.views.friend_add'), (r'^invitation/invite/$', 'itfprofiles.views.friend_invite'), + (r'^contact/person/$', 'itfprofiles.views.contact_person'), + (r'^contact/group/$', 'itfprofiles.views.contact_group'), ) # (r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')),