From 803b92fc9a6931fb1bf7d4a04b896f5e43cdacbe Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Tue, 30 Jul 2013 01:19:15 -0400 Subject: [PATCH] add ajax endpoint for getting notifications status --- lms/djangoapps/notification_prefs/views.py | 29 ++++++++++++++++++++++ lms/urls.py | 1 + 2 files changed, 30 insertions(+) diff --git a/lms/djangoapps/notification_prefs/views.py b/lms/djangoapps/notification_prefs/views.py index a5c58008e3..bacb98bc7d 100644 --- a/lms/djangoapps/notification_prefs/views.py +++ b/lms/djangoapps/notification_prefs/views.py @@ -131,6 +131,35 @@ def ajax_disable(request): return HttpResponse(status=204) +@require_POST +def ajax_status(request): + """ + A view that sends notifications status for the authenticated user + + This view should be invoked by an AJAX POST call. It returns status 204 + (no content) or an error. + """ + if not request.user.is_authenticated(): + raise PermissionDenied + + prefs UserPreference.objects.get( + user=request.user, + key=NOTIFICATION_PREF_KEY, + defaults={ + "value": UsernameCipher.encrypt(request.user.username) + } + ) + + if prefs + answer = true + else + answer = false + + return utils.JsonResponse({ + 'status': answer + }) + + @require_GET def unsubscribe(request, token): """ diff --git a/lms/urls.py b/lms/urls.py index 84cf149983..5dbeafe633 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -336,6 +336,7 @@ if settings.COURSEWARE_ENABLED: include('django_comment_client.urls')), url(r'^notification_prefs/enable/', 'notification_prefs.views.ajax_enable'), url(r'^notification_prefs/disable/', 'notification_prefs.views.ajax_disable'), + url(r'^notification_prefs/status/', 'notification_prefs.views.ajax_status'), url(r'^notification_prefs/unsubscribe/(?P[a-zA-Z0-9-_=]+)/', 'notification_prefs.views.unsubscribe'), ) urlpatterns += (