author | nishanth |
Fri, 16 Jul 2010 10:45:01 +0530 | |
branch | anoop |
changeset 107 | 9fd140628988 |
parent 106 | 39b0b9a71778 |
child 108 | 9363e5121f9b |
permissions | -rw-r--r-- |
15 | 1 |
from django.shortcuts import render_to_response, redirect |
98 | 2 |
from django.http import HttpResponse, Http404 |
65
0ca63c964237
now login is required for accessing stats and send_invi pages
nishanth
parents:
57
diff
changeset
|
3 |
from django.contrib.auth.decorators import login_required |
97 | 4 |
from django.utils.datastructures import MultiValueDictKeyError |
7 | 5 |
|
67 | 6 |
from django.contrib.auth import authenticate, login, logout |
7 |
||
7 | 8 |
from sage_days.sdi.models import Registrant |
90
1a6e1af98624
now selecting users through forms. created a form for that
nishanth
parents:
88
diff
changeset
|
9 |
from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm, LoginForm, UserSelectForm |
56 | 10 |
from sage_days.sdi.events import send_reg_complete_mail, mail_invi |
72 | 11 |
from sage_days.settings import APACHE_URL_PREFIX as aup |
7 | 12 |
|
13 |
def register(request): |
|
14 |
""" The user register page. |
|
15 |
""" |
|
16 |
||
9 | 17 |
if request.method == "POST": |
14 | 18 |
form = RegisterForm(request.POST) |
19 |
if form.is_valid(): |
|
15 | 20 |
form.save() |
53 | 21 |
|
22 |
data = form.cleaned_data |
|
23 |
first_name = data['first_name'] |
|
24 |
last_name = data['last_name'] |
|
25 |
email = data['email'] |
|
26 |
send_reg_complete_mail(email, first_name, last_name) |
|
27 |
||
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
28 |
return redirect("/sage_days/registration/complete") |
14 | 29 |
else: |
30 |
return render_to_response("register.html", {"form":form}) |
|
9 | 31 |
else: |
32 |
form = RegisterForm() |
|
33 |
return render_to_response("register.html", {"form":form}) |
|
22 | 34 |
|
35 |
def reg_complete(request): |
|
36 |
""" Tell the registration is successful. |
|
37 |
""" |
|
38 |
||
39 |
return render_to_response("reg_complete.html") |
|
23 | 40 |
|
65
0ca63c964237
now login is required for accessing stats and send_invi pages
nishanth
parents:
57
diff
changeset
|
41 |
@login_required |
23 | 42 |
def list_stats(request): |
43 |
""" List the statiscs of registered participants. |
|
44 |
""" |
|
45 |
||
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
46 |
if request.method == "POST": |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
47 |
form = SearchForm(request.POST) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
48 |
if form.is_valid(): |
25 | 49 |
data = form.cleaned_data |
79
064ff60025d9
removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents:
77
diff
changeset
|
50 |
|
064ff60025d9
removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents:
77
diff
changeset
|
51 |
#need_workshop = data['need_for_python_workshop'] |
064ff60025d9
removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents:
77
diff
changeset
|
52 |
#acco_required = data['need_accomodation'] |
064ff60025d9
removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents:
77
diff
changeset
|
53 |
#db_query = "Registrant.objects.filter(need_for_python_workshop=%s, acco_required=%s)"%(need_workshop, acco_required) |
064ff60025d9
removed the need_python_workshop and need_acco fields since they are very confusing
nishanth
parents:
77
diff
changeset
|
54 |
db_query = "Registrant.objects" |
25 | 55 |
|
56 |
topics_include, topics_exclude = data['topics_interested'] |
|
57 |
for number in topics_include: |
|
58 |
db_query += '.filter(topics_interested__contains="%s")'%number |
|
59 |
||
60 |
for number in topics_exclude: |
|
61 |
db_query += '.exclude(topics_interested__contains="%s")'%number |
|
62 |
||
63 |
start_python, stop_python = data['knowledge_of_python'] |
|
64 |
if start_python and stop_python: |
|
65 |
db_query += '.filter(knowledge_of_python__gte="%s")'%start_python |
|
66 |
db_query += '.filter(knowledge_of_python__lte="%s")'%stop_python |
|
67 |
elif start_python: |
|
68 |
db_query += '.filter(knowledge_of_python__exact="%s")'%start_python |
|
69 |
||
70 |
start_sage, stop_sage = data['knowledge_of_sage'] |
|
71 |
if start_sage and stop_sage: |
|
72 |
db_query += '.filter(knowledge_of_sage__gte="%s")'%start_sage |
|
73 |
db_query += '.filter(knowledge_of_sage__lte="%s")'%stop_sage |
|
74 |
elif start_sage: |
|
75 |
db_query += '.filter(knowledge_of_sage__exact="%s")'%start_sage |
|
76 |
||
77 |
start_likeliness, stop_likeliness = data['likeliness_of_attending'] |
|
78 |
if start_likeliness and stop_likeliness: |
|
79 |
db_query += '.filter(likeliness_of_attending__gte="%s")'%start_likeliness |
|
80 |
db_query += '.filter(likeliness_of_attending__lte="%s")'%stop_likeliness |
|
81 |
elif start_likeliness: |
|
82 |
db_query += '.filter(likeliness_of_attending__exact="%s")'%start_likeliness |
|
83 |
||
80
c200156c80a9
fixed a bug that arises when a query does not have any parameters to filter
nishanth
parents:
79
diff
changeset
|
84 |
db_query += ".all()" |
c200156c80a9
fixed a bug that arises when a query does not have any parameters to filter
nishanth
parents:
79
diff
changeset
|
85 |
|
25 | 86 |
matches = eval(db_query) |
87 |
return render_to_response("list_stats.html", {"form":form, 'matches':matches}) |
|
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
88 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
89 |
return render_to_response("list_stats.html", {"form":form}) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
90 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
91 |
form = SearchForm() |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
92 |
return render_to_response("list_stats.html", {"form":form}) |
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
93 |
|
65
0ca63c964237
now login is required for accessing stats and send_invi pages
nishanth
parents:
57
diff
changeset
|
94 |
@login_required |
56 | 95 |
def send_invi(request): |
96 |
""" Take a list of csv email addresses and send mails to them. |
|
97 |
""" |
|
98 |
||
99 |
if request.method == "POST": |
|
100 |
form = EmailForm(request.POST) |
|
101 |
if form.is_valid(): |
|
102 |
to_emails = form.cleaned_data['emails'] |
|
103 |
mail_invi(to_emails) |
|
104 |
return render_to_response("send_invi.html", {"emails":to_emails}) |
|
105 |
else: |
|
106 |
return render_to_response("send_invi.html", {"form":form}) |
|
107 |
else: |
|
57 | 108 |
form = EmailForm() |
56 | 109 |
return render_to_response("send_invi.html", {"form":form}) |
110 |
||
86 | 111 |
@login_required |
112 |
def send_workshop_confirm(request): |
|
113 |
""" Show a list of all the ppl who requested for a workshop and |
|
114 |
send a confirmation mail to them if not sent. |
|
115 |
""" |
|
116 |
||
88 | 117 |
matches = Registrant.objects.filter(need_for_python_workshop=True, registrantinfo__status_of_attending_workshop="1") |
86 | 118 |
if request.method == "POST": |
93
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
119 |
form = UserSelectForm(matches, request.POST) |
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
120 |
if form.is_valid(): |
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
121 |
selected_users = form.cleaned_data['selected_users'] |
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
122 |
return render_to_response("sent_wsp_confirm.html", {"selected_users":selected_users}) |
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
123 |
else: |
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
124 |
return render_to_response("send_workshop_confirm.html", {"matches":matches}) |
86 | 125 |
else: |
93
505989755cd8
modified the form and implemented the view to display selected users
nishanth
parents:
92
diff
changeset
|
126 |
return render_to_response("send_workshop_confirm.html", {"matches":matches}) |
86 | 127 |
|
95
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
128 |
def confirm_wsp_participation(request, uid): |
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
129 |
""" match id versus email and take lappy details. |
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
130 |
""" |
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
131 |
|
99 | 132 |
try: |
133 |
email = request.GET['email'] |
|
134 |
except MultiValueDictKeyError: |
|
135 |
raise Http404 |
|
136 |
||
137 |
try: |
|
138 |
user = Registrant.objects.get(id=uid, email=email) |
|
139 |
except Registrant.DoesNotExist: |
|
140 |
raise Http404 |
|
141 |
||
100 | 142 |
user_info = user.registrantinfo_set.all()[0] |
143 |
status = user_info.status_of_attending_workshop |
|
99 | 144 |
if status == "3": |
145 |
return render_to_response("attending_wsp.html") |
|
146 |
elif status != "2": |
|
147 |
raise Http404 |
|
148 |
||
95
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
149 |
if request.method == "POST": |
104
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
150 |
try: |
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
151 |
has_laptop = request.POST['lap_status'] |
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
152 |
except MultiValueDictKeyError: |
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
153 |
return render_to_response("cnf_wsp_ptc.html", {"user":user}) |
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
154 |
|
106 | 155 |
user_info.status_of_attending_workshop = "3" |
107 | 156 |
user_info.has_laptop_for_workshop = True if has_laptop == "True" else False |
106 | 157 |
user_info.save() |
158 |
||
104
7630d7f3613a
added template for thanking for participation in workshop
nishanth
parents:
102
diff
changeset
|
159 |
return render_to_response("attending_wsp.html") |
95
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
160 |
else: |
102 | 161 |
return render_to_response("cnf_wsp_ptc.html", {"user":user}) |
95
ab554d46fd34
created basic view for confirmation of wsp participation
nishanth
parents:
93
diff
changeset
|
162 |
|
67 | 163 |
def admin_login(request): |
164 |
""" basic login. |
|
165 |
""" |
|
56 | 166 |
|
72 | 167 |
redirect_url = "/%s/registration/stats"%aup |
168 |
||
169 |
user = request.user |
|
170 |
if user.is_authenticated(): |
|
171 |
return redirect(redirect_url) |
|
172 |
||
67 | 173 |
if request.method == "POST": |
174 |
form = LoginForm(request.POST) |
|
175 |
if form.is_valid(): |
|
72 | 176 |
data = form.cleaned_data |
67 | 177 |
|
178 |
username = data['username'] |
|
179 |
password = data['password'] |
|
180 |
||
181 |
user = authenticate(username=username, password=password) |
|
182 |
login(request, user) |
|
72 | 183 |
return redirect(redirect_url) |
67 | 184 |
else: |
185 |
return render_to_response("login.html", {"form":form}) |
|
186 |
else: |
|
187 |
form = LoginForm() |
|
188 |
return render_to_response("login.html", {"form":form}) |
|
189 |
||
70 | 190 |
@login_required |
67 | 191 |
def admin_logout(request): |
192 |
""" simply logout. |
|
193 |
""" |
|
194 |
||
195 |
logout(request) |
|
196 |
return render_to_response("logout.html") |
|
56 | 197 |
|
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
198 |
def homepage(request): |
91 | 199 |
return render_to_response("index.html") |
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
200 |
|
31 | 201 |
def schedule(request): |
91 | 202 |
return render_to_response("schedule.html") |
31 | 203 |
|
204 |
def organizers(request): |
|
91 | 205 |
return render_to_response("organizers.html") |
31 | 206 |
|
207 |
def venue(request): |
|
91 | 208 |
return render_to_response("about_venue.html") |
31 | 209 |
|
210 |
def contact(request): |
|
91 | 211 |
return render_to_response("contact.html") |
31 | 212 |
|
213 |
def about(request): |
|
91 | 214 |
return render_to_response("about.html") |
48
a3e6f9470549
made some changes to links and added accomodation page.
anoop
parents:
31
diff
changeset
|
215 |
|
a3e6f9470549
made some changes to links and added accomodation page.
anoop
parents:
31
diff
changeset
|
216 |
def accomodation(request): |
91 | 217 |
return render_to_response("accomodation.html") |
84 | 218 |
|
219 |
def about_mumbai(request): |
|
220 |
return render_to_response("about_mumbai.html") |
|
221 |
||
222 |
def reaching_iitb(request): |
|
223 |
return render_to_response("reaching_iitb.html") |
|
91 | 224 |
|
225 |
def talks_proposed(request): |
|
226 |
return render_to_response("talks_proposed.html") |