author | nishanth |
Mon, 12 Apr 2010 16:17:53 +0530 | |
changeset 17 | 125b6fc8f20b |
parent 16 | bef53aaf9085 |
child 18 | 7dae32a2439b |
permissions | -rw-r--r-- |
4 | 1 |
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
|
2 |
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
|
3 |
from django.contrib.auth.decorators import login_required |
2 | 4 |
|
4 | 5 |
from django.shortcuts import render_to_response, redirect |
6 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
7 |
from workshop.reg.models import Event |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
8 |
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
|
9 |
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
|
10 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
11 |
from workshop.feedback.models import Feedback |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
12 |
|
4 | 13 |
from django.http import HttpResponse |
14 |
||
15 |
def homepage(request): |
|
16 |
""" see if the user is active. |
|
17 |
If not, only show the re send activation email link. |
|
18 |
else show all the options in homepage. |
|
19 |
""" |
|
20 |
||
21 |
user = request.user |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
22 |
events = Event.objects.all()[:10] |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
23 |
|
17 | 24 |
return render_to_response('index.html', {'user':user, 'events':events}) |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
25 |
|
4 | 26 |
def user_login(request): |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
27 |
""" get the user object from e-mail and then check for password. |
2 | 28 |
""" |
29 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
30 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
31 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
32 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
33 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
34 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
35 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
36 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
37 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
38 |
password = form.cleaned_data['password'] |
4 | 39 |
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
|
40 |
|
4 | 41 |
user = authenticate(username=username, password=password) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
42 |
login(request, user) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
43 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
44 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
45 |
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
|
46 |
else: |
4 | 47 |
form = reg_forms.LoginForm() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
48 |
return render_to_response('login.html', {'user':user, 'form':form}) |
4 | 49 |
|
50 |
def user_logout(request): |
|
51 |
""" simply logout the user and redirect to homepage. |
|
52 |
""" |
|
53 |
||
54 |
logout(request) |
|
55 |
return redirect('/reg') |
|
56 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
57 |
def user_register(request): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
58 |
""" 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
|
59 |
""" |
4 | 60 |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
61 |
if request.method == "POST": |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
62 |
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
|
63 |
if form.is_valid(): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
64 |
data = form.cleaned_data |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
65 |
reg_events.create_user(email=data['email'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
66 |
password=data['password'], |
17 | 67 |
first_name=data['first_name'], |
68 |
last_name=data['last_name'], |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
69 |
gender=data['gender'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
70 |
profession=data['profession'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
71 |
affiliated_to=data['affiliated_to'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
72 |
interests=data['interests'] |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
73 |
) |
15 | 74 |
return render_to_response('account_created.html') |
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
75 |
else: |
15 | 76 |
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
|
77 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
78 |
form = reg_forms.RegisterForm() |
15 | 79 |
return render_to_response('register.html', {'form':form}) |
8 | 80 |
|
81 |
def create_event(request): |
|
82 |
""" see if the user is a staff and only then let him do it. |
|
83 |
""" |
|
84 |
||
85 |
user = request.user |
|
86 |
if user.is_authenticated() and user.is_staff: |
|
87 |
if request.method == "POST": |
|
88 |
form = reg_forms.EventCreateForm(request.POST) |
|
89 |
if form.is_valid(): |
|
90 |
data = form.cleaned_data |
|
91 |
new_event = reg_events.create_event(title=data['title'], |
|
92 |
description=data['description'], |
|
93 |
start_date=data['start_date'], |
|
94 |
stop_date=data['stop_date'], |
|
95 |
created_by=user, |
|
96 |
) |
|
97 |
event_url = "/reg/event/view/%s"%(new_event.key) |
|
98 |
return redirect(event_url) |
|
99 |
else: |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
100 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 101 |
else: |
102 |
form = reg_forms.EventCreateForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
103 |
return render_to_response('event_create.html', {'user':user, 'form':form}) |
8 | 104 |
else: |
105 |
return redirect('/reg') |
|
106 |
||
107 |
def view_event(request, key): |
|
108 |
""" get the event by its key and display it. |
|
109 |
""" |
|
110 |
||
111 |
user = request.user |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
112 |
user_ip = request.META['REMOTE_ADDR'] |
8 | 113 |
|
114 |
try: |
|
115 |
event = Event.objects.get(key__iexact=key) |
|
116 |
except Event.DoesNotExist: |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
117 |
return redirect("/reg") |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
118 |
|
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
119 |
is_guest = False if user.is_authenticated() else True |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
120 |
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
|
121 |
is_org = True if user in event.organizers.all() else False |
8 | 122 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
123 |
can_submit_feedback = False |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
124 |
if not event.feedback_status == "0": |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
125 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
126 |
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
|
127 |
except Feedback.DoesNotExist: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
128 |
can_submit_feedback = True |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
129 |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
130 |
context = {'user': user, |
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
131 |
'is_guest': is_guest, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
132 |
'event': event, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
133 |
'is_attendee': is_attendee, |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
134 |
'is_org': is_org, |
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
135 |
'can_submit_feedback': can_submit_feedback, |
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
136 |
} |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
137 |
return render_to_response('view_event.html', context) |
8 | 138 |
|
9 | 139 |
def reset_password(request): |
140 |
""" check for the existance of e-mail. |
|
141 |
Then call the event. |
|
142 |
""" |
|
143 |
||
144 |
user = request.user |
|
145 |
if user.is_authenticated(): |
|
146 |
return redirect('/reg') |
|
147 |
||
148 |
if request.method == "POST": |
|
149 |
form = reg_forms.PasswordResetForm(request.POST) |
|
150 |
if form.is_valid(): |
|
151 |
email = form.cleaned_data['email'] |
|
152 |
user = User.objects.get(email__iexact=email) |
|
153 |
new_password = reg_events.reset_password(user) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
154 |
return render_to_response('password_reset.html', {'user':user, 'new_password':new_password}) |
9 | 155 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
156 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 157 |
else: |
158 |
form = reg_forms.PasswordResetForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
159 |
return render_to_response('password_reset.html', {'user':user, 'form':form}) |
9 | 160 |
|
161 |
def change_password(request): |
|
162 |
""" check for the password and then set the new password. |
|
163 |
""" |
|
164 |
||
165 |
user = request.user |
|
166 |
if not user.is_authenticated(): |
|
167 |
return redirect('/reg') |
|
168 |
||
169 |
if request.method == "POST": |
|
170 |
data = request.POST.copy() |
|
171 |
data.__setitem__('username', user.username) |
|
172 |
form = reg_forms.PasswordChangeForm(data) |
|
173 |
if form.is_valid(): |
|
174 |
new_password = form.cleaned_data['new_password'] |
|
175 |
reg_events.change_password(user, new_password) |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
176 |
return render_to_response('password_change.html', {'user':user, 'password_changed': True}) |
9 | 177 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
178 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 179 |
else: |
180 |
form = reg_forms.PasswordChangeForm() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
181 |
return render_to_response('password_change.html', {'user':user, 'form':form}) |
9 | 182 |
|
12 | 183 |
def open_feedback(request, event_key): |
184 |
""" see if the event exists. |
|
185 |
then see if feedback is closed. |
|
186 |
then give option for opening the feedback. |
|
187 |
Any feedback can be opened on any day. |
|
188 |
""" |
|
9 | 189 |
|
12 | 190 |
user = request.user |
191 |
try: |
|
192 |
event = Event.objects.get(key__iexact=event_key) |
|
193 |
except Event.DoesNotExist: |
|
194 |
return redirect("/reg") |
|
9 | 195 |
|
12 | 196 |
is_org = True if user in event.organizers.all() else False |
9 | 197 |
|
12 | 198 |
if is_org and event.feedback_status == '0': |
199 |
#days = event.stop_date.day() - event.start_date.day() + 1 |
|
200 |
days = 2 |
|
201 |
if request.method == "POST": |
|
202 |
day = request.POST['day'] |
|
203 |
event.feedback_status = day |
|
204 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
205 |
return render_to_response('open_feedback.html', {'user':user, 'success': True, 'day':day, 'event':event}) |
12 | 206 |
else: |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
207 |
return render_to_response('open_feedback.html', {'user':user, 'event': event, 'days': range(1,days+1)}) |
12 | 208 |
else: |
209 |
return redirect('/reg') |
|
9 | 210 |
|
12 | 211 |
def close_feedback(request, event_key): |
212 |
""" check if the user is org. |
|
213 |
and then check if the feedback is open already. |
|
214 |
""" |
|
9 | 215 |
|
12 | 216 |
user = request.user |
217 |
try: |
|
218 |
event = Event.objects.get(key__iexact=event_key) |
|
219 |
except Event.DoesNotExist: |
|
220 |
return redirect("/reg") |
|
221 |
||
222 |
is_org = True if user in event.organizers.all() else False |
|
223 |
||
224 |
if is_org: |
|
225 |
day = event.feedback_status |
|
226 |
event.feedback_status = '0' |
|
227 |
event.save() |
|
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
228 |
return render_to_response('close_feedback.html', {'user':user, 'event': event, 'day':day}) |
12 | 229 |
else: |
230 |
return redirect('/reg') |
|
231 |
||
13
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
232 |
def open_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
233 |
""" 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
|
234 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
235 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
236 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
237 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
238 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
239 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
240 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
241 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
242 |
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
|
243 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
244 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
245 |
event.registration_is_open = True |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
246 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
247 |
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
|
248 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
249 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
250 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
251 |
def close_registration(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
252 |
""" 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
|
253 |
""" |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
254 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
255 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
256 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
257 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
258 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
259 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
260 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
261 |
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
|
262 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
263 |
if is_org: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
264 |
event.registration_is_open = False |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
265 |
event.save() |
14
cd6911eaac2c
moved templates into templates directory and added user in context .
nishanth
parents:
13
diff
changeset
|
266 |
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
|
267 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
268 |
return redirect('/reg') |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
269 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
270 |
def register_for_event(request, event_key): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
271 |
""" check if the user is logged in. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
272 |
simply add him to the attendees list. |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
273 |
""" |
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 |
user = request.user |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
276 |
if user.is_authenticated(): |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
277 |
try: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
278 |
event = Event.objects.get(key__iexact=event_key) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
279 |
except Event.DoesNotExist: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
280 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
281 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
282 |
event.attendees.add(user) |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
283 |
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
|
284 |
else: |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
285 |
return redirect("/reg") |
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
286 |
|
17 | 287 |
def view_profile(request): |
288 |
""" check if user is logged in. |
|
289 |
then show the profile. |
|
290 |
""" |
|
291 |
||
292 |
user = request.user |
|
293 |
if not user.is_authenticated(): |
|
294 |
return redirect('/reg') |
|
295 |
||
296 |
user_profile = user.get_profile() |
|
297 |
return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile}) |
|
298 |
||
299 |
def edit_profile(request): |
|
300 |
""" check if user is logged in. |
|
301 |
""" |
|
302 |
||
303 |
user = request.user |
|
304 |
if not user.is_authenticated(): |
|
305 |
return redirect('/reg') |
|
306 |
||
307 |
user_profile = user.get_profile() |
|
308 |
||
309 |
if request.method == "POST": |
|
310 |
form = reg_forms.EditProfileForm(request.POST) |
|
311 |
if form.is_valid(): |
|
312 |
reg_events.update_profile(user, form.cleaned_data) |
|
313 |
return redirect('/reg/profile/view') |
|
314 |
else: |
|
315 |
return render_to_response('edit_profile.html', {'user':user, 'form':form}) |
|
316 |
else: |
|
317 |
old_info = {'first_name': user.first_name, |
|
318 |
'last_name': user.last_name, |
|
319 |
'gender':user_profile.gender, |
|
320 |
'profession': user_profile.profession, |
|
321 |
'affiliated_to': user_profile.affiliated_to, |
|
322 |
'interests': user_profile.interests, |
|
323 |
} |
|
324 |
form = reg_forms.EditProfileForm(old_info) |
|
325 |
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
|
326 |
|
05248e27104a
added closing registration and registering for a workshop .
nishanth
parents:
12
diff
changeset
|
327 |