4 from django.shortcuts import redirect, render_to_response |
4 from django.shortcuts import redirect, render_to_response |
5 from django.contrib.auth.models import User |
5 from django.contrib.auth.models import User |
6 from django.contrib.auth.decorators import login_required |
6 from django.contrib.auth.decorators import login_required |
7 |
7 |
8 from pytask.taskapp.models import Task, Profile, Request |
8 from pytask.taskapp.models import Task, Profile, Request |
|
9 |
9 from pytask.taskapp.events.user import createUser, updateProfile |
10 from pytask.taskapp.events.user import createUser, updateProfile |
|
11 from pytask.taskapp.events.request import reply_to_request |
|
12 |
10 from pytask.taskapp.forms.user import UserProfileEditForm |
13 from pytask.taskapp.forms.user import UserProfileEditForm |
11 from pytask.taskapp.events.request import reply_to_request |
14 |
12 from pytask.taskapp.utilities.request import get_request |
15 from pytask.taskapp.utilities.request import get_request |
|
16 from pytask.taskapp.utilities.notification import get_notification |
13 |
17 |
14 def show_msg(user, message, redirect_url=None, url_desc=None): |
18 def show_msg(user, message, redirect_url=None, url_desc=None): |
15 """ simply redirect to homepage """ |
19 """ simply redirect to homepage """ |
16 |
20 |
17 return render_to_response('show_msg.html',{'user':user, 'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc}) |
21 return render_to_response('show_msg.html',{'user':user, 'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc}) |
38 |
42 |
39 else: |
43 else: |
40 user_profile = user.get_profile() |
44 user_profile = user.get_profile() |
41 is_mentor = True if user.task_mentors.all() else False |
45 is_mentor = True if user.task_mentors.all() else False |
42 can_create_task = False if user_profile.rights == u"CT" else True |
46 can_create_task = False if user_profile.rights == u"CT" else True |
43 notifications = user.notification_to.filter(deleted=False,is_read=False) |
47 notifications = user.notification_sent_to.filter(is_deleted=False,is_read=False) |
44 requests = user.request_sent_to.filter(is_replied=False) |
48 requests = user.request_sent_to.filter(is_replied=False) |
45 |
49 |
46 context = {'user':user, |
50 context = {'user':user, |
47 'is_guest':is_guest, |
51 'is_guest':is_guest, |
48 'is_mentor':is_mentor, |
52 'is_mentor':is_mentor, |
166 """ get the list of notifications that are not deleted and display in datetime order. |
170 """ get the list of notifications that are not deleted and display in datetime order. |
167 """ |
171 """ |
168 |
172 |
169 user = request.user |
173 user = request.user |
170 |
174 |
171 active_notifications = user.notification_to.filter(deleted=False).order_by('sent_date').reverse() |
175 active_notifications = user.notification_sent_to.filter(is_deleted=False).order_by('sent_date').reverse() |
172 for pos, notification in enumerate(reversed(active_notifications)): |
|
173 notification.pos = pos |
|
174 |
176 |
175 context = { |
177 context = { |
176 'user':user, |
178 'user':user, |
177 'notifications':active_notifications, |
179 'notifications':active_notifications, |
178 } |
180 } |
204 if it is unread, unset is_read. |
208 if it is unread, unset is_read. |
205 save the notification and redirect to browse_notifications. |
209 save the notification and redirect to browse_notifications. |
206 """ |
210 """ |
207 |
211 |
208 user = request.user |
212 user = request.user |
209 notifications = user.notification_to.filter(deleted=False).order_by('sent_date') |
213 notification = get_notification(nid, user) |
210 notification = notifications[int(nid)] |
214 |
|
215 if not notification: |
|
216 raise Http404 |
|
217 |
211 notifications_url = "/user/notifications/" |
218 notifications_url = "/user/notifications/" |
212 |
219 |
213 if request.method == "POST": |
220 if request.method == "POST": |
214 if action == "delete": |
221 if action == "delete": |
215 notification.deleted = True |
222 notification.is_deleted = True |
216 elif action == "unread": |
223 elif action == "unread": |
217 notification.is_read = False |
224 notification.is_read = False |
218 |
225 |
219 notification.save() |
226 notification.save() |
220 return redirect(notifications_url) |
227 return redirect(notifications_url) |