Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
1472eb71
Commit
1472eb71
authored
May 12, 2011
by
Georgios Gousios
Browse files
Methods to add/update invitations
parent
099521f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
invitations/
view
s.py
→
invitations/
invitation
s.py
View file @
1472eb71
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
settings.py.dist
View file @
1472eb71
...
...
@@ -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
settings.py.gousiosg
0 → 100644
View file @
1472eb71
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment