diff --git a/maloja/data_files/settings/default.ini b/maloja/data_files/settings/default.ini index 1784fc1..b94afa9 100644 --- a/maloja/data_files/settings/default.ini +++ b/maloja/data_files/settings/default.ini @@ -27,7 +27,7 @@ TRACK_SEARCH_PROVIDER = None DB_CACHE_SIZE = 8192 # how many MB on disk each database cache should have available. INVALID_ARTISTS = ["[Unknown Artist]","Unknown Artist","Spotify"] -REMOVE_FROM_TITLE = ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)"] +REMOVE_FROM_TITLE = ["(Original Mix)","(Radio Edit)","(Album Version)","(Explicit Version)","(Bonus Track)"] USE_PARSE_PLUGINS = no [Local Images] @@ -61,6 +61,7 @@ NAME = None EXPERIMENTAL_FEATURES = no USE_PYHP = no #not recommended at the moment +USE_JINJA = no #overwrites pyhp preference FEDERATION = yes #does nothing yet UPDATE_AFTER_CRASH = no #update when server is automatically restarted DAILY_RESTART = 2 # hour of day. no / none means no daily restarts diff --git a/maloja/server.py b/maloja/server.py index b012bdc..9003c9a 100755 --- a/maloja/server.py +++ b/maloja/server.py @@ -32,6 +32,7 @@ import signal import os import setproctitle import pkg_resources +import math # url handling import urllib @@ -170,22 +171,75 @@ def static(name,ext): return response +engine_prio = settings.get_settings("WEB_ENGINE_PRIORITY") +engines = { + "python":{"filetypes":["html","py"],"folder":"python"}, + "pyhp":{"filetypes":["pyhp"],"folder":"pyhp"}, + "jinja":{"filetypes":[],"folder":"jinja"} +} + + +JINJA_CONTEXT = { + # maloja + "db": database, + "htmlmodules": htmlmodules, + "htmlgenerators": htmlgenerators, + "malojatime": malojatime, + "utilities": utilities, + "urihandler": urihandler, + "settings": settings.get_settings, + # external + "urllib": urllib, + "math":math, + # config + "ranges": [ + ('day','7 days',malojatime.today().next(-6),'day',7), + ('week','12 weeks',malojatime.thisweek().next(-11),'week',12), + ('month','12 months',malojatime.thismonth().next(-11),'month',12), + ('year','10 years',malojatime.thisyear().next(-9),'year',12) + ] +} + +from jinja2 import Environment, PackageLoader, select_autoescape +jinjaenv = Environment( + loader=PackageLoader('maloja', 'web/jinja'), + autoescape=select_autoescape(['html', 'xml']) +) + @webserver.route("/") def static_html(name): linkheaders = ["; rel=preload; as=style"] keys = remove_identical(FormsDict.decode(request.query)) - pyhp_file = os.path.exists(pthjoin(WEBFOLDER,name + ".pyhp")) + + pyhp_file = os.path.exists(pthjoin(WEBFOLDER,"pyhp",name + ".pyhp")) html_file = os.path.exists(pthjoin(WEBFOLDER,name + ".html")) + jinja_file = os.path.exists(pthjoin(WEBFOLDER,"jinja",name + ".jinja")) pyhp_pref = settings.get_settings("USE_PYHP") + jinja_pref = settings.get_settings("USE_JINJA") adminmode = request.cookies.get("adminmode") == "true" and database.checkAPIkey(request.cookies.get("apikey")) is not False clock = Clock() clock.start() + # if a jinja file exists, use this + if (jinja_file and jinja_pref) or (jinja_file and not html_file and not pyhp_file): + LOCAL_CONTEXT = { + "adminmode":adminmode, + "apikey":request.cookies.get("apikey") if adminmode else None, + "_urikeys":keys #temporary! + } + LOCAL_CONTEXT["filterkeys"], LOCAL_CONTEXT["limitkeys"], LOCAL_CONTEXT["delimitkeys"], LOCAL_CONTEXT["amountkeys"] = uri_to_internal(keys) + + template = jinjaenv.get_template(name + '.jinja') + + res = template.render(**JINJA_CONTEXT,**LOCAL_CONTEXT) + log("Generated page {name} in {time}s (Jinja)".format(name=name,time=clock.stop()),module="debug") + return res + # if a pyhp file exists, use this - if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file): + elif (pyhp_file and pyhp_pref) or (pyhp_file and not html_file): #things we expose to the pyhp pages environ = { @@ -207,7 +261,7 @@ def static_html(name): environ["_urikeys"] = keys #temporary! #response.set_header("Content-Type","application/xhtml+xml") - res = pyhpfile(pthjoin(WEBFOLDER,name + ".pyhp"),environ) + res = pyhpfile(pthjoin(WEBFOLDER,"pyhp",name + ".pyhp"),environ) log("Generated page {name} in {time}s (PYHP)".format(name=name,time=clock.stop()),module="debug") return res diff --git a/maloja/web/jinja/base.jinja b/maloja/web/jinja/base.jinja new file mode 100644 index 0000000..58d5aef --- /dev/null +++ b/maloja/web/jinja/base.jinja @@ -0,0 +1,56 @@ + + + + + + {% block title %}{% endblock %} + + + + + + + + + + {% block scripts %}{% endblock %} + + + + + {% block content %} + + {% endblock %} + + + + + +
+ +
+ + + diff --git a/maloja/web/admin.pyhp b/maloja/web/pyhp/admin.pyhp similarity index 100% rename from maloja/web/admin.pyhp rename to maloja/web/pyhp/admin.pyhp diff --git a/maloja/web/artist.pyhp b/maloja/web/pyhp/artist.pyhp similarity index 100% rename from maloja/web/artist.pyhp rename to maloja/web/pyhp/artist.pyhp diff --git a/maloja/web/charts_artists.pyhp b/maloja/web/pyhp/charts_artists.pyhp similarity index 100% rename from maloja/web/charts_artists.pyhp rename to maloja/web/pyhp/charts_artists.pyhp diff --git a/maloja/web/charts_tracks.pyhp b/maloja/web/pyhp/charts_tracks.pyhp similarity index 100% rename from maloja/web/charts_tracks.pyhp rename to maloja/web/pyhp/charts_tracks.pyhp diff --git a/maloja/web/pyhp/common/footer.html b/maloja/web/pyhp/common/footer.html new file mode 100644 index 0000000..7de3865 --- /dev/null +++ b/maloja/web/pyhp/common/footer.html @@ -0,0 +1,27 @@ + + +
+ +
diff --git a/maloja/web/pyhp/common/header.html b/maloja/web/pyhp/common/header.html new file mode 100644 index 0000000..ba3db6d --- /dev/null +++ b/maloja/web/pyhp/common/header.html @@ -0,0 +1,11 @@ + + + + + + diff --git a/maloja/web/errors/generic.pyhp b/maloja/web/pyhp/errors/generic.pyhp similarity index 100% rename from maloja/web/errors/generic.pyhp rename to maloja/web/pyhp/errors/generic.pyhp diff --git a/maloja/web/partial/charts_artists.pyhp b/maloja/web/pyhp/partial/charts_artists.pyhp similarity index 100% rename from maloja/web/partial/charts_artists.pyhp rename to maloja/web/pyhp/partial/charts_artists.pyhp diff --git a/maloja/web/partial/charts_artists_tiles.pyhp b/maloja/web/pyhp/partial/charts_artists_tiles.pyhp similarity index 100% rename from maloja/web/partial/charts_artists_tiles.pyhp rename to maloja/web/pyhp/partial/charts_artists_tiles.pyhp diff --git a/maloja/web/partial/charts_tracks.pyhp b/maloja/web/pyhp/partial/charts_tracks.pyhp similarity index 100% rename from maloja/web/partial/charts_tracks.pyhp rename to maloja/web/pyhp/partial/charts_tracks.pyhp diff --git a/maloja/web/partial/charts_tracks_tiles.pyhp b/maloja/web/pyhp/partial/charts_tracks_tiles.pyhp similarity index 100% rename from maloja/web/partial/charts_tracks_tiles.pyhp rename to maloja/web/pyhp/partial/charts_tracks_tiles.pyhp diff --git a/maloja/web/partial/link_track_scrobbles.pyhp b/maloja/web/pyhp/partial/link_track_scrobbles.pyhp similarity index 100% rename from maloja/web/partial/link_track_scrobbles.pyhp rename to maloja/web/pyhp/partial/link_track_scrobbles.pyhp diff --git a/maloja/web/partial/pagination.pyhp b/maloja/web/pyhp/partial/pagination.pyhp similarity index 100% rename from maloja/web/partial/pagination.pyhp rename to maloja/web/pyhp/partial/pagination.pyhp diff --git a/maloja/web/partial/performance.pyhp b/maloja/web/pyhp/partial/performance.pyhp similarity index 100% rename from maloja/web/partial/performance.pyhp rename to maloja/web/pyhp/partial/performance.pyhp diff --git a/maloja/web/partial/pulse.pyhp b/maloja/web/pyhp/partial/pulse.pyhp similarity index 100% rename from maloja/web/partial/pulse.pyhp rename to maloja/web/pyhp/partial/pulse.pyhp diff --git a/maloja/web/summary.pyhp b/maloja/web/pyhp/summary.pyhp similarity index 100% rename from maloja/web/summary.pyhp rename to maloja/web/pyhp/summary.pyhp diff --git a/maloja/web/track.pyhp b/maloja/web/pyhp/track.pyhp similarity index 100% rename from maloja/web/track.pyhp rename to maloja/web/pyhp/track.pyhp