author | Madhusudan.C.S <madhusudancs@gmail.com> |
Thu, 14 Jan 2010 21:07:03 +0530 | |
changeset 92 | 3743275f7291 |
parent 90 | 587e9c025c73 |
child 93 | e86755df35da |
permissions | -rw-r--r-- |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
|
87
1ec579a679e4
Added two models, Paper and Attachments.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
84
diff
changeset
|
3 |
from django.contrib.auth import login |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
from django.contrib.auth.decorators import login_required |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
from django.contrib.auth.forms import AuthenticationForm |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
from django.shortcuts import render_to_response |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
from django.template import RequestContext |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
from project.kiwipycon.user.forms import RegisterForm |
90
587e9c025c73
Added UserProfile import which was missing to Proceedings views.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
87
diff
changeset
|
10 |
from project.kiwipycon.user.models import UserProfile |
84
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
from project.kiwipycon.proceedings.forms import ProceedingsForm |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
@login_required |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
def submit(request, template = 'proceedings/submit.html'): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
"""View to submit the proceedings paper. |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
""" |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
user = request.user |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
if user.is_authenticated(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
try: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
profile = user.get_profile() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
except: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
profile, new = UserProfile.objects.get_or_create(user=user) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
if new: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
profile.save() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
message = None |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
if request.method == 'POST': |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
proceedings_form = ProceedingsForm(data=request.POST) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
register_form = RegisterForm(data=request.POST, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
files=request.FILES) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
if request.POST.get('action', None) == 'login': |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
login_form = AuthenticationForm(data=request.POST) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
if login_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
login(request, login_form.get_user()) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
redirect_to = reverse('kiwipycon_submit_proceedings') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
return set_message_cookie(redirect_to, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
msg = u'You have been logged in.') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
if request.POST.get('action', None) == 'register': |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
# add the new user |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
if register_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
user = kiwipycon_createuser(request, register_form.data) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
50 |
if proceedings_form.is_valid(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
51 |
if user.is_authenticated(): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
52 |
title = proceedings_form.data.get('title') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
53 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
54 |
# Saved, ... redirect back to account |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
55 |
redirect_to = reverse('kiwipycon_account') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
56 |
return set_message_cookie(redirect_to, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
57 |
msg = u'Thanks, your paper has been submitted.') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
58 |
else: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
59 |
redirect_to = reverse('kiwipycon_submit_proceedings') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
60 |
return set_message_cookie(redirect_to, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
61 |
msg = u'Something is wrong here.') |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
62 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
63 |
else: |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
64 |
proceedings_form = ProceedingsForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
65 |
register_form = RegisterForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
66 |
login_form = AuthenticationForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
67 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
68 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
69 |
proceedings_form = ProceedingsForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
70 |
register_form = RegisterForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
71 |
login_form = AuthenticationForm() |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
72 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
73 |
context = RequestContext(request, { |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
74 |
'proceedings_form': proceedings_form, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
75 |
'register_form' : register_form, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
76 |
'message' : message, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
77 |
'login_form' : login_form |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
78 |
}) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
79 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
80 |
return render_to_response(template, context) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
81 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
82 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
83 |
def edit(request, id, template = 'proceedings/edit.html'): |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
84 |
"""View to edit the proceedings paper. |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
85 |
""" |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
86 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
87 |
context = RequestContext(request, { |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
88 |
'proceedings_form': proceedings_form, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
89 |
'register_form' : register_form, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
90 |
'message' : message, |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
91 |
'login_form' : login_form |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
92 |
}) |
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
93 |
|
d01c62c2a628
Added the initial proceedings app files and enabled them in both production and development settings.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
94 |
return render_to_response(template, context) |