author | Madhusudan.C.S <madhusudancs@gmail.com> |
Tue, 18 Jan 2011 14:33:54 +0530 | |
changeset 455 | 7b006fb467c2 |
parent 453 | 4b4e299add3b |
child 464 | 6f5a60ce7d25 |
permissions | -rwxr-xr-x |
455
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
1 |
from urllib2 import urlparse |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
2 |
|
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
3 |
from django import http |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
4 |
from django import shortcuts |
266
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
5 |
from django.contrib.auth.decorators import login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
6 |
from django.contrib.auth.models import User |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
7 |
from django.core.context_processors import csrf |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
8 |
from django.core.urlresolvers import reverse |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
9 |
from django.template import loader |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
10 |
from django.template import RequestContext |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
11 |
from django.utils import simplejson as json |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
12 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
13 |
from pytask.profile.forms import EditProfileForm |
409
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
14 |
from pytask.profile.utils import get_notification |
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
15 |
from pytask.profile.utils import get_user |
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
16 |
|
266
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
17 |
|
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
18 |
@login_required |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
19 |
def view_profile(request): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
20 |
""" Display the profile information. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
21 |
""" |
266
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
22 |
|
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
23 |
user = request.user |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
24 |
profile = user.get_profile() |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
25 |
|
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
26 |
context = {"user": user, |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
27 |
"profile": profile, |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
28 |
} |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
29 |
return shortcuts.render_to_response("profile/view.html", |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
30 |
RequestContext(request, context)) |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
31 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
32 |
@login_required |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
33 |
def view_user_profile(request, user_id): |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
34 |
""" Display the profile information of the user specified in the ID. |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
35 |
""" |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
36 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
37 |
user = shortcuts.get_object_or_404(User, pk=user_id) |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
38 |
profile = user.get_profile() |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
39 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
40 |
context = {"user": user, |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
41 |
"profile": profile, |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
42 |
} |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
43 |
return shortcuts.render_to_response("profile/view.html", |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
44 |
RequestContext(request, context)) |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
45 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
46 |
@login_required |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
47 |
def edit_profile(request): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
48 |
""" Make only a few fields editable. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
49 |
""" |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
50 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
51 |
user = request.user |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
52 |
profile = user.get_profile() |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
53 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
54 |
context = {"user": user, |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
55 |
"profile": profile, |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
56 |
} |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
57 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
58 |
context.update(csrf(request)) |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
59 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
60 |
if request.method == "POST": |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
61 |
form = EditProfileForm(request.POST, instance=profile) |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
62 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
63 |
if form.is_valid(): |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
64 |
form.save() |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
65 |
return shortcuts.redirect(reverse('view_profile')) |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
66 |
else: |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
67 |
context.update({"form":form}) |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
68 |
return shortcuts.render_to_response( |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
69 |
"profile/edit.html", RequestContext(request, context)) |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
70 |
else: |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
71 |
form = EditProfileForm(instance=profile) |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
72 |
context.update({"form":form}) |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
73 |
return shortcuts.render_to_response( |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
74 |
"profile/edit.html", RequestContext(request, context)) |
273
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
75 |
|
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
76 |
@login_required |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
77 |
def browse_notifications(request): |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
78 |
""" get the list of notifications that are not deleted and display in |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
79 |
datetime order.""" |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
80 |
|
275
c701e68f8d35
fixed a typo and browse notifications works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
274
diff
changeset
|
81 |
user = request.user |
273
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
82 |
|
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
83 |
active_notifications = user.notification_sent_to.filter( |
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
84 |
is_deleted=False).order_by('-sent_date') |
273
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
85 |
|
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
86 |
context = {'user':user, |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
87 |
'notifications':active_notifications, |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
88 |
} |
274
5cd56898033c
created template for browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
273
diff
changeset
|
89 |
|
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
90 |
return shortcuts.render_to_response('profile/browse_notifications.html', |
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
91 |
RequestContext(request, context)) |
276
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
92 |
|
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
93 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
94 |
def view_notification(request, notification_id): |
276
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
95 |
""" get the notification depending on nid. |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
96 |
Display it. |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
97 |
""" |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
98 |
|
282 | 99 |
user = request.user |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
100 |
newest, newer, notification, older, oldest = get_notification( |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
101 |
notification_id, user) |
276
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
102 |
|
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
103 |
if not notification: |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
104 |
raise http.Http404 |
276
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
105 |
|
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
106 |
notification.is_read = True |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
107 |
notification.save() |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
108 |
|
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
109 |
context = {'user':user, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
110 |
'notification':notification, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
111 |
'newest':newest, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
112 |
'newer':newer, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
113 |
'older':older, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
114 |
'oldest':oldest, |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
115 |
} |
c8c47fcb46f0
created a view for view notification and included the url. made changes accordingly in browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
275
diff
changeset
|
116 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
117 |
return shortcuts.render_to_response( |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
118 |
'profile/view_notification.html', RequestContext(request, context)) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
119 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
120 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
121 |
def delete_notification(request, notification_id): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
122 |
""" check if the user owns the notification and delete it. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
123 |
""" |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
124 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
125 |
user = request.user |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
126 |
newest, newer, notification, older, oldest = get_notification( |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
127 |
notification_id, user) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
128 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
129 |
if not notification: |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
130 |
raise http.Http404 |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
131 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
132 |
notification.is_deleted = True |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
133 |
notification.save() |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
134 |
|
288 | 135 |
if older: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
136 |
redirect_url = reverse('view_notification', |
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
137 |
kwargs={'notification_id': older.id}) |
288 | 138 |
else: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
139 |
redirect_url = reverse('browse_notifications') |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
140 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
141 |
return shortcuts.redirect(redirect_url) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
142 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
143 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
144 |
def unread_notification(request, notification_id): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
145 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
146 |
""" check if the user owns the notification and delete it. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
147 |
""" |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
148 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
149 |
user = request.user |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
150 |
newest, newer, notification, older, oldest = get_notification( |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
151 |
notification_id, user) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
152 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
153 |
if not notification: |
452
f10fe304298c
Replace all usage of context with RequestContext and use the imports in right form.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
440
diff
changeset
|
154 |
raise http.Http404 |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
155 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
156 |
notification.is_read = False |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
157 |
notification.save() |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
158 |
|
288 | 159 |
if older: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
160 |
redirect_url = reverse('view_notification', |
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
161 |
kwargs={'notification_id': older.id}) |
288 | 162 |
else: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
163 |
redirect_url = reverse('browse_notifications') |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
164 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
165 |
return shortcuts.redirect(redirect_url) |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
166 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
167 |
@login_required |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
168 |
def view_user(request, uid): |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
169 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
170 |
user = request.user |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
171 |
profile = user.get_profile() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
172 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
173 |
viewing_user = get_user(uid) |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
174 |
viewing_profile = viewing_user.get_profile() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
175 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
176 |
working_tasks = viewing_user.approved_tasks.filter(status="Working") |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
177 |
completed_tasks = viewing_user.approved_tasks.filter(status="Completed") |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
178 |
reviewing_tasks = viewing_user.reviewing_tasks.all() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
179 |
claimed_tasks = viewing_user.claimed_tasks.all() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
180 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
181 |
can_view_info = True if profile.role in [ |
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
182 |
'Administrator', 'Coordinator'] else False |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
183 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
184 |
context = {"user": user, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
185 |
"profile": profile, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
186 |
"viewing_user": viewing_user, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
187 |
"viewing_profile": viewing_profile, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
188 |
"working_tasks": working_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
189 |
"completed_tasks": completed_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
190 |
"reviewing_tasks": reviewing_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
191 |
"claimed_tasks": claimed_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
192 |
"can_view_info": can_view_info, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
193 |
} |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
194 |
|
453
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
195 |
return shortcuts.render_to_response("profile/view_user.html", |
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
196 |
RequestContext(request, context)) |
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
197 |
|
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
198 |
@login_required |
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
199 |
def login_proceed(request): |
455
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
200 |
"""View that handles the successful login. |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
201 |
""" |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
202 |
|
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
203 |
template_name = '_user_login.html' |
453
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
204 |
|
455
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
205 |
# Check if the request came from logout page, if so set |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
206 |
# authentication to redirect to home page |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
207 |
if reverse('auth_logout') == urlparse.urlsplit( |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
208 |
request.META['HTTP_REFERER'])[2]: |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
209 |
response = { |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
210 |
'authentication': 'success', |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
211 |
'redirect': reverse('home_page'), |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
212 |
} |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
213 |
else: |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
214 |
response = { |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
215 |
'authentication': 'success', |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
216 |
'markup': loader.render_to_string(template_name, |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
217 |
RequestContext(request, {})) |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
218 |
} |
453
4b4e299add3b
A new view for processing post login to give the right html to replace for user action right sidebar.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
452
diff
changeset
|
219 |
|
455
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
220 |
json_response = json.dumps(response) |
7b006fb467c2
Redirect the login to home page if the login is made from logout page.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
453
diff
changeset
|
221 |
return http.HttpResponse(json_response) |