1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-25 23:02:26 +00:00

update set_notices_seen

This commit is contained in:
lian
2016-08-19 15:00:10 +08:00
committed by lian
parent 996c67fdb7
commit 5a700d5f00
7 changed files with 60 additions and 37 deletions

View File

@@ -17,6 +17,11 @@ class NotificationsView(APIView):
throttle_classes = (UserRateThrottle,)
def get(self, request):
""" currently only used for get unseen notifications count
Permission checking:
1. login user.
"""
username = request.user.username
unseen_count = UserNotification.objects.count_unseen_user_notifications(username)
@@ -24,3 +29,26 @@ class NotificationsView(APIView):
result['unseen_count'] = unseen_count
return Response(result)
def put(self, request):
""" currently only used for mark all notifications seen
Permission checking:
1. login user.
"""
username = request.user.username
unseen_notices = UserNotification.objects.get_user_notifications(username,
seen=False)
for notice in unseen_notices:
notice.seen = True
notice.save()
# TODO mark related user msg as read
if notice.is_user_message():
d = notice.user_message_detail_to_dict()
msg_from = d.get('msg_from')
from seahub.message.models import UserMessage
UserMessage.objects.update_unread_messages(msg_from, username)
return Response({'success': True})