diff --git a/openslides/config/api.py b/openslides/config/api.py index ea5abfbd8..1b7acbb8b 100644 --- a/openslides/config/api.py +++ b/openslides/config/api.py @@ -39,13 +39,13 @@ class ConfigHandler(object): config_variable.on_change() break - def get_data_as_dict(self): + def items(self): """ - Returns all config variables as dictionary retrieved from the config cache. + Returns key-value pairs of all config variables. """ if not hasattr(self, '_cache'): self.setup_cache() - return self._cache + return self._cache.items() def get_default(self, key): """ diff --git a/openslides/config/views.py b/openslides/config/views.py index f731e1370..104de6f14 100644 --- a/openslides/config/views.py +++ b/openslides/config/views.py @@ -1,12 +1,14 @@ from django import forms from django.contrib import messages from django.core.urlresolvers import reverse +from django.http import Http404 from django.utils.translation import ugettext as _ from openslides.utils.rest_api import response, viewsets from openslides.utils.views import FormView from .api import config +from .exceptions import ConfigNotFound from .signals import config_signal @@ -105,16 +107,32 @@ class ConfigView(FormView): class ConfigViewSet(viewsets.ViewSet): """ - API endpoint to list and update the config. + API endpoint to list, retrieve and update the config. """ def list(self, request): """ - Lists als config variables. Everybody can see this. + Lists all config variables. Everybody can see them. """ # TODO: Check if we need permission check here. - return response.Response(config.get_data_as_dict()) + data = ({'key': key, 'value': value} for key, value in config.items()) + return response.Response(data) + + def retrieve(self, request, *args, **kwargs): + """ + Retrieves one config variable. + """ + # TODO: Check if we need permission check here. + key = kwargs['pk'] + try: + data = {'key': key, 'value': config[key]} + except ConfigNotFound: + raise Http404 + return response.Response(data) def update(self, request, pk=None): + """ + TODO + """ if not request.user.has_perm('config.can_manage'): self.permission_denied(request) else: