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