Commit 803b92fc by Kevin Chugh

add ajax endpoint for getting notifications status

parent 8f98a1c2
......@@ -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):
"""
......
......@@ -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<token>[a-zA-Z0-9-_=]+)/', 'notification_prefs.views.unsubscribe'),
)
urlpatterns += (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment