author | nishanth |
Mon, 12 Apr 2010 11:23:27 +0530 | |
changeset 11 | 334550460bd7 |
parent 10 | c52d170969f0 |
child 12 | f57b0a7f24d9 |
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 |
|
22 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
23 |
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
|
24 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
25 |
return render_to_response('index.html', {'events':events}) |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
26 |
|
4 | 27 |
def user_login(request): |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
28 |
""" get the user object from e-mail and then check for password. |
2 | 29 |
""" |
30 |
||
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
31 |
user = request.user |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
32 |
if user.is_authenticated(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
33 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
34 |
|
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
35 |
if request.method == "POST": |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
36 |
form = reg_forms.LoginForm(request.POST) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
37 |
if form.is_valid(): |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
38 |
email = form.cleaned_data['email'] |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
39 |
password = form.cleaned_data['password'] |
4 | 40 |
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
|
41 |
|
4 | 42 |
user = authenticate(username=username, password=password) |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
43 |
login(request, user) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
44 |
return redirect('/reg') |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
45 |
else: |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
46 |
return render_to_response('login.html', {'form':form}) |
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
47 |
else: |
4 | 48 |
form = reg_forms.LoginForm() |
3
182f216da4a8
made the login view. have to write templates and check it.
nishanth
parents:
2
diff
changeset
|
49 |
return render_to_response('login.html', {'form':form}) |
4 | 50 |
|
51 |
def user_logout(request): |
|
52 |
""" simply logout the user and redirect to homepage. |
|
53 |
""" |
|
54 |
||
55 |
logout(request) |
|
56 |
return redirect('/reg') |
|
57 |
||
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
58 |
def user_register(request): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
59 |
""" 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
|
60 |
""" |
4 | 61 |
|
6
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
62 |
if request.method == "POST": |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
63 |
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
|
64 |
if form.is_valid(): |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
65 |
data = form.cleaned_data |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
66 |
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
|
67 |
password=data['password'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
68 |
firstname=data['first_name'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
69 |
lastname=data['last_name'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
70 |
gender=data['gender'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
71 |
profession=data['profession'], |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
72 |
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
|
73 |
interests=data['interests'] |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
74 |
) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
75 |
return render_to_response('account_created.html') |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
76 |
else: |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
77 |
return render_to_response('register.html', {'form':form}) |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
78 |
else: |
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() |
057498d12450
users can now register but still there is no concept of activation e-mail .
nishanth
parents:
5
diff
changeset
|
80 |
return render_to_response('register.html', {'form':form}) |
8 | 81 |
|
82 |
def create_event(request): |
|
83 |
""" see if the user is a staff and only then let him do it. |
|
84 |
""" |
|
85 |
||
86 |
user = request.user |
|
87 |
if user.is_authenticated() and user.is_staff: |
|
88 |
if request.method == "POST": |
|
89 |
form = reg_forms.EventCreateForm(request.POST) |
|
90 |
if form.is_valid(): |
|
91 |
data = form.cleaned_data |
|
92 |
new_event = reg_events.create_event(title=data['title'], |
|
93 |
description=data['description'], |
|
94 |
start_date=data['start_date'], |
|
95 |
stop_date=data['stop_date'], |
|
96 |
created_by=user, |
|
97 |
) |
|
98 |
event_url = "/reg/event/view/%s"%(new_event.key) |
|
99 |
return redirect(event_url) |
|
100 |
else: |
|
101 |
return render_to_response('event_create.html', {'form':form}) |
|
102 |
else: |
|
103 |
form = reg_forms.EventCreateForm() |
|
104 |
return render_to_response('event_create.html', {'form':form}) |
|
105 |
else: |
|
106 |
return redirect('/reg') |
|
107 |
||
108 |
def view_event(request, key): |
|
109 |
""" get the event by its key and display it. |
|
110 |
""" |
|
111 |
||
112 |
user = request.user |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
113 |
user_ip = request.META['REMOTE_ADDR'] |
8 | 114 |
|
115 |
try: |
|
116 |
event = Event.objects.get(key__iexact=key) |
|
117 |
except Event.DoesNotExist: |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
118 |
return redirect("/reg") |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
119 |
|
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
120 |
is_guest = False if user.is_authenticated() else True |
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
121 |
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
|
122 |
is_org = True if user in event.organizers.all() else False |
8 | 123 |
|
11
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
124 |
can_submit_feedback = False |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
125 |
if not event.feedback_status == "0": |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
126 |
try: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
127 |
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
|
128 |
except Feedback.DoesNotExist: |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
129 |
can_submit_feedback = True |
334550460bd7
added the view event functionality and submitting feedback according to the status .
nishanth
parents:
10
diff
changeset
|
130 |
|
10
c52d170969f0
quite a few changes. modified models and feedback views .
nishanth
parents:
9
diff
changeset
|
131 |
context = {'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) |
|
154 |
return render_to_response('password_reset.html', {'new_password':new_password}) |
|
155 |
else: |
|
156 |
return render_to_response('password_reset.html', {'form':form}) |
|
157 |
else: |
|
158 |
form = reg_forms.PasswordResetForm() |
|
159 |
return render_to_response('password_reset.html', {'form':form}) |
|
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) |
|
176 |
return render_to_response('password_change.html', {'password_changed': True}) |
|
177 |
else: |
|
178 |
return render_to_response('password_change.html', {'form':form}) |
|
179 |
else: |
|
180 |
form = reg_forms.PasswordChangeForm() |
|
181 |
return render_to_response('password_change.html', {'form':form}) |
|
182 |
||
183 |
||
184 |
||
185 |
||
186 |
||
187 |
||
188 |