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:
Prachi Srivastava 2017-09-08 12:26:14 +05:30 committed by Joseph Nuthalpati
parent c0fb2abf46
commit fbe08443f4
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35
3 changed files with 13 additions and 14 deletions

View File

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

View File

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

View File

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