From 49228343b73092d1c27ae4c29fbc7ed4416405be Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 27 Nov 2019 00:44:02 -0800 Subject: [PATCH] toolbar: Rewamp toolbar code for simplicity and to fix issues - Fix problems with turbolinks. Closes: #1712. - Remove unnecessary nesting of - - - {% elif clients|get_self_hosted_web_apps|length == 1 %} - - - - - {% else %} - - {% endif %} - - {% block diagnostics %} - {% if diagnostics_module_name %} - -
- - -
- + + {% endif %} - {% endblock %} - - - -
- {% include "clients.html" with clients=clients enabled=is_enabled %} -
- - {% endif %} -{% endblock toolbar %} \ No newline at end of file + {% if client_platforms.web|length > 1 or client_platforms.other %} + + {% endif %} + {% endwith %} + {% endif %} + + {% if diagnostics_module_name %} + +
+ + +
+ {% endif %} + + +
+ {% include "clients.html" with clients=clients enabled=is_enabled %} +
+ + +{% endblock toolbar %} diff --git a/plinth/templatetags/plinth_extras.py b/plinth/templatetags/plinth_extras.py index 2a0047d06..1ac05b0e0 100644 --- a/plinth/templatetags/plinth_extras.py +++ b/plinth/templatetags/plinth_extras.py @@ -76,30 +76,22 @@ def lookup(dictionary, key): return dictionary[key] -@register.filter(name='is_relative_url') -def is_relative_url(url): - """Check if the given link is relative or not""" - parsed_url = urlparse(url) +def _is_relative_url(url): + """Check if the given link is relative or not.""" + parsed_url = urlparse(str(url)) return not parsed_url.netloc -@register.filter(name='get_self_hosted_web_apps') -def get_self_hosted_web_apps(clients): - """Get a list of self hosted web apps""" - clients_with_web_platforms = list( - filter( - lambda c: len( - list(filter(lambda p: p['type'] == 'web', c['platforms']))), - clients)) - clients_with_self_hosted_apps = list( - filter( - lambda c: len( - list( - filter(lambda p: is_relative_url(p['url']), c['platforms']) - )), clients_with_web_platforms)) - mapped_list = list( - map( - lambda c: list(filter(lambda p: p['type'] == 'web', c['platforms']) - ), clients_with_self_hosted_apps)) +@register.filter(name='clients_get_platforms') +def clients_get_platforms(clients): + """Return lists of self hosted platforms and all other platforms.""" + other = [] + web = [] + for client in clients: + for platform in client['platforms']: + if platform['type'] == 'web' and _is_relative_url(platform['url']): + web.append(platform) + else: + other.append(platform) - return [elm for clnt in mapped_list for elm in clnt] + return {'web': web, 'other': other}