add ajax endpoint for getting notifications status
This commit is contained in:
@@ -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 += (
|
||||
|
||||
Reference in New Issue
Block a user