Added api viewset for custom slides.

This commit is contained in:
Norman Jäckel 2015-01-06 00:04:36 +01:00
parent 7ed5d2fc43
commit 7644cb9a09
3 changed files with 36 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)