diff --git a/plinth/modules/api/test/test_get_apps.py b/plinth/modules/api/test/test_get_apps.py index 2b84f0a76..2d4a33a84 100644 --- a/plinth/modules/api/test/test_get_apps.py +++ b/plinth/modules/api/test/test_get_apps.py @@ -35,7 +35,7 @@ class TestApi(unittest.TestCase): expected = [{ 'name': 'someName', 'short_description': 'someDescription', - 'icon_url': 'static/theme/icons/someIconURl.svg' + 'icon': 'static/theme/icons/someIconURl.svg' }] def test_get_app_payload(self): diff --git a/plinth/modules/api/urls.py b/plinth/modules/api/urls.py index 26f03d8bd..d1bfbb0f8 100644 --- a/plinth/modules/api/urls.py +++ b/plinth/modules/api/urls.py @@ -26,5 +26,5 @@ from plinth.modules.api.views import get_apps, get_access_info urlpatterns = [ url(r'^api/(?P[0-9]+)/services/?$', public(get_apps)), - url(r'^api/(?P[0-9]+)/accessInfo/?$', public(get_access_info)) + url(r'^api/(?P[0-9]+)/access-info/?$', public(get_access_info)) ] \ No newline at end of file diff --git a/plinth/modules/api/views.py b/plinth/modules/api/views.py index b7076d401..e6a02e0b8 100644 --- a/plinth/modules/api/views.py +++ b/plinth/modules/api/views.py @@ -34,19 +34,18 @@ def get_apps(request, **kwargs): def get_app_payload(enabled_apps): - service_apps = [] - for app in enabled_apps: - app['icon_url'] = 'static/theme/icons/' + app['icon'] + '.svg' - app_required_fields = dict((key, app[key]) for key in ('name', 'short_description', 'icon_url')) - apps = {key: str(value) for key, value in app_required_fields.items()} - service_apps.append(apps) + def get_value(key, value): + return str(value) if key != 'icon' \ + else 'static/theme/icons/{}.svg'.format(value) - return service_apps + def filter_app_data(app): + return {key: get_value(key, value) for key, value in app.items() + if key in ('name', 'short_description', 'icon')} + + return list(map(filter_app_data, enabled_apps)) def get_access_info(request, **kwargs): - domain_types = get_domain_types() - response = {} - for domain_type in domain_types: - response[domain_type] = get_domain(domain_type) - return HttpResponse(json.dumps(response), content_type="application/json") \ No newline at end of file + response = {domain_type: get_domain(domain_type) for domain_type in + get_domain_types()} + return HttpResponse(json.dumps(response), content_type="application/json")