add ajax endpoint for getting notifications status

This commit is contained in:
Kevin Chugh
2013-07-30 01:19:15 -04:00
parent 8f98a1c2be
commit 803b92fc9a
2 changed files with 30 additions and 0 deletions

View File

@@ -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):
"""

View File

@@ -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 += (