def getCount(request, **kwargs): user_id = request.user.id if 'type' in kwargs: try: if kwargs['type'] == 'notifications': count = Notification.objects(owner = user_id).count() unread_count = Notification.objects(Q(owner = user_id) & Q(read = False)).count() else: count = 'Nothing to report' result = {'count' : count, 'unread_count' : unread_count} return JsonResponse(result, safe=False) except Exception as e: return JsonResponse({'Error' : str(e)})
def get_queryset(self): #print 'in query' user_id = self.request.user.id if 'type' in self.kwargs: #print 'type is ' + str(self.kwargs['type']) if 'subtype' not in self.kwargs: if self.kwargs['type'] == 'notifications': user_id = self.request.user.id queryset = Notification.objects(owner = user_id) else: queryset = None else: if self.kwargs['type'] == 'notifications' and self.kwargs['subtype'] == 'unread': queryset = Notification.objects(Q(owner = user_id) & Q(read = False)) elif self.kwargs['type'] == 'notifications' and self.kwargs['subtype'] == 'all': queryset = Notification.objects(owner = user_id) return queryset
def setUnread(request, **kwargs): try: if kwargs['type'] == 'notifications': post_data = json.loads(request.body) ids = post_data['ids[]'] #ids = request.POST.getlist('ids[]') #print 'arr is ' + str(ids) if ids: for id in ids: #print 'id is ' + str(id) existingRecord = Notification.objects(id = id).update(set__read = True) result = {'message' : str(len(ids)) + ' records updated'} return JsonResponse(result, safe=False) except Exception as e: return JsonResponse({'Error' : str(e)})