frontpage: Add shortcut for each ikiwiki wiki and blog

This commit is contained in:
James Valleroy 2016-08-30 08:42:33 -04:00 committed by Sunil Mohan Adapa
parent 3eb7dd914a
commit fa0bc7471f
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 31 additions and 13 deletions

View File

@ -37,6 +37,15 @@ def add_shortcut(app, label, url, icon):
def remove_shortcut(app):
"""Remove shortcut from front page."""
if app in shortcuts:
"""
Remove shortcut from front page.
If app ends with *, remove all shortcuts with that prefix.
"""
if app[-1] == '*':
remove = [k for k in shortcuts if k.startswith(app[:-1])]
for k in remove:
del shortcuts[k]
elif app in shortcuts:
del shortcuts[app]

View File

@ -60,7 +60,7 @@ def init():
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
add_shortcuts()
def setup(helper, old_version=None):
@ -68,11 +68,14 @@ def setup(helper, old_version=None):
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'ikiwiki', ['setup'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('ikiwiki', title, '/ikiwiki', 'glyphicon-edit')
def add_shortcuts():
sites = actions.run('ikiwiki', ['get-sites']).split('\n')
sites = [name for name in sites if name != '']
for site in sites:
frontpage.add_shortcut(
'ikiwiki_' + site, site, '/ikiwiki/' + site, 'glyphicon-edit')
def is_enabled():
@ -83,13 +86,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('ikiwiki', ['enable'])
add_shortcut()
add_shortcuts()
def disable():
"""Enable the module."""
actions.superuser_run('ikiwiki', ['disable'])
frontpage.remove_shortcut('ikiwiki')
frontpage.remove_shortcut('ikiwiki*')
def diagnose():

View File

@ -26,6 +26,7 @@ from django.urls import reverse_lazy
from django.utils.translation import ugettext as _, ugettext_lazy
from plinth import actions
from plinth import frontpage
from plinth import views
from plinth.modules import ikiwiki
@ -81,6 +82,10 @@ def create(request):
form.cleaned_data['admin_name'],
form.cleaned_data['admin_password'])
site = form.cleaned_data['name'].replace(' ', '')
frontpage.add_shortcut('ikiwiki_' + site, site,
'/ikiwiki/' + site, 'glyphicon-edit')
return redirect(reverse_lazy('ikiwiki:manage'))
else:
form = IkiwikiCreateForm(prefix='ikiwiki')
@ -129,6 +134,7 @@ def delete(request, name):
try:
actions.superuser_run('ikiwiki', ['delete', '--name', name])
messages.success(request, _('{name} deleted.').format(name=name))
frontpage.remove_shortcut('ikiwiki_' + name)
except actions.ActionError as error:
messages.error(request, _('Could not delete {name}: {error}')
.format(name=name, error=error))

View File

@ -56,11 +56,11 @@
{% block sidebar %}
<h4>
{% blocktrans trimmed %}
Welcome to {{ box_name }}!
{% endblocktrans %}
</h4>
<h4>
{% blocktrans trimmed %}
Welcome to {{ box_name }}!
{% endblocktrans %}
</h4>
<p>
{% blocktrans trimmed %}