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.
This commit is contained in:
Sunil Mohan Adapa 2016-09-02 18:49:41 +05:30
parent 3763e28d15
commit 7d2f9549a0
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 46 additions and 49 deletions

View File

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

View File

@ -23,39 +23,37 @@
{% block content %}
<div class="row">
{% if shortcuts %}
{% if shortcuts %}
{% for shortcut in shortcuts %}
<div class="col-sm-4">
<ul class="nav nav-pills nav-stacked">
{% if selected_app == shortcut.app %}
<li class="active">
<a href="{{ shortcut.url }}" class="active">
{% else %}
<li>
<a href="{{ shortcut.url }}">
{% endif %}
<span class="{{ shortcut.icon }} glyphicon"></span>
{{ shortcut.label }}
</a>
</li>
</ul>
</div>
{% endfor %}
{% for shortcut in shortcuts %}
<div class="col-sm-4">
<ul class="nav nav-pills nav-stacked">
{% if selected_id == shortcut.id %}
<li class="active">
<a href="{{ shortcut.url }}" class="active">
{% else %}
<li>
<a href="{{ shortcut.url }}">
{% endif %}
<span class="{{ shortcut.icon }} glyphicon"></span>
{{ shortcut.label }}
</a>
</li>
</ul>
</div>
{% endfor %}
{% else %}
{% else %}
<h4>
{% url 'apps:index' as apps_url %}
{% blocktrans trimmed %}
<h4>
{% url 'apps:index' as apps_url %}
{% blocktrans trimmed %}
Enable some <a href="{{ apps_url }}">applications</a> to add
shortcuts to this page.
{% endblocktrans %}
</h4>
Enable some <a href="{{ apps_url }}">applications</a> to add
shortcuts to this page.
{% endblocktrans %}
</h4>
{% endif %}
{% endif %}
</div>
<br>
@ -67,7 +65,7 @@
{% for paragraph in details %}
<div class="panel-body">
{{ paragraph|safe }}
{{ paragraph|safe }}
</div>
{% endfor %}
</div>
@ -86,32 +84,26 @@
<p>
{% 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 %}
</p>
<p>
{% blocktrans trimmed %}
More info about {{ box_name }} is available on the
project <a href="https://freedombox.org">homepage</a>
and <a href="https://wiki.debian.org/FreedomBox">wiki</a>.
{% endblocktrans %}
</p>
<p>
{% 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 %}
</p>

View File

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