mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Refactor functions for api
- Change url to use hyphen instead of camelCase - Refactor functions to be immutable Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
c0fb2abf46
commit
fbe08443f4
@ -35,7 +35,7 @@ class TestApi(unittest.TestCase):
|
|||||||
expected = [{
|
expected = [{
|
||||||
'name': 'someName',
|
'name': 'someName',
|
||||||
'short_description': 'someDescription',
|
'short_description': 'someDescription',
|
||||||
'icon_url': 'static/theme/icons/someIconURl.svg'
|
'icon': 'static/theme/icons/someIconURl.svg'
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def test_get_app_payload(self):
|
def test_get_app_payload(self):
|
||||||
|
|||||||
@ -26,5 +26,5 @@ from plinth.modules.api.views import get_apps, get_access_info
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^api/(?P<version>[0-9]+)/services/?$', public(get_apps)),
|
url(r'^api/(?P<version>[0-9]+)/services/?$', public(get_apps)),
|
||||||
url(r'^api/(?P<version>[0-9]+)/accessInfo/?$', public(get_access_info))
|
url(r'^api/(?P<version>[0-9]+)/access-info/?$', public(get_access_info))
|
||||||
]
|
]
|
||||||
@ -34,19 +34,18 @@ def get_apps(request, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def get_app_payload(enabled_apps):
|
def get_app_payload(enabled_apps):
|
||||||
service_apps = []
|
def get_value(key, value):
|
||||||
for app in enabled_apps:
|
return str(value) if key != 'icon' \
|
||||||
app['icon_url'] = 'static/theme/icons/' + app['icon'] + '.svg'
|
else 'static/theme/icons/{}.svg'.format(value)
|
||||||
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)
|
|
||||||
|
|
||||||
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):
|
def get_access_info(request, **kwargs):
|
||||||
domain_types = get_domain_types()
|
response = {domain_type: get_domain(domain_type) for domain_type in
|
||||||
response = {}
|
get_domain_types()}
|
||||||
for domain_type in domain_types:
|
|
||||||
response[domain_type] = get_domain(domain_type)
|
|
||||||
return HttpResponse(json.dumps(response), content_type="application/json")
|
return HttpResponse(json.dumps(response), content_type="application/json")
|
||||||
Loading…
x
Reference in New Issue
Block a user