From 7d2f9549a0ab61feaed12dabacfc5ad5ab0cd154 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 2 Sep 2016 18:49:41 +0530 Subject: [PATCH] frontpage: Fix regression in showing description - After the shortcuts were turned into a list instead of dictionary, the descriptions stopped showing in the front page due to an 'in' check that worked for dict. Fix this by changing the shortcuts into a dictionary. - Also make the key of the shortcut dict an 'id' instead of 'app' that could create confusion how an app maps to a shortcut. - Minor indentation fixes. --- plinth/frontpage.py | 29 ++++++++++------- plinth/templates/index.html | 64 ++++++++++++++++--------------------- plinth/views.py | 2 +- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/plinth/frontpage.py b/plinth/frontpage.py index 2a658162f..633133095 100644 --- a/plinth/frontpage.py +++ b/plinth/frontpage.py @@ -19,33 +19,38 @@ Manage application shortcuts on front page. """ -shortcuts = [] +shortcuts = {} def get_shortcuts(): """Return menu items in sorted order according to current locale.""" - return sorted(shortcuts, key=lambda x: x['label']) + return sorted(shortcuts.values(), key=lambda item: item['label']) -def add_shortcut(app, label, url, icon, details=None): +def add_shortcut(id, label, url, icon, details=None): """Add shortcut to front page.""" - shortcuts.append({ - 'app': app, + shortcuts[id] = { + 'id': id, 'label': label, 'url': url, 'icon': icon, 'details': details, - }) + } -def remove_shortcut(app): +def remove_shortcut(id): """ Remove shortcut from front page. - If app ends with *, remove all shortcuts with that prefix. + If id ends with *, remove all shortcuts with that prefix. """ - match = lambda x: x['app'] == app - if app[-1] == '*': - match = lambda x: x['app'].startswith(app[:-1]) + def match(item): + if id[-1] == '*': + return item['id'].startswith(id[:-1]) - shortcuts[:] = [shortcut for shortcut in shortcuts if not match(shortcut)] + return item['id'] == id + + global shortcuts + shortcuts = {id: shortcut + for id, shortcut in shortcuts.items() + if not match(shortcut)} diff --git a/plinth/templates/index.html b/plinth/templates/index.html index f511e407a..06cc31b5e 100644 --- a/plinth/templates/index.html +++ b/plinth/templates/index.html @@ -23,39 +23,37 @@ {% block content %}
- {% if shortcuts %} + {% if shortcuts %} - {% for shortcut in shortcuts %} -
- -
- {% endfor %} + {% for shortcut in shortcuts %} +
+ +
+ {% endfor %} - {% else %} + {% else %} -

- {% url 'apps:index' as apps_url %} - {% blocktrans trimmed %} +

+ {% url 'apps:index' as apps_url %} + {% blocktrans trimmed %} + Enable some applications to add + shortcuts to this page. + {% endblocktrans %} +

- Enable some applications to add - shortcuts to this page. - - {% endblocktrans %} - - - {% endif %} + {% endif %}

@@ -67,7 +65,7 @@ {% for paragraph in details %}
- {{ paragraph|safe }} + {{ paragraph|safe }}
{% endfor %} @@ -86,32 +84,26 @@

{% blocktrans trimmed %} - {{ box_name }}, a Debian pure blend, is a 100% free software self-hosting web server to deploy social applications on small machines. It provides online communication tools respecting your privacy and data ownership. - {% endblocktrans %}

{% blocktrans trimmed %} - More info about {{ box_name }} is available on the project homepage and wiki. - {% endblocktrans %}

{% blocktrans trimmed %} - This portal is a part of Plinth, the {{ box_name }} web interface. Plinth is free software, distributed under the GNU Affero General Public License, Version 3 or later. - {% endblocktrans %}

diff --git a/plinth/views.py b/plinth/views.py index f79c3f88d..2ad68c8ba 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -46,7 +46,7 @@ def index(request): return TemplateResponse(request, 'index.html', {'title': _('FreedomBox'), 'shortcuts': shortcuts, - 'selected_app': selection, + 'selected_id': selection, 'details': details, 'details_label': details_label})