From 7644cb9a09d981986300d580b13de95ebae53144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Tue, 6 Jan 2015 00:04:36 +0100 Subject: [PATCH] Added api viewset for custom slides. --- openslides/core/apps.py | 5 +++++ openslides/core/serializers.py | 11 +++++++++++ openslides/core/views.py | 21 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 openslides/core/serializers.py diff --git a/openslides/core/apps.py b/openslides/core/apps.py index fb0fa62e0..caafdbf69 100644 --- a/openslides/core/apps.py +++ b/openslides/core/apps.py @@ -13,7 +13,9 @@ class CoreAppConfig(AppConfig): # Import all required stuff. from openslides.config.signals import config_signal from openslides.projector.api import register_slide_model + from openslides.utils.rest_api import router from .signals import setup_general_config + from .views import CustomSlideViewSet # Connect signals. config_signal.connect(setup_general_config, dispatch_uid='setup_general_config') @@ -21,3 +23,6 @@ class CoreAppConfig(AppConfig): # Register slides. CustomSlide = self.get_model('CustomSlide') register_slide_model(CustomSlide, 'core/customslide_slide.html') + + # Register viewset. + router.register('core/customslide', CustomSlideViewSet) diff --git a/openslides/core/serializers.py b/openslides/core/serializers.py new file mode 100644 index 000000000..1a052dd27 --- /dev/null +++ b/openslides/core/serializers.py @@ -0,0 +1,11 @@ +from rest_framework import serializers + +from .models import CustomSlide + + +class CustomSlideSerializer(serializers.ModelSerializer): + """ + Serializer for a core.models.CustomSlide objects. + """ + class Meta: + model = CustomSlide diff --git a/openslides/core/views.py b/openslides/core/views.py index 1e41107ec..fade07f12 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -12,14 +12,16 @@ from haystack.views import SearchView as _SearchView from openslides import get_version as get_openslides_version from openslides import get_git_commit_id, RELEASE from openslides.config.api import config +from openslides.utils import rest_api +from openslides.utils import views as utils_views from openslides.utils.plugins import get_plugin_description, get_plugin_verbose_name, get_plugin_version from openslides.utils.signals import template_manipulation -from openslides.utils import views as utils_views from openslides.utils.widgets import Widget from .forms import SelectWidgetsForm from .models import CustomSlide, Tag from .exceptions import TagException +from .serializers import CustomSlideSerializer class DashboardView(utils_views.AjaxMixin, utils_views.TemplateView): @@ -291,3 +293,20 @@ class TagListView(utils_views.AjaxMixin, utils_views.ListView): action=getattr(self, 'action', None), error=getattr(self, 'error', None), **context) + + +class CustomSlideViewSet(rest_api.viewsets.ModelViewSet): + """ + API endpoint to view, edit and delete custom slides. + """ + model = CustomSlide + queryset = CustomSlide.objects.all() + serializer_class = CustomSlideSerializer + + def check_permissions(self, request): + """ + Calls self.permission_denied() if the requesting user has not the + permission to manage. + """ + if not request.user.has_perm('core.can_manage_projector'): + self.permission_denied(request)