author | nishanth |
Mon, 07 Jun 2010 15:39:33 +0530 | |
branch | anoop |
changeset 67 | b9690fbf78af |
parent 65 | 0ca63c964237 |
child 70 | 58cafee2ee89 |
permissions | -rw-r--r-- |
15 | 1 |
from django.shortcuts import render_to_response, redirect |
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
2 |
from django.http import HttpResponse |
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 |
7 | 4 |
|
67 | 5 |
from django.contrib.auth import authenticate, login, logout |
6 |
||
7 | 7 |
from sage_days.sdi.models import Registrant |
67 | 8 |
from sage_days.sdi.forms import RegisterForm, SearchForm, EmailForm, LoginForm |
56 | 9 |
from sage_days.sdi.events import send_reg_complete_mail, mail_invi |
7 | 10 |
|
11 |
def register(request): |
|
12 |
""" The user register page. |
|
13 |
""" |
|
14 |
||
9 | 15 |
if request.method == "POST": |
14 | 16 |
form = RegisterForm(request.POST) |
17 |
if form.is_valid(): |
|
15 | 18 |
form.save() |
53 | 19 |
|
20 |
data = form.cleaned_data |
|
21 |
first_name = data['first_name'] |
|
22 |
last_name = data['last_name'] |
|
23 |
email = data['email'] |
|
24 |
send_reg_complete_mail(email, first_name, last_name) |
|
25 |
||
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
26 |
return redirect("/sage_days/registration/complete") |
14 | 27 |
else: |
28 |
return render_to_response("register.html", {"form":form}) |
|
9 | 29 |
else: |
30 |
form = RegisterForm() |
|
31 |
return render_to_response("register.html", {"form":form}) |
|
22 | 32 |
|
33 |
def reg_complete(request): |
|
34 |
""" Tell the registration is successful. |
|
35 |
""" |
|
36 |
||
37 |
return render_to_response("reg_complete.html") |
|
23 | 38 |
|
65
0ca63c964237
now login is required for accessing stats and send_invi pages
nishanth
parents:
57
diff
changeset
|
39 |
@login_required |
23 | 40 |
def list_stats(request): |
41 |
""" List the statiscs of registered participants. |
|
42 |
""" |
|
43 |
||
24
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
44 |
if request.method == "POST": |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
45 |
form = SearchForm(request.POST) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
46 |
if form.is_valid(): |
25 | 47 |
data = form.cleaned_data |
48 |
need_workshop = data['need_for_python_workshop'] |
|
49 |
db_query = "Registrant.objects.filter(need_for_python_workshop=%s)"%need_workshop |
|
50 |
||
51 |
topics_include, topics_exclude = data['topics_interested'] |
|
52 |
for number in topics_include: |
|
53 |
db_query += '.filter(topics_interested__contains="%s")'%number |
|
54 |
||
55 |
for number in topics_exclude: |
|
56 |
db_query += '.exclude(topics_interested__contains="%s")'%number |
|
57 |
||
58 |
start_python, stop_python = data['knowledge_of_python'] |
|
59 |
if start_python and stop_python: |
|
60 |
db_query += '.filter(knowledge_of_python__gte="%s")'%start_python |
|
61 |
db_query += '.filter(knowledge_of_python__lte="%s")'%stop_python |
|
62 |
elif start_python: |
|
63 |
db_query += '.filter(knowledge_of_python__exact="%s")'%start_python |
|
64 |
||
65 |
start_sage, stop_sage = data['knowledge_of_sage'] |
|
66 |
if start_sage and stop_sage: |
|
67 |
db_query += '.filter(knowledge_of_sage__gte="%s")'%start_sage |
|
68 |
db_query += '.filter(knowledge_of_sage__lte="%s")'%stop_sage |
|
69 |
elif start_sage: |
|
70 |
db_query += '.filter(knowledge_of_sage__exact="%s")'%start_sage |
|
71 |
||
72 |
start_likeliness, stop_likeliness = data['likeliness_of_attending'] |
|
73 |
if start_likeliness and stop_likeliness: |
|
74 |
db_query += '.filter(likeliness_of_attending__gte="%s")'%start_likeliness |
|
75 |
db_query += '.filter(likeliness_of_attending__lte="%s")'%stop_likeliness |
|
76 |
elif start_likeliness: |
|
77 |
db_query += '.filter(likeliness_of_attending__exact="%s")'%start_likeliness |
|
78 |
||
79 |
matches = eval(db_query) |
|
80 |
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
|
81 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
82 |
return render_to_response("list_stats.html", {"form":form}) |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
83 |
else: |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
84 |
form = SearchForm() |
f79be1dd4a22
added clean methods for each attribute in search form
nishanth
parents:
23
diff
changeset
|
85 |
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
|
86 |
|
65
0ca63c964237
now login is required for accessing stats and send_invi pages
nishanth
parents:
57
diff
changeset
|
87 |
@login_required |
56 | 88 |
def send_invi(request): |
89 |
""" Take a list of csv email addresses and send mails to them. |
|
90 |
""" |
|
91 |
||
92 |
if request.method == "POST": |
|
93 |
form = EmailForm(request.POST) |
|
94 |
if form.is_valid(): |
|
95 |
to_emails = form.cleaned_data['emails'] |
|
96 |
mail_invi(to_emails) |
|
97 |
return render_to_response("send_invi.html", {"emails":to_emails}) |
|
98 |
else: |
|
99 |
return render_to_response("send_invi.html", {"form":form}) |
|
100 |
else: |
|
57 | 101 |
form = EmailForm() |
56 | 102 |
return render_to_response("send_invi.html", {"form":form}) |
103 |
||
67 | 104 |
def admin_login(request): |
105 |
""" basic login. |
|
106 |
""" |
|
56 | 107 |
|
67 | 108 |
if request.method == "POST": |
109 |
form = LoginForm(request.POST) |
|
110 |
if form.is_valid(): |
|
111 |
data = form.cleaned_data() |
|
112 |
||
113 |
username = data['username'] |
|
114 |
password = data['password'] |
|
115 |
||
116 |
user = authenticate(username=username, password=password) |
|
117 |
login(request, user) |
|
118 |
return redirect("/registration/stats") |
|
119 |
else: |
|
120 |
return render_to_response("login.html", {"form":form}) |
|
121 |
else: |
|
122 |
form = LoginForm() |
|
123 |
return render_to_response("login.html", {"form":form}) |
|
124 |
||
125 |
def admin_logout(request): |
|
126 |
""" simply logout. |
|
127 |
""" |
|
128 |
||
129 |
logout(request) |
|
130 |
return render_to_response("logout.html") |
|
56 | 131 |
|
26
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
132 |
def homepage(request): |
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
133 |
return render_to_response("index.html") |
212fcba4459e
changed the app to work with apache + added base.html, and did needed changes.
anoop
parents:
25
diff
changeset
|
134 |
|
31 | 135 |
def schedule(request): |
136 |
return render_to_response("schedule.html") |
|
137 |
||
138 |
def organizers(request): |
|
139 |
return render_to_response("organizers.html") |
|
140 |
||
141 |
def venue(request): |
|
142 |
return render_to_response("venue.html") |
|
143 |
||
144 |
def contact(request): |
|
145 |
return render_to_response("contact.html") |
|
146 |
||
147 |
def about(request): |
|
148 |
return render_to_response("about.html") |
|
48
a3e6f9470549
made some changes to links and added accomodation page.
anoop
parents:
31
diff
changeset
|
149 |
|
a3e6f9470549
made some changes to links and added accomodation page.
anoop
parents:
31
diff
changeset
|
150 |
def accomodation(request): |
a3e6f9470549
made some changes to links and added accomodation page.
anoop
parents:
31
diff
changeset
|
151 |
return render_to_response("accomodation.html") |