mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
plinth/*: Rename plinth/ folder to freedombox/
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
dd0161a7e5
commit
23b6aff290
1264 files changed
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
FreedomBox app for api for android app.
|
||||
"""
|
||||
|
||||
from plinth import app as app_module
|
||||
|
||||
|
||||
class ApiApp(app_module.App):
|
||||
"""FreedomBox app for API for Android app."""
|
||||
|
||||
app_id = 'api'
|
||||
|
||||
_version = 1
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Create components for the app."""
|
||||
super().__init__()
|
||||
|
||||
info = app_module.Info(app_id=self.app_id, version=self._version,
|
||||
is_essential=True)
|
||||
self.add(info)
|
||||
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
super().setup(old_version)
|
||||
self.enable()
|
||||
@@ -0,0 +1 @@
|
||||
plinth.modules.api
|
||||
Whitespace-only changes.
@@ -0,0 +1,13 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
URLs for the plinth api for android app.
|
||||
"""
|
||||
|
||||
from django.urls import re_path
|
||||
from stronghold.decorators import public
|
||||
|
||||
from plinth.modules.api import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^api/(?P<version>[0-9]+)/shortcuts/?$', public(views.shortcuts)),
|
||||
]
|
||||
@@ -0,0 +1,62 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
FreedomBox app for api for android app.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.http import HttpResponse
|
||||
from django.templatetags.static import static
|
||||
|
||||
from plinth import frontpage
|
||||
|
||||
|
||||
def shortcuts(request, **kwargs):
|
||||
"""API view to return the list of frontpage services."""
|
||||
# XXX: Get the module (or module name) from shortcut properly.
|
||||
username = str(request.user) if request.user.is_authenticated else None
|
||||
response = get_shortcuts_as_json(username)
|
||||
return HttpResponse(json.dumps(response, cls=DjangoJSONEncoder),
|
||||
content_type='application/json')
|
||||
|
||||
|
||||
def get_shortcuts_as_json(username=None):
|
||||
shortcuts = [
|
||||
_get_shortcut_data(shortcut)
|
||||
for shortcut in frontpage.Shortcut.list(username)
|
||||
if shortcut.component_id and shortcut.is_enabled()
|
||||
]
|
||||
shortcuts += frontpage.get_custom_shortcuts()['shortcuts']
|
||||
return {'shortcuts': shortcuts}
|
||||
|
||||
|
||||
def _get_shortcut_data(shortcut):
|
||||
"""Return detailed information about a shortcut."""
|
||||
shortcut_data = {
|
||||
'name': shortcut.name,
|
||||
'description': shortcut.description,
|
||||
'icon_url': _get_icon_url(shortcut.app_id, shortcut.icon),
|
||||
'clients': copy.deepcopy(shortcut.clients),
|
||||
'tags': copy.deepcopy(shortcut.tags),
|
||||
}
|
||||
# XXX: Fix the hardcoding
|
||||
if shortcut.name.startswith('shortcut-ikiwiki-'):
|
||||
shortcut_data['clients'][0]['platforms'][0]['url'] += '/{}'.format(
|
||||
shortcut['name'])
|
||||
return shortcut_data
|
||||
|
||||
|
||||
def _get_icon_url(app_id, icon_name):
|
||||
"""Return icon path given app's ID and icon name."""
|
||||
if not icon_name:
|
||||
return None
|
||||
|
||||
if icon_name.startswith('/'):
|
||||
return icon_name
|
||||
|
||||
if app_id:
|
||||
return static(f'{app_id}') + f'/icons/{icon_name}.png'
|
||||
|
||||
return static(f'theme/icons/{icon_name}.png')
|
||||
Reference in new issue
Block a user