email user invitations 0.5

This commit is contained in:
Johnson Chetty 2012-09-27 20:45:50 +02:00
parent e655d0ecf8
commit 476c28819b
5 changed files with 96 additions and 9 deletions

View File

@ -8,6 +8,12 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from imagestore.models import Album
# mail imports
from django.core.mail import send_mail
from django.template.loader import get_template
from django.template import Context
from itf.settings import SITE_HOST, DEFAULT_FROM_MAIL
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
@ -125,6 +131,37 @@ BUZZ_ITEM_TYPES = (
('publicity', 'Publicity'),
)
class PersonInvitation(models.Model):
invite_code = models.CharField(max_length=30)
inviter = models.ForeignKey(Person, related_name='has_invited', null=True, blank=True)
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):
subject = 'Invitation to join the India Theatre Forum'
link = 'http://%s/invitation/accept/%s/' % (
SITE_HOST,
self.invite_code,
)
template = get_template('modules/itfprofiles/invitation_email.txt')
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),
})
message = template.render(context)
send_mail(
subject, message,
DEFAULT_FROM_MAIL, [self.invitee.email]
)
class BuzzItem(ItfModel):
link = models.URLField(verify_exists=False)
title = models.CharField(max_length=255)
@ -218,7 +255,7 @@ class Training(models.Model):
# title = models.CharField(max_length=255)
# desc= models.TextField(max_length=2048)
person = models.ForeignKey("Person")
area = models.CharField(max_length=255) # Choices?
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?
where = models.ForeignKey("TheatreGroup")
from_when = models.DateField(blank=True, null=True)

View File

@ -8,6 +8,7 @@ from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from datetime import datetime
def person_form(request):
person = Person.objects.all()[0]
@ -17,7 +18,6 @@ def person_form(request):
#pdb.set_trace()
return render_to_response("test/person_form.html", {'form': form, 'inlines': inlines})
@login_required
def edit_profile(request):
user = request.user
@ -49,10 +49,49 @@ def edit_profile(request):
})
return render_to_response("test/person_form.html", context)
@login_required
def friend_invite(request):
if request.method == 'POST':
form = PersonForm(request.POST, request.FILES)
if form.is_valid():
invitee = form.save()
invitation = PersonInvitation(
invitee=invitee,
invite_code=User.objects.make_random_password(30),
is_validated=False,
inviter=Person.objects.get(user=request.user),
sent_date=datetime.now()
)
invitation.send()
try:
invitation.save()
except:
return HttpResponse("<html><body>Not Invited!!</body></html>")
return HttpResponse("<html><body>Invited!!</body></html>")
#return HttpResponseRedirect('/invitation/invite/')
else:
return render_to_response('test/popup.html', context)
else:
form = PersonForm()
context = RequestContext(request, {
'form': form
})
return render_to_response("test/popup.html", context)
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')
def personpopup(request):
form = PersonForm()
if request.POST:
return HttpResponse("<script>opener.dismissAddAnotherPopup(window, '%s', '%s')</script>" % ("45", "sanjay bhangar",))
return HttpResponse("<script>opener.dismissAddAnotherPopup(window, '%s', '%s')</script>" % ("45", "sanjay bhangar",))
form = PersonForm(request.POST, request.FILES)
if form.is_valid():
instance = form.save()

View File

@ -5,6 +5,7 @@ from os.path import join
# import markdown
SITENAME = "India Theatre Forum"
SITE_HOST = "theatreforum.in"
DEBUG = True
TEMPLATE_DEBUG = DEBUG
JSON_DEBUG = DEBUG
@ -233,10 +234,10 @@ INSTALLED_APPS = (
)
# jj allauthsettingsa
# jj all auth + email settings
LOGIN_REDIRECT_URL = '/edit_profile'
#ACCOUNT_AUTHENTICATION_METHOD=''
DEFAULT_FROM_MAIL='webmaster@%s' % (SITE_HOST,)
#ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_EMAIL_VERIFICATION=False
@ -263,8 +264,6 @@ SOCIALACCOUNT_PROVIDERS = { 'openid':
name='Google',
openid_url='https://www.google.com/accounts/o8/id')]}}
#ACCOUNT_ACTIVATION_DAYS = 30
#overwrite default settings with local settings
try:
from local_settings import *

View File

@ -1 +1,8 @@
Please activate your registration by clicking on this link: http://theatreforum.in/accounts/activate/{{ activation_key }}/
Hello,
Welcome to the theatre forum circle!
Please activate your registration by clicking on this link:
http://theatreforum.in/accounts/activate/{{ activation_key }}/
--
India Theatre Forum

View File

@ -55,12 +55,17 @@ 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/add/$', 'itfprofiles.views.friend_add'),
(r'^invitation/invite/$', 'itfprofiles.views.friend_invite'),
)
# (r'^ajax_filtered_fields/', include('ajax_filtered_fields.urls')),
# Uncomment the next line to enable the admin:
# (r'^test$', 'app.views.index'),
# (r'^$', 'festival.views.home')
)
if settings.LOCAL_DEVELOPMENT:
#