mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
customization: Show custom shortcuts on frontpage
Closes #1379 Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
5e06017e5c
commit
1307e474da
7 files changed
+63
-28
No files matched your search
@@ -20,13 +20,12 @@ FreedomBox app for api for android app.
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.http import HttpResponse
|
||||
from django.templatetags.static import static
|
||||
|
||||
from plinth import cfg, frontpage, module_loader
|
||||
from plinth import frontpage, module_loader
|
||||
from plinth.modules import names
|
||||
|
||||
|
||||
@@ -54,24 +53,14 @@ def shortcuts(request, **kwargs):
|
||||
def get_shortcuts_as_json(username=None):
|
||||
shortcuts = [
|
||||
_get_shortcut_data(shortcut['id'].split('_')[0], shortcut)
|
||||
for shortcut in frontpage.get_shortcuts(username)
|
||||
for shortcut in frontpage.get_shortcuts(username) if shortcut['id']
|
||||
]
|
||||
custom_shortcuts = get_custom_shortcuts()
|
||||
custom_shortcuts = frontpage.get_custom_shortcuts()
|
||||
if custom_shortcuts:
|
||||
shortcuts += custom_shortcuts['shortcuts']
|
||||
return {'shortcuts': shortcuts}
|
||||
|
||||
|
||||
def get_custom_shortcuts():
|
||||
cfg_dir = os.path.dirname(cfg.config_file)
|
||||
shortcuts_file = os.path.join(cfg_dir, 'custom-shortcuts.json')
|
||||
if os.path.isfile(shortcuts_file) and os.stat(shortcuts_file).st_size:
|
||||
with open(shortcuts_file) as shortcuts:
|
||||
custom_shortcuts = json.load(shortcuts)
|
||||
return custom_shortcuts
|
||||
return None
|
||||
|
||||
|
||||
def _get_shortcut_data(module_name, shortcut):
|
||||
"""Return detailed information about a shortcut."""
|
||||
module = module_loader.loaded_modules[module_name]
|
||||
|
||||
@@ -44,7 +44,8 @@ def domain_label_validator(domainname):
|
||||
|
||||
def get_default_app_choices():
|
||||
shortcuts = frontpage.get_shortcuts(web_apps_only=True, sort_by='name')
|
||||
apps = [(shortcut['id'], shortcut['name']) for shortcut in shortcuts]
|
||||
apps = [(shortcut['id'], shortcut['name']) for shortcut in shortcuts
|
||||
if shortcut['id']]
|
||||
return [('plinth', 'FreedomBox Service (Plinth)')] + apps
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user