author | Madhusudan.C.S <madhusudancs@gmail.com> |
Mon, 17 Jan 2011 04:37:07 +0530 | |
changeset 440 | 56ea209e559f |
parent 418 | df241055a1a7 |
child 452 | f10fe304298c |
permissions | -rwxr-xr-x |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
1 |
from django import shortcuts |
266
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
2 |
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
|
3 |
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
|
4 |
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
|
5 |
from django.core.urlresolvers import reverse |
409
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
6 |
from django.http import Http404 |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
7 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
8 |
from pytask.profile.forms import EditProfileForm |
409
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
9 |
from pytask.profile.utils import get_notification |
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
10 |
from pytask.profile.utils import get_user |
09e381a7c2c3
Make adjustment in import styling.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
378
diff
changeset
|
11 |
|
266
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
12 |
|
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
13 |
@login_required |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
14 |
def view_profile(request): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
15 |
""" Display the profile information. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
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 |
user = request.user |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
19 |
profile = user.get_profile() |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
20 |
|
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
21 |
context = {"user": user, |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
22 |
"profile": profile, |
4dfcc826b241
Created a view for viewing profile
Nishanth Amuluru <nishanth@fossee.in>
parents:
241
diff
changeset
|
23 |
} |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
24 |
return shortcuts.render_to_response("profile/view.html", context) |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
25 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
26 |
@login_required |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
27 |
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
|
28 |
""" 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
|
29 |
""" |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
30 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
|
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
34 |
context = {"user": user, |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
35 |
"profile": profile, |
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 |
return shortcuts.render_to_response("profile/view.html", context) |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
38 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
39 |
@login_required |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
40 |
def edit_profile(request): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
41 |
""" Make only a few fields editable. |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
42 |
""" |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
43 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
44 |
user = request.user |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
45 |
profile = user.get_profile() |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
46 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
47 |
context = {"user": user, |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
48 |
"profile": profile, |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
49 |
} |
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 |
context.update(csrf(request)) |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
52 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
53 |
if request.method == "POST": |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
54 |
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
|
55 |
|
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
56 |
if form.is_valid(): |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
57 |
form.save() |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
58 |
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
|
59 |
else: |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
60 |
context.update({"form":form}) |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
61 |
return shortcuts.render_to_response("profile/edit.html", context) |
269
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
62 |
else: |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
63 |
form = EditProfileForm(instance=profile) |
dde894b36370
created view for editing profile and created corresponding template
Nishanth Amuluru <nishanth@fossee.in>
parents:
267
diff
changeset
|
64 |
context.update({"form":form}) |
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.render_to_response("profile/edit.html", context) |
273
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
66 |
|
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
67 |
@login_required |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
68 |
def browse_notifications(request): |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
69 |
""" 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
|
70 |
datetime order.""" |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
71 |
|
275
c701e68f8d35
fixed a typo and browse notifications works fine
Nishanth Amuluru <nishanth@fossee.in>
parents:
274
diff
changeset
|
72 |
user = request.user |
273
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
73 |
|
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
|
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
77 |
context = {'user':user, |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
78 |
'notifications':active_notifications, |
8318df7e2d52
created a view for browising thro notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
269
diff
changeset
|
79 |
} |
274
5cd56898033c
created template for browse notifications
Nishanth Amuluru <nishanth@fossee.in>
parents:
273
diff
changeset
|
80 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
81 |
return shortcuts.render_to_response('profile/browse_notifications.html', 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
|
82 |
|
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
|
83 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
84 |
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
|
85 |
""" 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
|
86 |
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
|
87 |
""" |
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
|
88 |
|
282 | 89 |
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
|
90 |
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
|
91 |
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
|
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 |
if not 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
|
94 |
raise Http404 |
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 |
|
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 |
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
|
97 |
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
|
98 |
|
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
|
99 |
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
|
100 |
'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
|
101 |
'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
|
102 |
'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
|
103 |
'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
|
104 |
'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
|
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 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
107 |
return shortcuts.render_to_response( |
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
108 |
'profile/view_notification.html', context) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
109 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
110 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
111 |
def delete_notification(request, notification_id): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
112 |
""" 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
|
113 |
""" |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
114 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
notification_id, user) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
118 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
119 |
if not notification: |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
120 |
raise Http404 |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
121 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
122 |
notification.is_deleted = True |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
123 |
notification.save() |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
124 |
|
288 | 125 |
if older: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
126 |
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
|
127 |
kwargs={'notification_id': older.id}) |
288 | 128 |
else: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
129 |
redirect_url = reverse('browse_notifications') |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
130 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
131 |
return shortcuts.redirect(redirect_url) |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
132 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
133 |
@login_required |
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
134 |
def unread_notification(request, notification_id): |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
135 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
136 |
""" 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
|
137 |
""" |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
138 |
|
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
notification_id, user) |
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 |
if not notification: |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
144 |
raise Http404 |
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 |
notification.is_read = False |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
147 |
notification.save() |
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
148 |
|
288 | 149 |
if older: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
150 |
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
|
151 |
kwargs={'notification_id': older.id}) |
288 | 152 |
else: |
411
edf514c6a820
Used reverse URL matching instead of hard coded URLs.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
409
diff
changeset
|
153 |
redirect_url = reverse('browse_notifications') |
287
d24b4a7147d2
created views for delete and unread notification
Nishanth Amuluru <nishanth@fossee.in>
parents:
282
diff
changeset
|
154 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
155 |
return shortcuts.redirect(redirect_url) |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
156 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
157 |
@login_required |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
158 |
def view_user(request, uid): |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
159 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
160 |
user = request.user |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
161 |
profile = user.get_profile() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
162 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
163 |
viewing_user = get_user(uid) |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
164 |
viewing_profile = viewing_user.get_profile() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
165 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
166 |
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
|
167 |
completed_tasks = viewing_user.approved_tasks.filter(status="Completed") |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
168 |
reviewing_tasks = viewing_user.reviewing_tasks.all() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
169 |
claimed_tasks = viewing_user.claimed_tasks.all() |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
170 |
|
440
56ea209e559f
Use the right form of names to be stored in the database.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
418
diff
changeset
|
171 |
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
|
172 |
'Administrator', 'Coordinator'] else False |
378
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
173 |
|
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
174 |
context = {"user": user, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
175 |
"profile": profile, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
176 |
"viewing_user": viewing_user, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
177 |
"viewing_profile": viewing_profile, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
178 |
"working_tasks": working_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
179 |
"completed_tasks": completed_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
180 |
"reviewing_tasks": reviewing_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
181 |
"claimed_tasks": claimed_tasks, |
8fcde6f8f750
added view_user functionality
Nishanth Amuluru <nishanth@fossee.in>
parents:
307
diff
changeset
|
182 |
"can_view_info": can_view_info, |
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 |
|
418
df241055a1a7
Add a new view method for specific users profile view.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
411
diff
changeset
|
185 |
return shortcuts.render_to_response("profile/view_user.html", context) |