Commit 472a77d8 authored by Alex Pyrgiotis's avatar Alex Pyrgiotis

admin: Get subclasses of AdminJSONView properly

In the `views.py` of each resource, add a JSON_CLASS attribute that
holds the class that will be used for the /json/... requests.
parent a396b494
......@@ -92,6 +92,9 @@ class AstakosUserAuthProviderJSONView(DatatablesView):
return extra_dict
JSON_CLASS = AstakosUserAuthProviderJSONView
class AstakosUserAuthProviderAction(AdminAction):
"""Class for actions on auth_providers. Derived from AdminAction.
......
......@@ -72,6 +72,9 @@ class GroupJSONView(DatatablesView):
return extra_dict
JSON_CLASS = GroupJSONView
class GroupAction(AdminAction):
"""Class for actions on groups. Derived from AdminAction.
......
......@@ -86,6 +86,9 @@ class IPLogJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = IPLogJSONView
def catalog(request):
"""List view for Cyclades ip log."""
context = {}
......
......@@ -148,6 +148,9 @@ class IPJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = IPJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
"""Apply the requested action on the specified ip."""
......
......@@ -140,6 +140,9 @@ class NetworkJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = NetworkJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
"""Apply the requested action on the specified network."""
......
......@@ -187,6 +187,9 @@ class ProjectJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = ProjectJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
"""Apply the requested action on the specified user."""
......
......@@ -158,6 +158,9 @@ class UserJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = UserJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
"""Apply the requested action on the specified user."""
......
......@@ -142,6 +142,9 @@ class VMJSONView(AdminJSONView):
return extra_dict
JSON_CLASS = VMJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
"""Apply the requested action on the specified user."""
......
......@@ -162,6 +162,8 @@ class VolumeJSONView(AdminJSONView):
}
return extra_dict
JSON_CLASS = VolumeJSONView
@has_permission_or_403(cached_actions)
def do_action(request, op, id):
......
......@@ -42,6 +42,7 @@ from synnefo_admin.admin.exceptions import AdminHttp404, AdminHttp405
from synnefo_admin import admin_settings
from synnefo_admin.admin import exceptions
from synnefo_admin.admin import tables
from synnefo_admin.admin.utils import (conditionally_gzip_page,
customize_details_context, admin_log)
......@@ -79,12 +80,11 @@ def get_view_module_or_404(view_type):
def get_json_view_or_404(view_type):
"""Try to import a josn view or raise 404."""
"""Try to import a json view or raise 404."""
mod = get_view_module_or_404(view_type)
for key, cls in inspect.getmembers(mod, inspect.isclass):
if 'JSONView' in key and not key == 'AdminJSONView':
return cls.as_view()
logging.error("The %s view is probably broken.", view_type)
# We expect that the module has a JSON_CLASS attribute with the appropriate
# subclass of django-eztable's DatatablesView.
return mod.JSON_CLASS.as_view()
def get_token_from_cookie(request, cookiename):
......
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