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