def read_notification(request): try: queryset = request.user.misago_notifications notification = queryset.get(id=request.POST['notification']) if notification.is_new: is_changed = True with atomic(): notification.is_new = False notification.save(update_fields=['is_new']) assert_real_new_notifications_count(request.user) else: is_changed = False if request.is_ajax(): return JsonResponse({'is_error': False, 'is_changed': is_changed}) else: messages.success(request, _("Notification was marked as read.")) return redirect('misago:notifications') except Notification.DoesNotExist: message = _("Specified notification could not be found.") if request.is_ajax(): return JsonResponse({ 'is_error': True, 'message': message, }) else: messages.error(request, message) return redirect('misago:notifications')
def read_notification(request): try: queryset = request.user.misago_notifications notification = queryset.get(id=request.POST['notification']) if notification.is_new: is_changed = True with atomic(): notification.is_new = False notification.save(update_fields=['is_new']) assert_real_new_notifications_count(request.user) else: is_changed = False if request.is_ajax(): return JsonResponse({ 'is_error': False, 'is_changed': is_changed }) else: messages.success(request, _("Notification was marked as read.")) return redirect('misago:notifications') except Notification.DoesNotExist: message = _("Specified notification could not be found.") if request.is_ajax(): return JsonResponse({ 'is_error': True, 'message': message, }) else: messages.error(request, message) return redirect('misago:notifications')
def go_to_notification(request, notification_id, trigger): queryset = request.user.misago_notifications.select_for_update() notification = get_object_or_404( queryset, pk=notification_id, trigger=trigger) if notification.is_new: notification.is_new = False notification.save(update_fields=['is_new']) assert_real_new_notifications_count(request.user) return redirect(notification.url)
def go_to_notification(request, notification_id, hash): queryset = request.user.misago_notifications.select_for_update() notification = get_object_or_404( queryset, pk=notification_id, hash=hash) if notification.is_new: update_qs = request.user.misago_notifications.filter(hash=hash) update_qs.update(is_new=False) assert_real_new_notifications_count(request.user) return redirect(notification.url)
def go_to_notification(request, notification_id, trigger): queryset = request.user.misago_notifications.select_for_update() notification = get_object_or_404(queryset, pk=notification_id, trigger=trigger) if notification.is_new: notification.is_new = False notification.save(update_fields=['is_new']) assert_real_new_notifications_count(request.user) return redirect(notification.url)
def notifications(request): if request.method == 'POST': read_all(request) if not request.is_ajax(): return redirect('misago:notifications') else: assert_real_new_notifications_count(request.user) if request.is_ajax(): return dropdown(request) else: return full_page(request)
def notifications(request): if request.method == 'POST': if 'read-all' in request.POST: return read_all(request) if request.POST.get('notification'): return read_notification(request) else: assert_real_new_notifications_count(request.user) if request.is_ajax(): return dropdown(request) else: return full_page(request)