From cf95e4e1c68bbf85625fd1209db6aaaf048602b2 Mon Sep 17 00:00:00 2001 From: zPlus Date: Wed, 20 Nov 2024 13:39:50 +0100 Subject: [PATCH] Move license queries from templates to controllers. --- app.py | 30 ++++++++++++++++++++++++++++- pages/license.html | 12 ------------ pages/templates/license/license.tpl | 7 ------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app.py b/app.py index 8c94ea8..ed3d417 100755 --- a/app.py +++ b/app.py @@ -229,12 +229,40 @@ def library_item(item_id): return template('templates/library/item.tpl', item_id=item_id, plaintext=item_plaintext) +@bottle.get('/license', name='license_list') +def license_list(): + """ + List all licenses. + """ + + # TODO sanitize input + data = query(f""" + PREFIX license: + + SELECT * + WHERE {{ + ?license license:id ?id ; + license:name ?name . + }} + ORDER BY ASC(UCASE(?name)) + """) + + return template('license.html', data=data) + @bottle.get('/license/', name='license') def license(id): """ + Show a single license """ - return template('templates/license/license.tpl', license_id=id) + # TODO sanitize input + data = query(f""" + PREFIX license: + + DESCRIBE + """) + + return template('templates/license/license.tpl', data=data) @bottle.get('/manpages//', name='manpages_distribution') def manpages_distribution(distribution, version): diff --git a/pages/license.html b/pages/license.html index 01bb8dc..c1792cc 100644 --- a/pages/license.html +++ b/pages/license.html @@ -1,17 +1,5 @@ {% extends "templates/base.tpl" %} -{% set data = query(""" - PREFIX license: - - SELECT * - WHERE { - ?license license:id ?id ; - license:name ?name. - } - ORDER BY ASC(UCASE(?name)) - """) -%} - {% block title %}Licenses{% endblock %} {% block body %} diff --git a/pages/templates/license/license.tpl b/pages/templates/license/license.tpl index 228e9d2..0ec6978 100644 --- a/pages/templates/license/license.tpl +++ b/pages/templates/license/license.tpl @@ -1,12 +1,5 @@ {% extends "templates/base.tpl" %} -{% set data = query(""" - PREFIX license: - - DESCRIBE license:""" + license_id + """ - """) -%} - {% block title %}{{ data['license:name'] }}{% endblock %} {% block body %}