Commit 1472eb71 authored by Georgios Gousios's avatar Georgios Gousios
Browse files

Methods to add/update invitations

parent 099521f5
from django import forms
from django.conf import settings
from django.db import transaction
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from synnefo.api.common import method_not_allowed
from synnefo.db.models import Invitations, SynnefoUser
from synnefo.logic import users
class InvitationForm(forms.Form):
emails = forms.Textarea
......@@ -21,9 +25,52 @@ class InvitationForm(forms.Form):
def inv_demux(request):
if request.method == 'GET':
data = t.render('invitation.html', {'invitations': None})
#data = t.render('invitation.html', {'invitations': None})
return HttpResponse(data)
elif request.method == 'POST':
f = InvitationForm(request)
else:
method_not_allowed(request)
\ No newline at end of file
method_not_allowed(request)
@transaction.commit_on_success
def add_invitation(source, name, email):
"""
Adds an invitation, if the source user has not gone over his/her
invitation count or the target user has not been invited already
"""
num_inv = Invitations.objects.filter(source = source).count()
if num_inv >= settings.MAX_INVITATIONS:
raise TooManyInvitations(source)
target = SynnefoUser.objects.filter(name = name, uniq = email)
if target.count() is not 0:
raise AlreadyInvited("User already invited: %s <%s>" % (name, email))
users.register_student(name, '', email)
inv = Invitations()
inv.source = source
inv.target = target
inv.save()
@transaction.commit_on_success
def invitation_accepted(invitation):
"""
Mark an invitation as accepted
"""
invitation.accepted = True
invitation.save()
class TooManyInvitations(BaseException):
def __init__(self, source):
self.source = source
class AlreadyInvited(BaseException):
def __init__(self, msg):
self.msg = msg
\ No newline at end of file
......@@ -240,3 +240,5 @@ LOGIN_PATH = "/login"
# work after this many hours after 2011/05/10
AUTH_TOKEN_DURATION = 30 * 24
#Max number of invitations allowed per user
MAX_INVITATIONS = 20
\ No newline at end of file
AUTH_TOKEN_DURATION = 24 * 234
DISPATCHER_LOG_FILE = "synnefo.log"
BACKEND_PREFIX_ID = "gousiosg-"
fix_amqp_settings(BACKEND_PREFIX_ID)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment