From 211e39be2c29acf5f39cfb2486c4fc727c34a03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Thu, 18 Jun 2015 21:48:20 +0200 Subject: [PATCH] Added version view via REST API. --- openslides/core/urls.py | 3 +++ openslides/core/views.py | 25 +++++++++++++++++++++++++ tests/integration/core/test_views.py | 16 ++++++++++++++++ tests/old/utils/__init__.py | 2 ++ 4 files changed, 46 insertions(+) diff --git a/openslides/core/urls.py b/openslides/core/urls.py index 88093fd89..9bcf92ec4 100644 --- a/openslides/core/urls.py +++ b/openslides/core/urls.py @@ -7,4 +7,7 @@ urlpatterns = patterns( url(r'^core/url_patterns/$', views.UrlPatternsView.as_view(), name='core_url_patterns'), + url(r'^core/version/$', + views.VersionView.as_view(), + name='core_version'), ) diff --git a/openslides/core/views.py b/openslides/core/views.py index ae11d6b5c..3ac43a34b 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -1,10 +1,17 @@ import re +from django.conf import settings from django.contrib.staticfiles import finders from django.core.urlresolvers import get_resolver from django.http import HttpResponse +from openslides import __version__ as version 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.rest_api import ( ModelViewSet, ReadOnlyModelViewSet, @@ -191,3 +198,21 @@ class UrlPatternsView(utils_views.APIView): url, url_kwargs = normalized_regex_bits[0] result[pattern_name] = self.URL_KWARGS_REGEX.sub(r':\1', url) return result + + +class VersionView(utils_views.APIView): + """ + Returns a dictionary with the OpenSlides version and the version of all + plugins. + """ + http_method_names = ['get'] + + def get_context_data(self, **context): + result = dict(openslides_version=version, plugins=[]) + # Versions of plugins. + for plugin in settings.INSTALLED_PLUGINS: + result['plugins'].append({ + 'verbose_name': get_plugin_verbose_name(plugin), + 'description': get_plugin_description(plugin), + 'version': get_plugin_version(plugin)}) + return result diff --git a/tests/integration/core/test_views.py b/tests/integration/core/test_views.py index 4b09e8638..d7a9efeb1 100644 --- a/tests/integration/core/test_views.py +++ b/tests/integration/core/test_views.py @@ -3,6 +3,7 @@ import json from django.core.urlresolvers import reverse from rest_framework import status +from openslides import __version__ as version from openslides.core.models import CustomSlide, Projector from openslides.utils.test import TestCase @@ -44,3 +45,18 @@ class ProjectorAPI(TestCase): 'projector_elements': [ {'name': 'invalid_slide', 'error': 'Projector element does not exist.'}]}) + + +class VersionView(TestCase): + """ + Tests the version info view. + """ + def test_get(self): + self.client.login(username='admin', password='admin') + response = self.client.get(reverse('core_version')) + self.assertEqual(json.loads(response.content.decode()), { + 'openslides_version': version, + 'plugins': [ + {'verbose_name': 'Plugin tests.old.utils', + 'description': 'Description of plugin tests.old.utils', + 'version': 'unknown'}]}) diff --git a/tests/old/utils/__init__.py b/tests/old/utils/__init__.py index e69de29bb..36b96fbb1 100644 --- a/tests/old/utils/__init__.py +++ b/tests/old/utils/__init__.py @@ -0,0 +1,2 @@ +__verbose_name__ = 'Plugin tests.old.utils' +__description__ = 'Description of plugin tests.old.utils'