Added version view via REST API.

This commit is contained in:
Norman Jäckel 2015-06-18 21:48:20 +02:00
parent 4506d787ee
commit 211e39be2c
4 changed files with 46 additions and 0 deletions

View File

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

View File

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

View File

@ -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'}]})

View File

@ -0,0 +1,2 @@
__verbose_name__ = 'Plugin tests.old.utils'
__description__ = 'Description of plugin tests.old.utils'