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