mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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 = [{
|
||||
'name': 'someName',
|
||||
'short_description': 'someDescription',
|
||||
'icon_url': 'static/theme/icons/someIconURl.svg'
|
||||
'icon': 'static/theme/icons/someIconURl.svg'
|
||||
}]
|
||||
|
||||
def test_get_app_payload(self):
|
||||
|
||||
@ -26,5 +26,5 @@ from plinth.modules.api.views import get_apps, get_access_info
|
||||
|
||||
urlpatterns = [
|
||||
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):
|
||||
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")
|
||||
response = {domain_type: get_domain(domain_type) for domain_type in
|
||||
get_domain_types()}
|
||||
return HttpResponse(json.dumps(response), content_type="application/json")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user