author | nishanth |
Tue, 13 Apr 2010 14:54:06 +0530 | |
changeset 28 | 14c5ccb18159 |
parent 27 | ea6aef4b379d |
child 29 | 5fb4edd157e1 |
permissions | -rw-r--r-- |
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
1 |
from datetime import datetime |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
2 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
3 |
from django.http import Http404 |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
4 |
from django.utils.datastructures import MultiValueDictKeyError |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
5 |
|
4 | 6 |
from django.contrib.auth.models import User |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
7 |
from django.contrib.auth import authenticate, login, logout |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
8 |
from django.contrib.auth.decorators import login_required |
2 | 9 |
|
4 | 10 |
from django.shortcuts import render_to_response, redirect |
11 |
||
23 | 12 |
from workshop.reg.models import Event, Profile |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
13 |
from workshop.reg import forms as reg_forms |
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
14 |
from workshop.reg import events as reg_events |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
15 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
16 |
from workshop.feedback.models import Feedback |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
17 |
|
4 | 18 |
def homepage(request): |
19 |
""" see if the user is active. |
|
20 |
If not, only show the re send activation email link. |
|
21 |
else show all the options in homepage. |
|
22 |
""" |
|
23 |
||
24 |
user = request.user |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
25 |
|
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
26 |
return render_to_response('index.html', {'user':user}) |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
27 |
|
4 | 28 |
def user_login(request): |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
29 |
""" get the user object from e-mail and then check for password. |
2 | 30 |
""" |
31 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
32 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
33 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
34 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
35 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
36 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
37 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
38 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
39 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
40 |
password = form.cleaned_data['password'] |
4 | 41 |
username = User.objects.get(email__iexact=email).username |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
42 |
|
4 | 43 |
user = authenticate(username=username, password=password) |
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
44 |
if user.is_active: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
45 |
login(request, user) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
46 |
return redirect('/reg') |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
47 |
else: |
25 | 48 |
return render_to_response('account_inactive.html', {'email':email}) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
49 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
50 |
return render_to_response('login.html', {'user':user, 'form':form}) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
51 |
else: |
4 | 52 |
form = reg_forms.LoginForm() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
53 |
return render_to_response('login.html', {'user':user, 'form':form}) |
4 | 54 |
|
55 |
def user_logout(request): |
|
56 |
""" simply logout the user and redirect to homepage. |
|
57 |
""" |
|
58 |
||
59 |
logout(request) |
|
60 |
return redirect('/reg') |
|
61 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
62 |
def user_register(request): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
63 |
""" take the credentials like name, college and gender here itself. |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
64 |
""" |
4 | 65 |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
66 |
if request.method == "POST": |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
67 |
form = reg_forms.RegisterForm(request.POST) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
68 |
if form.is_valid(): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
69 |
data = form.cleaned_data |
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
70 |
new_user = reg_events.create_user(email=data['email'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
71 |
password=data['password'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
72 |
first_name=data['first_name'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
73 |
last_name=data['last_name'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
74 |
gender=data['gender'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
75 |
profession=data['profession'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
76 |
affiliated_to=data['affiliated_to'], |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
77 |
interests=data['interests'] |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
78 |
) |
23 | 79 |
reg_events.send_activation(new_user) |
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
80 |
return redirect('/reg/account_created') |
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
81 |
else: |
15 | 82 |
return render_to_response('register.html', {'form':form}) |
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
83 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
84 |
form = reg_forms.RegisterForm() |
15 | 85 |
return render_to_response('register.html', {'form':form}) |
8 | 86 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
87 |
def account_created(request): |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
88 |
""" simply display a page. |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
89 |
""" |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
90 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
91 |
user = request.user |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
92 |
return render_to_response('account_created.html', {'user':user}) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
93 |
|
23 | 94 |
def account_activate(request, activation_key): |
95 |
""" see if the key exists. |
|
96 |
see if the corresponding user is inactive. |
|
97 |
""" |
|
98 |
||
99 |
user = request.user |
|
100 |
if user.is_authenticated(): |
|
101 |
return redirect('/reg') |
|
102 |
||
103 |
try: |
|
104 |
profile = Profile.objects.get(activation_key__iexact=activation_key) |
|
105 |
except Profile.DoesNotExist: |
|
106 |
raise Http404 |
|
107 |
||
108 |
user = profile.user |
|
109 |
reg_events.activate_user(user) |
|
110 |
return render_to_response('account_activated.html', {'user':user}) |
|
111 |
||
21 | 112 |
def resend_activation(request): |
23 | 113 |
""" resend only if user is registered and is inactive. |
114 |
""" |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
115 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
116 |
try: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
117 |
email = request.GET['email'] |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
118 |
except MultiValueDictKeyError: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
119 |
raise Http404 |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
120 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
121 |
try: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
122 |
user = User.objects.get(email__iexact=email) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
123 |
except User.DoesNotExist: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
124 |
raise Http404 |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
125 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
126 |
if user.is_active: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
127 |
return redirect('/reg') |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
128 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
129 |
profile = user.get_profile() |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
130 |
activation_key = profile.activation_key |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
131 |
reg_events.send_activation(user) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
132 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
133 |
return render_to_response('sent_activationkey.html', {'user':user}) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
134 |
|
8 | 135 |
def create_event(request): |
136 |
""" see if the user is a staff and only then let him do it. |
|
137 |
""" |
|
138 |
||
139 |
user = request.user |
|
140 |
if user.is_authenticated() and user.is_staff: |
|
141 |
if request.method == "POST": |
|
142 |
form = reg_forms.EventCreateForm(request.POST) |
|
143 |
if form.is_valid(): |
|
144 |
data = form.cleaned_data |
|
145 |
new_event = reg_events.create_event(title=data['title'], |
|
146 |
description=data['description'], |
|
147 |
start_date=data['start_date'], |
|
148 |
stop_date=data['stop_date'], |
|
149 |
created_by=user, |
|
150 |
) |
|
151 |
event_url = "/reg/event/view/%s"%(new_event.key) |
|
152 |
return redirect(event_url) |
|
153 |
else: |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
154 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 155 |
else: |
156 |
form = reg_forms.EventCreateForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
157 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 158 |
else: |
159 |
return redirect('/reg') |
|
160 |
||
161 |
def view_event(request, key): |
|
162 |
""" get the event by its key and display it. |
|
163 |
""" |
|
164 |
||
165 |
user = request.user |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
166 |
user_ip = request.META['REMOTE_ADDR'] |
8 | 167 |
|
168 |
try: |
|
169 |
event = Event.objects.get(key__iexact=key) |
|
170 |
except Event.DoesNotExist: |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
171 |
return redirect("/reg") |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
172 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
173 |
is_guest = False if user.is_authenticated() and user.is_active else True |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
174 |
is_attendee = True if user in event.attendees.all() else False |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
175 |
is_org = True if user in event.organizers.all() else False |
8 | 176 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
177 |
can_submit_feedback = False |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
178 |
if not event.feedback_status == "0": |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
179 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
180 |
event.feedback.get(user_ip__iexact=user_ip, day=event.feedback_status) |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
181 |
except Feedback.DoesNotExist: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
182 |
can_submit_feedback = True |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
183 |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
184 |
context = {'user': user, |
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
185 |
'is_guest': is_guest, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
186 |
'event': event, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
187 |
'is_attendee': is_attendee, |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
188 |
'is_org': is_org, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
189 |
'can_submit_feedback': can_submit_feedback, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
190 |
} |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
191 |
return render_to_response('view_event.html', context) |
8 | 192 |
|
9 | 193 |
def reset_password(request): |
194 |
""" check for the existance of e-mail. |
|
195 |
Then call the event. |
|
196 |
""" |
|
197 |
||
198 |
user = request.user |
|
199 |
if user.is_authenticated(): |
|
200 |
return redirect('/reg') |
|
201 |
||
202 |
if request.method == "POST": |
|
203 |
form = reg_forms.PasswordResetForm(request.POST) |
|
204 |
if form.is_valid(): |
|
205 |
email = form.cleaned_data['email'] |
|
206 |
user = User.objects.get(email__iexact=email) |
|
207 |
new_password = reg_events.reset_password(user) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
208 |
return render_to_response('password_reset.html', {'user':user, 'new_password':new_password}) |
9 | 209 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
210 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 211 |
else: |
212 |
form = reg_forms.PasswordResetForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
213 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 214 |
|
215 |
def change_password(request): |
|
216 |
""" check for the password and then set the new password. |
|
217 |
""" |
|
218 |
||
219 |
user = request.user |
|
220 |
if not user.is_authenticated(): |
|
221 |
return redirect('/reg') |
|
222 |
||
223 |
if request.method == "POST": |
|
224 |
data = request.POST.copy() |
|
225 |
data.__setitem__('username', user.username) |
|
226 |
form = reg_forms.PasswordChangeForm(data) |
|
227 |
if form.is_valid(): |
|
228 |
new_password = form.cleaned_data['new_password'] |
|
229 |
reg_events.change_password(user, new_password) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
230 |
return render_to_response('password_change.html', {'user':user, 'password_changed': True}) |
9 | 231 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
232 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 233 |
else: |
234 |
form = reg_forms.PasswordChangeForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
235 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 236 |
|
12 | 237 |
def open_feedback(request, event_key): |
238 |
""" see if the event exists. |
|
239 |
then see if feedback is closed. |
|
240 |
then give option for opening the feedback. |
|
241 |
Any feedback can be opened on any day. |
|
242 |
""" |
|
9 | 243 |
|
12 | 244 |
user = request.user |
245 |
try: |
|
246 |
event = Event.objects.get(key__iexact=event_key) |
|
247 |
except Event.DoesNotExist: |
|
248 |
return redirect("/reg") |
|
9 | 249 |
|
28
14c5ccb18159
now opening and closing of feedback quiz and registration can be done only by staff users .
nishanth
parents:
27
diff
changeset
|
250 |
can_do_this = True if user in event.organizers.all() and user.is_staff else False |
9 | 251 |
|
28
14c5ccb18159
now opening and closing of feedback quiz and registration can be done only by staff users .
nishanth
parents:
27
diff
changeset
|
252 |
if can_do_this and event.feedback_status == '0': |
12 | 253 |
#days = event.stop_date.day() - event.start_date.day() + 1 |
254 |
days = 2 |
|
255 |
if request.method == "POST": |
|
256 |
day = request.POST['day'] |
|
257 |
event.feedback_status = day |
|
258 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
259 |
return render_to_response('open_feedback.html', {'user':user, 'success': True, 'day':day, 'event':event}) |
12 | 260 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
261 |
return render_to_response('open_feedback.html', {'user':user, 'event': event, 'days': range(1,days+1)}) |
12 | 262 |
else: |
27 | 263 |
raise Http404 |
9 | 264 |
|
12 | 265 |
def close_feedback(request, event_key): |
266 |
""" check if the user is org. |
|
267 |
and then check if the feedback is open already. |
|
268 |
""" |
|
9 | 269 |
|
12 | 270 |
user = request.user |
271 |
try: |
|
272 |
event = Event.objects.get(key__iexact=event_key) |
|
273 |
except Event.DoesNotExist: |
|
274 |
return redirect("/reg") |
|
275 |
||
276 |
is_org = True if user in event.organizers.all() else False |
|
277 |
||
278 |
if is_org: |
|
279 |
day = event.feedback_status |
|
280 |
event.feedback_status = '0' |
|
281 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
282 |
return render_to_response('close_feedback.html', {'user':user, 'event': event, 'day':day}) |
12 | 283 |
else: |
284 |
return redirect('/reg') |
|
285 |
||
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
286 |
def open_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
287 |
""" simply check for is_org and then set the registration_is_open flag. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
288 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
289 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
290 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
291 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
292 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
293 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
294 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
295 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
296 |
is_org = True if user in event.organizers.all() else False |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
297 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
298 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
299 |
event.registration_is_open = True |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
300 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
301 |
return render_to_response('reg_open.html', {'user':user, 'event': event}) |
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
302 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
303 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
304 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
305 |
def close_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
306 |
""" simply check for is_org and then unset the registration_is_open flag. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
307 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
308 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
309 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
310 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
311 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
312 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
313 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
314 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
315 |
is_org = True if user in event.organizers.all() else False |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
316 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
317 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
318 |
event.registration_is_open = False |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
319 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
320 |
return render_to_response('reg_close.html', {'user':user, 'event': event}) |
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
321 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
322 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
323 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
324 |
def register_for_event(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
325 |
""" check if the user is logged in. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
326 |
simply add him to the attendees list. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
327 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
328 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
329 |
user = request.user |
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
330 |
if user.is_authenticated() and user.is_active: |
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
331 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
332 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
333 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
334 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
335 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
336 |
event.attendees.add(user) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
337 |
return render_to_response("event_register.html", {"user":user, 'event':event}) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
338 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
339 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
340 |
|
17 | 341 |
def view_profile(request): |
342 |
""" check if user is logged in. |
|
343 |
then show the profile. |
|
344 |
""" |
|
345 |
||
346 |
user = request.user |
|
347 |
if not user.is_authenticated(): |
|
348 |
return redirect('/reg') |
|
349 |
||
350 |
user_profile = user.get_profile() |
|
351 |
return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile}) |
|
352 |
||
353 |
def edit_profile(request): |
|
354 |
""" check if user is logged in. |
|
355 |
""" |
|
356 |
||
357 |
user = request.user |
|
358 |
if not user.is_authenticated(): |
|
359 |
return redirect('/reg') |
|
360 |
||
361 |
user_profile = user.get_profile() |
|
362 |
||
363 |
if request.method == "POST": |
|
364 |
form = reg_forms.EditProfileForm(request.POST) |
|
365 |
if form.is_valid(): |
|
366 |
reg_events.update_profile(user, form.cleaned_data) |
|
367 |
return redirect('/reg/profile/view') |
|
368 |
else: |
|
369 |
return render_to_response('edit_profile.html', {'user':user, 'form':form}) |
|
370 |
else: |
|
371 |
old_info = {'first_name': user.first_name, |
|
372 |
'last_name': user.last_name, |
|
373 |
'gender':user_profile.gender, |
|
374 |
'profession': user_profile.profession, |
|
375 |
'affiliated_to': user_profile.affiliated_to, |
|
376 |
'interests': user_profile.interests, |
|
377 |
} |
|
378 |
form = reg_forms.EditProfileForm(old_info) |
|
379 |
return render_to_response('edit_profile.html', {'user':user, 'form':form}) |
|
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
380 |
|
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
381 |
def list_events(request): |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
382 |
""" Get all the events including those that are over and list them. |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
383 |
""" |
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
384 |
|
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
385 |
user = request.user |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
386 |
|
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
387 |
today = datetime.now() |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
388 |
context = {'user':user, |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
389 |
'upcoming_events': Event.objects.filter(start_date__gt=today), |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
390 |
'ongoing_events': Event.objects.filter(start_date__lte=today, stop_date__gte=today), |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
391 |
'previous_events': Event.objects.filter(stop_date__lt=today), |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
392 |
} |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
393 |
|
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
394 |
return render_to_response('list_events.html', context) |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
395 |
|
19 | 396 |
def list_attendees(request, event_key): |
397 |
""" see if the request user is org. |
|
398 |
Else redirect him to homepage. |
|
399 |
""" |
|
400 |
||
401 |
user = request.user |
|
402 |
try: |
|
403 |
event = Event.objects.get(key__iexact=event_key) |
|
404 |
except Event.DoesNotExist: |
|
405 |
return redirect('/reg') |
|
406 |
||
407 |
if not user in event.organizers.all(): |
|
408 |
return redirect('/reg') |
|
409 |
||
410 |
profile = user.get_profile() |
|
411 |
return render_to_response('list_attendees.html', {'user':user, 'event':event, 'attendees':event.attendees.all()}) |