From a5edc113c80da9f2690b01807c6f9ef6d50acfdd Mon Sep 17 00:00:00 2001
From: Krateng
Date: Sun, 30 Aug 2020 18:56:28 +0200
Subject: [PATCH] Removed non-jinja support
---
maloja/server.py | 81 +++-------------
maloja/web/common/footer.html | 27 ------
maloja/web/common/header.html | 11 ---
maloja/web/compare.html | 78 ---------------
maloja/web/compare.py | 90 ------------------
.../jinja/partials/charts_artists_tiles.jinja | 2 +-
.../jinja/partials/charts_tracks_tiles.jinja | 2 +-
maloja/web/performance.html | 29 ------
maloja/web/performance.py | 67 -------------
maloja/web/pulse.html | 29 ------
maloja/web/pulse.py | 71 --------------
maloja/web/scrobbles.html | 29 ------
maloja/web/scrobbles.py | 56 -----------
maloja/{ => web}/static/ico/favicon.ico | Bin
maloja/{ => web}/static/js/cookies.js | 0
maloja/{ => web}/static/js/datechange.js | 0
maloja/{ => web}/static/js/manualscrobble.js | 0
maloja/{ => web}/static/js/neopolitan.js | 0
maloja/{ => web}/static/js/rangeselect.js | 0
maloja/{ => web}/static/js/search.js | 0
maloja/{ => web}/static/js/upload.js | 0
maloja/{ => web}/static/less/grisons.less | 0
maloja/{ => web}/static/less/grisonsfont.less | 0
maloja/{ => web}/static/less/maloja.less | 0
.../{ => web}/static/png/chartpos_bronze.png | Bin
maloja/{ => web}/static/png/chartpos_gold.png | Bin
.../{ => web}/static/png/chartpos_normal.png | Bin
.../{ => web}/static/png/chartpos_silver.png | Bin
maloja/{ => web}/static/png/favicon.png | Bin
.../{ => web}/static/png/record_diamond.png | Bin
maloja/{ => web}/static/png/record_gold.png | Bin
.../static/png/record_gold_original.png | Bin
.../{ => web}/static/png/record_platinum.png | Bin
maloja/{ => web}/static/png/star.png | Bin
maloja/{ => web}/static/png/star_alt.png | Bin
maloja/{ => web}/static/txt/robots.txt | 0
maloja/web/top_artists.html | 29 ------
maloja/web/top_artists.py | 40 --------
maloja/web/top_tracks.html | 29 ------
maloja/web/top_tracks.py | 37 -------
40 files changed, 15 insertions(+), 692 deletions(-)
delete mode 100644 maloja/web/common/footer.html
delete mode 100644 maloja/web/common/header.html
delete mode 100644 maloja/web/compare.html
delete mode 100644 maloja/web/compare.py
delete mode 100644 maloja/web/performance.html
delete mode 100644 maloja/web/performance.py
delete mode 100644 maloja/web/pulse.html
delete mode 100644 maloja/web/pulse.py
delete mode 100644 maloja/web/scrobbles.html
delete mode 100644 maloja/web/scrobbles.py
rename maloja/{ => web}/static/ico/favicon.ico (100%)
rename maloja/{ => web}/static/js/cookies.js (100%)
rename maloja/{ => web}/static/js/datechange.js (100%)
rename maloja/{ => web}/static/js/manualscrobble.js (100%)
rename maloja/{ => web}/static/js/neopolitan.js (100%)
rename maloja/{ => web}/static/js/rangeselect.js (100%)
rename maloja/{ => web}/static/js/search.js (100%)
rename maloja/{ => web}/static/js/upload.js (100%)
rename maloja/{ => web}/static/less/grisons.less (100%)
rename maloja/{ => web}/static/less/grisonsfont.less (100%)
rename maloja/{ => web}/static/less/maloja.less (100%)
rename maloja/{ => web}/static/png/chartpos_bronze.png (100%)
rename maloja/{ => web}/static/png/chartpos_gold.png (100%)
rename maloja/{ => web}/static/png/chartpos_normal.png (100%)
rename maloja/{ => web}/static/png/chartpos_silver.png (100%)
rename maloja/{ => web}/static/png/favicon.png (100%)
rename maloja/{ => web}/static/png/record_diamond.png (100%)
rename maloja/{ => web}/static/png/record_gold.png (100%)
rename maloja/{ => web}/static/png/record_gold_original.png (100%)
rename maloja/{ => web}/static/png/record_platinum.png (100%)
rename maloja/{ => web}/static/png/star.png (100%)
rename maloja/{ => web}/static/png/star_alt.png (100%)
rename maloja/{ => web}/static/txt/robots.txt (100%)
delete mode 100644 maloja/web/top_artists.html
delete mode 100644 maloja/web/top_artists.py
delete mode 100644 maloja/web/top_tracks.html
delete mode 100644 maloja/web/top_tracks.py
diff --git a/maloja/server.py b/maloja/server.py
index f448eed..e777c3f 100755
--- a/maloja/server.py
+++ b/maloja/server.py
@@ -52,8 +52,7 @@ HOST = settings.get_settings("HOST")
THREADS = 24
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
-WEBFOLDER = pkg_resources.resource_filename(__name__,"web")
-STATICFOLDER = pkg_resources.resource_filename(__name__,"static")
+STATICFOLDER = pkg_resources.resource_filename(__name__,"web/static")
DATAFOLDER = DATA_DIR
webserver = Bottle()
@@ -229,7 +228,7 @@ JINJA_CONTEXT = {
jinjaenv = Environment(
- loader=PackageLoader('maloja', 'web/jinja'),
+ loader=PackageLoader('maloja', "web/jinja"),
autoescape=select_autoescape(['html', 'xml'])
)
jinjaenv.globals.update(JINJA_CONTEXT)
@@ -250,78 +249,24 @@ def static_html(name):
linkheaders = ["; rel=preload; as=style"]
keys = remove_identical(FormsDict.decode(request.query))
- html_file = os.path.exists(pthjoin(WEBFOLDER,name + ".html"))
- jinja_file = os.path.exists(pthjoin(WEBFOLDER,"jinja",name + ".jinja"))
- jinja_pref = settings.get_settings("USE_JINJA")
-
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
clock = Clock()
clock.start()
- # if a jinja file exists, use this
- if ("pyhtml" not in keys and jinja_file and jinja_pref) or (jinja_file and not html_file):
- LOCAL_CONTEXT = {
- "adminmode":adminmode,
- "apikey":request.cookies.get("apikey") if adminmode else None,
- "_urikeys":keys, #temporary!
- }
- lc = LOCAL_CONTEXT
- lc["filterkeys"], lc["limitkeys"], lc["delimitkeys"], lc["amountkeys"], lc["specialkeys"] = uri_to_internal(keys)
+ LOCAL_CONTEXT = {
+ "adminmode":adminmode,
+ "apikey":request.cookies.get("apikey") if adminmode else None,
+ "_urikeys":keys, #temporary!
+ }
+ lc = LOCAL_CONTEXT
+ lc["filterkeys"], lc["limitkeys"], lc["delimitkeys"], lc["amountkeys"], lc["specialkeys"] = uri_to_internal(keys)
- template = jinjaenv.get_template(name + '.jinja')
+ template = jinjaenv.get_template(name + '.jinja')
- res = template.render(**LOCAL_CONTEXT)
- log("Generated page {name} in {time:.5f}s (Jinja)".format(name=name,time=clock.stop()),module="debug_performance")
- return res
-
-
- # if not, use the old way
- else:
- try:
- with open(pthjoin(WEBFOLDER,name + ".html")) as htmlfile:
- html = htmlfile.read()
-
- # apply global substitutions
- with open(pthjoin(WEBFOLDER,"common/footer.html")) as footerfile:
- footerhtml = footerfile.read()
- with open(pthjoin(WEBFOLDER,"common/header.html")) as headerfile:
- headerhtml = headerfile.read()
- html = html.replace("
-
-
- KEY_NAME_SELF
-
-
-
- KEY_MATCH%
-
-
-
- KEY_NAME_OTHER
-
-
-
-
-
- The size of the circle shows matching music taste.
- The fuzziness of its border indicates differences in quantity.
-
-
-
-
-
-
- Common Favorite
- KEY_BESTARTIST_LINK
-
-
-
-
-
-
-
-
-
- ",footerhtml + "").replace("",headerhtml + "")
-
-
- # If a python file exists, it provides the replacement dict for the html file
- if os.path.exists(pthjoin(WEBFOLDER,name + ".py")):
- #txt_keys = SourceFileLoader(name,"web/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
- try:
- module = importlib.import_module(".web." + name,package="maloja")
- txt_keys,resources = module.instructions(keys)
- except Exception as e:
- log("Error in website generation: " + str(sys.exc_info()),module="error")
- raise
-
- # add headers for server push
- for resource in resources:
- if all(ord(c) < 128 for c in resource["file"]):
- # we can only put ascii stuff in the http header
- linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"])
-
- # apply key substitutions
- for k in txt_keys:
- if isinstance(txt_keys[k],list):
- # if list, we replace each occurence with the next item
- for element in txt_keys[k]:
- html = html.replace(k,element,1)
- else:
- html = html.replace(k,txt_keys[k])
-
-
- response.set_header("Link",",".join(linkheaders))
- log("Generated page {name} in {time:.5f}s (Python+HTML)".format(name=name,time=clock.stop()),module="debug_performance")
- return html
-
- except:
- abort(404, "Page does not exist")
+ res = template.render(**LOCAL_CONTEXT)
+ log("Generated page {name} in {time:.5f}s (Jinja)".format(name=name,time=clock.stop()),module="debug_performance")
+ return res
# Shortlinks
diff --git a/maloja/web/common/footer.html b/maloja/web/common/footer.html
deleted file mode 100644
index 4f4a96f..0000000
--- a/maloja/web/common/footer.html
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
diff --git a/maloja/web/common/header.html b/maloja/web/common/header.html
deleted file mode 100644
index ba3db6d..0000000
--- a/maloja/web/common/header.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/maloja/web/compare.html b/maloja/web/compare.html
deleted file mode 100644
index ff5d3bf..0000000
--- a/maloja/web/compare.html
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
-
-
-
Maloja - Compare
-
-
-
-
-