diff --git a/plinth/templates/app.html b/plinth/templates/app.html index 8e18f7994..9031d5faf 100644 --- a/plinth/templates/app.html +++ b/plinth/templates/app.html @@ -57,7 +57,7 @@

{% endif %} - {% include "toolbar.html" with clients=clients enabled=is_enabled diagnostics_module_name=diagnostics_module_name %} + {% include "toolbar.html" with enabled=is_enabled %} {% block subsubmenu %} {% if subsubmenu %} diff --git a/plinth/templates/toolbar.html b/plinth/templates/toolbar.html index b2152535b..33514589e 100644 --- a/plinth/templates/toolbar.html +++ b/plinth/templates/toolbar.html @@ -23,83 +23,54 @@ {% load static %} {% block toolbar %} - {% if clients %} -
-
-
- {% if clients|get_self_hosted_web_apps|length == 1 and clients|length == 1 %} +
+
-
-
- {% 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}