author | nishanth |
Tue, 13 Apr 2010 12:03:12 +0530 | |
changeset 20 | 9354ef8119c6 |
parent 19 | 115860e87238 |
child 21 | a0f4aba61275 |
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 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
12 |
from workshop.reg.models import Event |
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: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
48 |
return render_to_response('account_inactive.html', {'user':user, '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 |
) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
79 |
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
|
80 |
else: |
15 | 81 |
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
|
82 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
83 |
form = reg_forms.RegisterForm() |
15 | 84 |
return render_to_response('register.html', {'form':form}) |
8 | 85 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
86 |
def account_created(request): |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
87 |
""" simply display a page. |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
88 |
""" |
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 |
user = request.user |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
91 |
return render_to_response('account_created.html', {'user':user}) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
92 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
93 |
def send_activation(request): |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
94 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
95 |
try: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
96 |
email = request.GET['email'] |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
97 |
except MultiValueDictKeyError: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
98 |
raise Http404 |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
99 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
100 |
try: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
101 |
user = User.objects.get(email__iexact=email) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
102 |
except User.DoesNotExist: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
103 |
raise Http404 |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
104 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
105 |
if user.is_active: |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
106 |
return redirect('/reg') |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
107 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
108 |
profile = user.get_profile() |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
109 |
activation_key = profile.activation_key |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
110 |
reg_events.send_activation(user) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
111 |
|
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
112 |
return render_to_response('sent_activationkey.html', {'user':user}) |
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
113 |
|
8 | 114 |
def create_event(request): |
115 |
""" see if the user is a staff and only then let him do it. |
|
116 |
""" |
|
117 |
||
118 |
user = request.user |
|
119 |
if user.is_authenticated() and user.is_staff: |
|
120 |
if request.method == "POST": |
|
121 |
form = reg_forms.EventCreateForm(request.POST) |
|
122 |
if form.is_valid(): |
|
123 |
data = form.cleaned_data |
|
124 |
new_event = reg_events.create_event(title=data['title'], |
|
125 |
description=data['description'], |
|
126 |
start_date=data['start_date'], |
|
127 |
stop_date=data['stop_date'], |
|
128 |
created_by=user, |
|
129 |
) |
|
130 |
event_url = "/reg/event/view/%s"%(new_event.key) |
|
131 |
return redirect(event_url) |
|
132 |
else: |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
133 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 134 |
else: |
135 |
form = reg_forms.EventCreateForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
136 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 137 |
else: |
138 |
return redirect('/reg') |
|
139 |
||
140 |
def view_event(request, key): |
|
141 |
""" get the event by its key and display it. |
|
142 |
""" |
|
143 |
||
144 |
user = request.user |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
145 |
user_ip = request.META['REMOTE_ADDR'] |
8 | 146 |
|
147 |
try: |
|
148 |
event = Event.objects.get(key__iexact=key) |
|
149 |
except Event.DoesNotExist: |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
150 |
return redirect("/reg") |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
151 |
|
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
is_org = True if user in event.organizers.all() else False |
8 | 155 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
156 |
can_submit_feedback = False |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
157 |
if not event.feedback_status == "0": |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
158 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
159 |
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
|
160 |
except Feedback.DoesNotExist: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
161 |
can_submit_feedback = True |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
162 |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
163 |
context = {'user': user, |
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
164 |
'is_guest': is_guest, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
165 |
'event': event, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
166 |
'is_attendee': is_attendee, |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
167 |
'is_org': is_org, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
168 |
'can_submit_feedback': can_submit_feedback, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
169 |
} |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
170 |
return render_to_response('view_event.html', context) |
8 | 171 |
|
9 | 172 |
def reset_password(request): |
173 |
""" check for the existance of e-mail. |
|
174 |
Then call the event. |
|
175 |
""" |
|
176 |
||
177 |
user = request.user |
|
178 |
if user.is_authenticated(): |
|
179 |
return redirect('/reg') |
|
180 |
||
181 |
if request.method == "POST": |
|
182 |
form = reg_forms.PasswordResetForm(request.POST) |
|
183 |
if form.is_valid(): |
|
184 |
email = form.cleaned_data['email'] |
|
185 |
user = User.objects.get(email__iexact=email) |
|
186 |
new_password = reg_events.reset_password(user) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
187 |
return render_to_response('password_reset.html', {'user':user, 'new_password':new_password}) |
9 | 188 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
189 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 190 |
else: |
191 |
form = reg_forms.PasswordResetForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
192 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 193 |
|
194 |
def change_password(request): |
|
195 |
""" check for the password and then set the new password. |
|
196 |
""" |
|
197 |
||
198 |
user = request.user |
|
199 |
if not user.is_authenticated(): |
|
200 |
return redirect('/reg') |
|
201 |
||
202 |
if request.method == "POST": |
|
203 |
data = request.POST.copy() |
|
204 |
data.__setitem__('username', user.username) |
|
205 |
form = reg_forms.PasswordChangeForm(data) |
|
206 |
if form.is_valid(): |
|
207 |
new_password = form.cleaned_data['new_password'] |
|
208 |
reg_events.change_password(user, new_password) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
209 |
return render_to_response('password_change.html', {'user':user, 'password_changed': True}) |
9 | 210 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
211 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 212 |
else: |
213 |
form = reg_forms.PasswordChangeForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
214 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 215 |
|
12 | 216 |
def open_feedback(request, event_key): |
217 |
""" see if the event exists. |
|
218 |
then see if feedback is closed. |
|
219 |
then give option for opening the feedback. |
|
220 |
Any feedback can be opened on any day. |
|
221 |
""" |
|
9 | 222 |
|
12 | 223 |
user = request.user |
224 |
try: |
|
225 |
event = Event.objects.get(key__iexact=event_key) |
|
226 |
except Event.DoesNotExist: |
|
227 |
return redirect("/reg") |
|
9 | 228 |
|
12 | 229 |
is_org = True if user in event.organizers.all() else False |
9 | 230 |
|
12 | 231 |
if is_org and event.feedback_status == '0': |
232 |
#days = event.stop_date.day() - event.start_date.day() + 1 |
|
233 |
days = 2 |
|
234 |
if request.method == "POST": |
|
235 |
day = request.POST['day'] |
|
236 |
event.feedback_status = day |
|
237 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
238 |
return render_to_response('open_feedback.html', {'user':user, 'success': True, 'day':day, 'event':event}) |
12 | 239 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
240 |
return render_to_response('open_feedback.html', {'user':user, 'event': event, 'days': range(1,days+1)}) |
12 | 241 |
else: |
242 |
return redirect('/reg') |
|
9 | 243 |
|
12 | 244 |
def close_feedback(request, event_key): |
245 |
""" check if the user is org. |
|
246 |
and then check if the feedback is open already. |
|
247 |
""" |
|
9 | 248 |
|
12 | 249 |
user = request.user |
250 |
try: |
|
251 |
event = Event.objects.get(key__iexact=event_key) |
|
252 |
except Event.DoesNotExist: |
|
253 |
return redirect("/reg") |
|
254 |
||
255 |
is_org = True if user in event.organizers.all() else False |
|
256 |
||
257 |
if is_org: |
|
258 |
day = event.feedback_status |
|
259 |
event.feedback_status = '0' |
|
260 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
261 |
return render_to_response('close_feedback.html', {'user':user, 'event': event, 'day':day}) |
12 | 262 |
else: |
263 |
return redirect('/reg') |
|
264 |
||
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
265 |
def open_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
266 |
""" 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
|
267 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
268 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
269 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
270 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
271 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
272 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
273 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
274 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
275 |
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
|
276 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
277 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
278 |
event.registration_is_open = True |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
279 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
280 |
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
|
281 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
282 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
283 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
284 |
def close_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
285 |
""" 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
|
286 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
287 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
288 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
289 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
290 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
291 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
292 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
293 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
294 |
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
|
295 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
296 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
297 |
event.registration_is_open = False |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
298 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
299 |
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
|
300 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
301 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
302 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
303 |
def register_for_event(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
304 |
""" check if the user is logged in. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
305 |
simply add him to the attendees list. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
306 |
""" |
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 |
user = request.user |
20
9354ef8119c6
added account_inactive and resend_activationkey functionalities
nishanth
parents:
19
diff
changeset
|
309 |
if user.is_authenticated() and user.is_active: |
13
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 |
event.attendees.add(user) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
316 |
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
|
317 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
318 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
319 |
|
17 | 320 |
def view_profile(request): |
321 |
""" check if user is logged in. |
|
322 |
then show the profile. |
|
323 |
""" |
|
324 |
||
325 |
user = request.user |
|
326 |
if not user.is_authenticated(): |
|
327 |
return redirect('/reg') |
|
328 |
||
329 |
user_profile = user.get_profile() |
|
330 |
return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile}) |
|
331 |
||
332 |
def edit_profile(request): |
|
333 |
""" check if user is logged in. |
|
334 |
""" |
|
335 |
||
336 |
user = request.user |
|
337 |
if not user.is_authenticated(): |
|
338 |
return redirect('/reg') |
|
339 |
||
340 |
user_profile = user.get_profile() |
|
341 |
||
342 |
if request.method == "POST": |
|
343 |
form = reg_forms.EditProfileForm(request.POST) |
|
344 |
if form.is_valid(): |
|
345 |
reg_events.update_profile(user, form.cleaned_data) |
|
346 |
return redirect('/reg/profile/view') |
|
347 |
else: |
|
348 |
return render_to_response('edit_profile.html', {'user':user, 'form':form}) |
|
349 |
else: |
|
350 |
old_info = {'first_name': user.first_name, |
|
351 |
'last_name': user.last_name, |
|
352 |
'gender':user_profile.gender, |
|
353 |
'profession': user_profile.profession, |
|
354 |
'affiliated_to': user_profile.affiliated_to, |
|
355 |
'interests': user_profile.interests, |
|
356 |
} |
|
357 |
form = reg_forms.EditProfileForm(old_info) |
|
358 |
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
|
359 |
|
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
360 |
def list_events(request): |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
361 |
""" 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
|
362 |
""" |
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
363 |
|
18
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
364 |
user = request.user |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
365 |
|
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
366 |
today = datetime.now() |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
367 |
context = {'user':user, |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
368 |
'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
|
369 |
'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
|
370 |
'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
|
371 |
} |
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
372 |
|
7dae32a2439b
prettified the home page and moved workshops to another page called workshops.
nishanth
parents:
17
diff
changeset
|
373 |
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
|
374 |
|
19 | 375 |
def list_attendees(request, event_key): |
376 |
""" see if the request user is org. |
|
377 |
Else redirect him to homepage. |
|
378 |
""" |
|
379 |
||
380 |
user = request.user |
|
381 |
try: |
|
382 |
event = Event.objects.get(key__iexact=event_key) |
|
383 |
except Event.DoesNotExist: |
|
384 |
return redirect('/reg') |
|
385 |
||
386 |
if not user in event.organizers.all(): |
|
387 |
return redirect('/reg') |
|
388 |
||
389 |
profile = user.get_profile() |
|
390 |
return render_to_response('list_attendees.html', {'user':user, 'event':event, 'attendees':event.attendees.all()}) |