Skip to content

Commit

Permalink
Merge pull request #54 from erfaan/fix_#53
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
Mauricio committed Mar 10, 2016
2 parents 7e88e57 + b2d1f03 commit 81126d9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dashing/widgets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
import json
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.views.generic.detail import View

from dashing.settings import dashing_settings


class JSONResponseMixin(object):
"""
Expand All @@ -24,7 +27,20 @@ def convert_context_to_json(self, context):


class Widget(JSONResponseMixin, View):
permission_classes = dashing_settings.PERMISSION_CLASSES

def check_permissions(self, request):
"""
Check if the request should be permitted.
Raises an appropriate exception if the request is not permitted.
"""
permissions = [permission() for permission in self.permission_classes]
for permission in permissions:
if not permission.has_permission(request):
raise PermissionDenied()

def get(self, request, *args, **kwargs):
self.check_permissions(request)
context = json.dumps(self.get_context())
return HttpResponse(context, content_type="application/json")

Expand Down

0 comments on commit 81126d9

Please sign in to comment.