Commit 0c07829d by Kálmán Viktor

occi: use mixin instead of copy pasted csrf_exempt method

parent b6a0fdb4
...@@ -25,6 +25,12 @@ from .occi import ( ...@@ -25,6 +25,12 @@ from .occi import (
) )
class CSRFExemptMixin(object):
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)
def get_post_data_from_request(request): def get_post_data_from_request(request):
""" Returns the post data in an array """ Returns the post data in an array
""" """
...@@ -45,7 +51,7 @@ def get_post_data_from_request(request): ...@@ -45,7 +51,7 @@ def get_post_data_from_request(request):
return post_data return post_data
class QueryInterface(View): class QueryInterface(CSRFExemptMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "Category: %s\n" % COMPUTE_KIND.render_values() response = "Category: %s\n" % COMPUTE_KIND.render_values()
...@@ -70,12 +76,8 @@ class QueryInterface(View): ...@@ -70,12 +76,8 @@ class QueryInterface(View):
response = HttpResponse(status=501) response = HttpResponse(status=501)
return response return response
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(QueryInterface, self).dispatch(*args, **kwargs)
class ComputeInterface(View): class ComputeInterface(CSRFExemptMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "\n".join([Compute(instance=i).render_location() response = "\n".join([Compute(instance=i).render_location()
...@@ -96,12 +98,8 @@ class ComputeInterface(View): ...@@ -96,12 +98,8 @@ class ComputeInterface(View):
) )
return response return response
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(ComputeInterface, self).dispatch(*args, **kwargs)
class VmInterface(CSRFExemptMixin, DetailView):
class VmInterface(DetailView):
model = Instance model = Instance
def get_object(self): def get_object(self):
...@@ -130,12 +128,8 @@ class VmInterface(DetailView): ...@@ -130,12 +128,8 @@ class VmInterface(DetailView):
return HttpResponse() return HttpResponse()
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(VmInterface, self).dispatch(*args, **kwargs)
class OsTplInterface(View): class OsTplInterface(CSRFExemptMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "\n".join([OsTemplate(template=t).render_location() response = "\n".join([OsTemplate(template=t).render_location()
...@@ -148,12 +142,8 @@ class OsTplInterface(View): ...@@ -148,12 +142,8 @@ class OsTplInterface(View):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
pass pass
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(OsTplInterface, self).dispatch(*args, **kwargs)
class StorageInterface(View): class StorageInterface(CSRFExemptMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "\n".join([Storage(disk=d).render_location() response = "\n".join([Storage(disk=d).render_location()
...@@ -174,12 +164,8 @@ class StorageInterface(View): ...@@ -174,12 +164,8 @@ class StorageInterface(View):
) )
return response return response
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(StorageInterface, self).dispatch(*args, **kwargs)
class DiskInterface(DetailView): class DiskInterface(CSRFExemptMixin, DetailView):
model = Disk model = Disk
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
...@@ -203,12 +189,8 @@ class DiskInterface(DetailView): ...@@ -203,12 +189,8 @@ class DiskInterface(DetailView):
Storage(disk=self.get_object()).delete() Storage(disk=self.get_object()).delete()
return HttpResponse("") return HttpResponse("")
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(DiskInterface, self).dispatch(*args, **kwargs)
class StorageLinkInterface(View): class StorageLinkInterface(CSRFExemptMixin, View):
def get_vm_and_disk(self): def get_vm_and_disk(self):
vm = get_object_or_404(Instance.objects.filter(destroyed_at=None), vm = get_object_or_404(Instance.objects.filter(destroyed_at=None),
...@@ -254,12 +236,8 @@ class StorageLinkInterface(View): ...@@ -254,12 +236,8 @@ class StorageLinkInterface(View):
sl.delete() sl.delete()
return HttpResponse("") return HttpResponse("")
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(StorageLinkInterface, self).dispatch(*args, **kwargs)
class NetworkInterface(View): class NetworkInterface(CSRFExemptMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "\n".join([Network(vlan=v).render_location() response = "\n".join([Network(vlan=v).render_location()
...@@ -272,12 +250,8 @@ class NetworkInterface(View): ...@@ -272,12 +250,8 @@ class NetworkInterface(View):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
pass # we don't really want to create networks via OCCI yet pass # we don't really want to create networks via OCCI yet
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(NetworkInterface, self).dispatch(*args, **kwargs)
class VlanInterface(DetailView): class VlanInterface(CSRFExemptMixin, DetailView):
model = Vlan model = Vlan
slug_field = 'vid' slug_field = 'vid'
slug_url_kwarg = 'vid' slug_url_kwarg = 'vid'
...@@ -298,7 +272,3 @@ class VlanInterface(DetailView): ...@@ -298,7 +272,3 @@ class VlanInterface(DetailView):
Compute(instance=vm).delete() Compute(instance=vm).delete()
return HttpResponse() return HttpResponse()
@method_decorator(csrf_exempt) # decorator on post method doesn't work
def dispatch(self, *args, **kwargs):
return super(VlanInterface, self).dispatch(*args, **kwargs)
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 sign in to comment