diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index 6d6c39d..8a94f72 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -5,7 +5,7 @@ author = { "email":"maloja@krateng.dev", "github": "krateng" } -version = 2,7,3 +version = 2,7,4 versionstr = ".".join(str(n) for n in version) links = { "pypi":"malojaserver", diff --git a/maloja/server.py b/maloja/server.py index 6e8684d..abc5f14 100755 --- a/maloja/server.py +++ b/maloja/server.py @@ -24,7 +24,6 @@ from . import globalconf from doreah import settings from doreah.logging import log from doreah.timing import Clock -from doreah.pyhp import file as pyhpfile from doreah import auth # technical #from importlib.machinery import SourceFileLoader @@ -241,11 +240,8 @@ def static_html(name): linkheaders = ["; rel=preload; as=style"] keys = remove_identical(FormsDict.decode(request.query)) - - 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 auth.check(request) @@ -254,7 +250,7 @@ def static_html(name): 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): + 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, @@ -268,32 +264,6 @@ def static_html(name): log("Generated page {name} in {time:.5f}s (Jinja)".format(name=name,time=clock.stop()),module="debug") return res - # if a pyhp file exists, use this - elif (pyhp_file and pyhp_pref) or (pyhp_file and not html_file): - - #things we expose to the pyhp pages - environ = { - "adminmode":adminmode, - "apikey":request.cookies.get("apikey") if adminmode else None, - # maloja - "db": database, - "htmlmodules": htmlmodules, - "htmlgenerators": htmlgenerators, - "malojatime": malojatime, - "utilities": utilities, - "urihandler": urihandler, - "settings": settings.get_settings, - # external - "urllib": urllib - } - # request - environ["filterkeys"], environ["limitkeys"], environ["delimitkeys"], environ["amountkeys"] = uri_to_internal(keys) - environ["_urikeys"] = keys #temporary! - - #response.set_header("Content-Type","application/xhtml+xml") - res = pyhpfile(pthjoin(WEBFOLDER,"pyhp",name + ".pyhp"),environ) - log("Generated page {name} in {time:.5f}s (PYHP)".format(name=name,time=clock.stop()),module="debug") - return res # if not, use the old way else: diff --git a/maloja/urihandler.py b/maloja/urihandler.py index 9a569c1..440b854 100644 --- a/maloja/urihandler.py +++ b/maloja/urihandler.py @@ -113,6 +113,12 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False): return resultkeys1, resultkeys2, resultkeys3, resultkeys4 +def compose_from_dicts(*dicts): + return compose_querystring(internal_to_uri_p(*dicts)) + +def internal_to_uri_p(*dicts): + return internal_to_uri({k:d[k] for d in dicts for k in d}) + def internal_to_uri(keys): urikeys = FormsDict() diff --git a/maloja/web/artist.html b/maloja/web/artist.html deleted file mode 100644 index 8a48636..0000000 --- a/maloja/web/artist.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - Maloja - KEY_ARTISTNAME - - - - - - - - - - -
-
-
-

KEY_ARTISTNAME

- KEY_POSITION -
- KEY_ASSOCIATED -

KEY_SCROBBLES Scrobbles

- -

KEY_DESCRIPTION

- KEY_MEDALS KEY_TOPWEEKS KEY_CERTS -
- -

Top Tracks

- KEY_TRACKLIST - - - - - - -
-

Pulse

- - - 7 days - | 12 weeks - | 12 months - | 10 years - -

- - KEY_PULSE_MONTHS - - - -
- -

Performance

- 7 days - | 12 weeks - | 12 months - | 10 years - -

- - KEY_PERFORMANCE_MONTHS - - - -
- - -

Last Scrobbles

- KEY_SCROBBLELIST - - - diff --git a/maloja/web/artist.py b/maloja/web/artist.py deleted file mode 100644 index f75c884..0000000 --- a/maloja/web/artist.py +++ /dev/null @@ -1,110 +0,0 @@ -import urllib -from .. import database -from ..malojatime import today,thisweek,thismonth,thisyear - - -def instructions(keys): - from ..utilities import getArtistImage - from ..htmlgenerators import artistLink, artistLinks, link_address - from ..urihandler import compose_querystring, uri_to_internal - from ..htmlmodules import module_pulse, module_performance, module_trackcharts, module_scrobblelist - - filterkeys, _, _, _ = uri_to_internal(keys,forceArtist=True) - artist = filterkeys.get("artist") - imgurl = getArtistImage(filterkeys["artist"],fast=True) - pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - - data = database.artistInfo(filterkeys["artist"]) - scrobbles = str(data["scrobbles"]) - pos = "#" + str(data["position"]) - - html_medals = "" - if "medals" in data and data["medals"] is not None: - if "gold" in data["medals"]: - for y in data["medals"]["gold"]: - html_medals += "" + str(y) + "" - if "silver" in data["medals"]: - for y in data["medals"]["silver"]: - html_medals += "" + str(y) + "" - if "bronze" in data["medals"]: - for y in data["medals"]["bronze"]: - html_medals += "" + str(y) + "" - - html_cert = "" - for track in database.get_tracks(artist=artist): - info = database.trackInfo(track) - if info.get("certification") is not None: - img = "/media/record_{cert}.png".format(cert=info["certification"]) - trackname = track["title"].replace("'","'") - tracklink = link_address(track) - tooltip = "{title} has reached {cert} status".format(title=trackname,cert=info["certification"].capitalize()) - html_cert += "".format(tooltip=tooltip,img=img,link=tracklink) - - - html_topweeks = "" - if data.get("topweeks") not in [0,None]: - link = "/performance?artist=" + urllib.parse.quote(keys["artist"]) + "&trail=1&step=week" - title = str(data["topweeks"]) + " weeks on #1" - html_topweeks = "" + str(data["topweeks"]) + "" - - - credited = data.get("replace") - includestr = " " - if credited is not None: - includestr = "Competing under " + artistLink(credited) + " (" + pos + ")" - pos = "" - else: - credited = artist - included = data.get("associated") - if included is not None and included != []: - includestr = "associated: " - includestr += artistLinks(included) - - - html_tracks, _ = module_trackcharts(**filterkeys,max_=15) - - html_scrobbles, _, _ = module_scrobblelist(artist=artist,max_=10,earlystop=True) - - # pulse and rankings - html_pulse_days = module_pulse(**filterkeys,max_=7,since=today().next(-6),step="day",trail=1) - html_pulse_weeks = module_pulse(**filterkeys,max_=12,since=thisweek().next(-11),step="week",trail=1) - html_pulse_months = module_pulse(**filterkeys,max_=12,since=thismonth().next(-11),step="month",trail=1) - html_pulse_years = module_pulse(**filterkeys,max_=10,since=thisyear().next(-9),step="year",trail=1) - - html_performance_days = module_performance(artist=credited,max_=7,since=today().next(-6),step="day",trail=1) - html_performance_weeks = module_performance(artist=credited,max_=12,since=thisweek().next(-11),step="week",trail=1) - html_performance_months = module_performance(artist=credited,max_=12,since=thismonth().next(-11),step="month",trail=1) - html_performance_years = module_performance(artist=credited,max_=10,since=thisyear().next(-9),step="year",trail=1) - - replace = { - # info - "KEY_ARTISTNAME":keys["artist"], - "KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]), - "KEY_ENC_CREDITEDARTISTNAME":urllib.parse.quote(credited), - "KEY_IMAGEURL":imgurl, - "KEY_DESCRIPTION":"", - "KEY_SCROBBLES":scrobbles, - "KEY_POSITION":pos, - "KEY_ASSOCIATED":includestr, - "KEY_MEDALS":html_medals, - "KEY_CERTS":html_cert, - "KEY_TOPWEEKS":html_topweeks, - # tracks - "KEY_TRACKLIST":html_tracks, - # pulse - "KEY_PULSE_MONTHS":html_pulse_months, - "KEY_PULSE_YEARS":html_pulse_years, - "KEY_PULSE_DAYS":html_pulse_days, - "KEY_PULSE_WEEKS":html_pulse_weeks, - # performance - "KEY_PERFORMANCE_MONTHS":html_performance_months, - "KEY_PERFORMANCE_YEARS":html_performance_years, - "KEY_PERFORMANCE_DAYS":html_performance_days, - "KEY_PERFORMANCE_WEEKS":html_performance_weeks, - # scrobbles - "KEY_SCROBBLELIST":html_scrobbles, - "KEY_SCROBBLELINK":compose_querystring(keys), - - } - - return (replace,pushresources) diff --git a/maloja/web/charts_artists.html b/maloja/web/charts_artists.html deleted file mode 100644 index e203049..0000000 --- a/maloja/web/charts_artists.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - Maloja - Artist Charts - - - - - - - - - -
- KEY_TOPARTIST_IMAGEDIV - -

Artist Charts

View #1 Artists
- KEY_RANGE - -

- KEY_FILTERSELECTOR - -
- - - KEY_ARTISTCHART - - - KEY_ARTISTLIST - - - diff --git a/maloja/web/charts_artists.py b/maloja/web/charts_artists.py deleted file mode 100644 index 04cc582..0000000 --- a/maloja/web/charts_artists.py +++ /dev/null @@ -1,47 +0,0 @@ -import urllib - - -def instructions(keys): - from ..utilities import getArtistImage - from ..urihandler import compose_querystring, uri_to_internal - from ..htmlmodules import module_artistcharts, module_filterselection, module_artistcharts_tiles - from ..malojatime import range_desc - from doreah.settings import get_settings - - - _, timekeys, _, amountkeys = uri_to_internal(keys) - - limitstring = timekeys["timerange"].desc(prefix=True) - - html_filterselector = module_filterselection(keys) - - - - - html_charts, rep = module_artistcharts(**amountkeys,**timekeys) - - if rep is not None: - imgurl = getArtistImage(rep) - else: - imgurl = "" - - html_tiles = "" - if get_settings("CHARTS_DISPLAY_TILES"): - html_tiles = module_artistcharts_tiles(timerange=timekeys["timerange"]) - imgurl = "favicon.png" - - imgdiv = '
' - - - pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - - - replace = { - "KEY_TOPARTIST_IMAGEDIV":imgdiv, - "KEY_ARTISTCHART":html_tiles, - "KEY_ARTISTLIST":html_charts, - "KEY_RANGE":limitstring, - "KEY_FILTERSELECTOR":html_filterselector - } - - return (replace,pushresources) diff --git a/maloja/web/charts_tracks.html b/maloja/web/charts_tracks.html deleted file mode 100644 index 769a599..0000000 --- a/maloja/web/charts_tracks.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - Maloja - Track Charts - - - - - - - - -
- KEY_TOPARTIST_IMAGEDIV - -

Track Charts

TOP_TRACKS_LINK
- KEY_LIMITS - -

- KEY_FILTERSELECTOR -
- - - KEY_TRACKCHART - - - KEY_TRACKLIST - - - diff --git a/maloja/web/charts_tracks.py b/maloja/web/charts_tracks.py deleted file mode 100644 index 0bfe9a4..0000000 --- a/maloja/web/charts_tracks.py +++ /dev/null @@ -1,62 +0,0 @@ -import urllib - - -def instructions(keys): - from ..utilities import getArtistImage, getTrackImage - from ..htmlgenerators import artistLink - from ..urihandler import compose_querystring, uri_to_internal - from ..htmlmodules import module_trackcharts, module_filterselection, module_trackcharts_tiles - from ..malojatime import range_desc - from doreah.settings import get_settings - - filterkeys, timekeys, _, amountkeys = uri_to_internal(keys) - - if len(filterkeys) == 0: - toptrackslink = "View #1 Tracks" - else: - toptrackslink = "" - - - limitstring = "" - - html_filterselector = module_filterselection(keys) - - html_charts, rep = module_trackcharts(**amountkeys,**timekeys,**filterkeys) - - - - html_tiles = "" - - if filterkeys.get("artist") is not None: - imgurl = getArtistImage(filterkeys.get("artist")) - limitstring = "by " + artistLink(filterkeys.get("artist")) - elif rep is not None: - imgurl = getTrackImage(rep["artists"],rep["title"]) - else: - imgurl = "" - - html_tiles = "" - if get_settings("CHARTS_DISPLAY_TILES"): - html_tiles = module_trackcharts_tiles(timerange=timekeys["timerange"]) - imgurl = "favicon.png" - - imgdiv = '
' - - - - limitstring += " " + timekeys["timerange"].desc(prefix=True) - - pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - - - - replace = { - "KEY_TOPARTIST_IMAGEDIV":imgdiv, - "KEY_TRACKCHART":html_tiles, - "KEY_TRACKLIST":html_charts, - "KEY_LIMITS":limitstring, - "KEY_FILTERSELECTOR":html_filterselector, - "TOP_TRACKS_LINK":toptrackslink, - } - - return (replace,pushresources) diff --git a/maloja/web/jinja/charts_artists.jinja b/maloja/web/jinja/charts_artists.jinja index a03e078..bb14dff 100644 --- a/maloja/web/jinja/charts_artists.jinja +++ b/maloja/web/jinja/charts_artists.jinja @@ -6,6 +6,7 @@ {% endblock %} {% set charts = dbp.get_charts_artists(filterkeys,limitkeys) %} +{% set pages = math.ceil(charts.__len__() / amountkeys.perpage) %} {% if charts[0] is defined %} {% set topartist = charts[0].artist %} {% set img = utilities.getArtistImage(artist=topartist,fast=True) %} @@ -37,5 +38,8 @@ {{ charts_artists.charts_artists(limitkeys,amountkeys,compare=False) }} +{% import 'snippets/pagination.jinja' as pagination %} + +{{ pagination.pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages) }} {% endblock %} diff --git a/maloja/web/jinja/charts_tracks.jinja b/maloja/web/jinja/charts_tracks.jinja index 4d11d3a..e38752b 100644 --- a/maloja/web/jinja/charts_tracks.jinja +++ b/maloja/web/jinja/charts_tracks.jinja @@ -6,6 +6,7 @@ {% endblock %} {% set charts = dbp.get_charts_tracks(filterkeys,limitkeys) %} +{% set pages = math.ceil(charts.__len__() / amountkeys.perpage) %} {% if charts[0] is defined %} {% set toptrack = charts[0].track %} {% set img = utilities.getTrackImage(artists=toptrack.artists,title=toptrack.title,fast=True) %} @@ -37,5 +38,8 @@ {{ charts_tracks.charts_tracks(filterkeys,limitkeys,amountkeys,charts=charts,compare=false) }} +{% import 'snippets/pagination.jinja' as pagination %} + +{{ pagination.pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages) }} {% endblock %} diff --git a/maloja/web/jinja/snippets/pagination.jinja b/maloja/web/jinja/snippets/pagination.jinja new file mode 100644 index 0000000..36e8d10 --- /dev/null +++ b/maloja/web/jinja/snippets/pagination.jinja @@ -0,0 +1,50 @@ +{% macro pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages=1) %} + +{% set page = amountkeys.page %} + + + + +
+ + {% if pages > 1 %} + {% if page > 1 %} + + 1 + | + {% endif %} + + {% if page > 2 %} + ... | + {% endif %} + + {% if page > 0 %} + + {{ page }} + « + {% endif %} + + + {{ page + 1 }} + + + {% if page < pages-1 %} + » + {{ page+2 }} + + {% endif %} + + {% if page < pages-3 %} + | ... + {% endif %} + + {% if page < pages-2 %} + | + {{ pages }} + + {% endif %} + {% endif %} + +
+ +{% endmacro %} diff --git a/maloja/web/jinja/wait.jinja b/maloja/web/jinja/wait.jinja new file mode 100644 index 0000000..19dff3e --- /dev/null +++ b/maloja/web/jinja/wait.jinja @@ -0,0 +1,41 @@ +{% extends "abstracts/base.jinja" %} +{% block title %}Maloja - Please wait...{% endblock %} + +{% block heading %}Redbuilding the database{% endblock %} + +{% block top_info %} + Please wait... +{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/maloja/web/pyhp/charts_artists.pyhp b/maloja/web/pyhp/charts_artists.pyhp deleted file mode 100644 index a2962c3..0000000 --- a/maloja/web/pyhp/charts_artists.pyhp +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - Maloja - Artist Charts - - - - - - - try: - top = db.get_charts_artists(**filterkeys,**limitkeys)[0]["artist"] - img = utilities.getArtistImage(top) - except: - img = "" - - - - - - - - -
-
-
-

Artist Charts

View #1 Artists
- -

- - -
- - - - - - - - - - - - - - diff --git a/maloja/web/pyhp/charts_tracks.pyhp b/maloja/web/pyhp/charts_tracks.pyhp deleted file mode 100644 index 9850375..0000000 --- a/maloja/web/pyhp/charts_tracks.pyhp +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - Maloja - Track Charts - - - - - - - try: - try: - img = utilities.getArtistImage(filterkeys['artist']) - except: - top = db.get_charts_tracks(**filterkeys,**limitkeys)[0]["track"] - img = utilities.getTrackImage(**top) - except: - img = "" - - - - - - - - -
-
-
-

Track Charts

View #1 Tracks
- - by - - -

- - -
- - - - - - - - - - - - - - diff --git a/maloja/web/track.html b/maloja/web/track.html deleted file mode 100644 index 1fdd265..0000000 --- a/maloja/web/track.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - Maloja - KEY_TRACKTITLE - - - - - - - - - - -
-
-
- KEY_ARTISTS
-

KEY_TRACKTITLE

KEY_CERTS KEY_POSITION - -

KEY_SCROBBLES Scrobbles

- -

- KEY_MEDALS KEY_TOPWEEKS -
- - - - - - - -
-

Pulse

- 7 days - | 12 weeks - | 12 months - | 10 years - -

- - KEY_PULSE_MONTHS - - - -
-

Performance

- 7 days - | 12 weeks - | 12 months - | 10 years - -

- - KEY_PERFORMANCE_MONTHS - - - -
- - -

Last Scrobbles

- KEY_SCROBBLELIST - - - - - diff --git a/maloja/web/track.py b/maloja/web/track.py deleted file mode 100644 index 0110576..0000000 --- a/maloja/web/track.py +++ /dev/null @@ -1,88 +0,0 @@ -import urllib -from .. import database -from ..malojatime import today,thisweek,thismonth,thisyear - - -def instructions(keys): - from ..utilities import getArtistImage, getTrackImage - from ..htmlgenerators import artistLinks - from ..urihandler import compose_querystring, uri_to_internal - from ..htmlmodules import module_scrobblelist, module_pulse, module_performance - - - filterkeys, _, _, _ = uri_to_internal(keys,forceTrack=True) - - track = filterkeys.get("track") - imgurl = getTrackImage(track["artists"],track["title"],fast=True) - pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - - data = database.trackInfo(track) - - scrobblesnum = str(data["scrobbles"]) - pos = "#" + str(data["position"]) - - html_cert = "" - if data["certification"] is not None: - html_cert = "".format(cert=data["certification"],certc=data["certification"].capitalize()) - - html_medals = "" - if "medals" in data and data["medals"] is not None: - if "gold" in data["medals"]: - for y in data["medals"]["gold"]: - html_medals += "" + str(y) + "" - if "silver" in data["medals"]: - for y in data["medals"]["silver"]: - html_medals += "" + str(y) + "" - if "bronze" in data["medals"]: - for y in data["medals"]["bronze"]: - html_medals += "" + str(y) + "" - - html_topweeks = "" - if data.get("topweeks") not in [0,None]: - link = "/performance?" + compose_querystring(keys) + "&trail=1&step=week" - title = str(data["topweeks"]) + " weeks on #1" - html_topweeks = "" + str(data["topweeks"]) + "" - - - - html_scrobbles, _, _ = module_scrobblelist(track=track,max_=10,earlystop=True) # we have the number already from the trackinfo - - html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1) - html_performance = module_performance(track=track,step="year",stepn=1,trail=1) - - # pulse and rankings - html_pulse_days = module_pulse(track=track,max_=7,since=today().next(-6),step="day",trail=1) - html_pulse_weeks = module_pulse(track=track,max_=12,since=thisweek().next(-11),step="week",trail=1) - html_pulse_months = module_pulse(track=track,max_=12,since=thismonth().next(-11),step="month",trail=1) - html_pulse_years = module_pulse(track=track,max_=10,since=thisyear().next(-9),step="year",trail=1) - - html_performance_days = module_performance(track=track,max_=7,since=today().next(-6),step="day",trail=1) - html_performance_weeks = module_performance(track=track,max_=12,since=thisweek().next(-11),step="week",trail=1) - html_performance_months = module_performance(track=track,max_=12,since=thismonth().next(-11),step="month",trail=1) - html_performance_years = module_performance(track=track,max_=10,since=thisyear().next(-9),step="year",trail=1) - - - replace = { - "KEY_TRACKTITLE":track.get("title"), - "KEY_ARTISTS":artistLinks(track.get("artists")), - "KEY_SCROBBLES":scrobblesnum, - "KEY_POSITION":pos, - "KEY_IMAGEURL":imgurl, - "KEY_SCROBBLELINK":compose_querystring(keys), - "KEY_MEDALS":html_medals, - "KEY_CERTS":html_cert, - "KEY_TOPWEEKS":html_topweeks, - "KEY_SCROBBLELIST":html_scrobbles, - # pulse - "KEY_PULSE_MONTHS":html_pulse_months, - "KEY_PULSE_YEARS":html_pulse_years, - "KEY_PULSE_DAYS":html_pulse_days, - "KEY_PULSE_WEEKS":html_pulse_weeks, - # performance - "KEY_PERFORMANCE_MONTHS":html_performance_months, - "KEY_PERFORMANCE_YEARS":html_performance_years, - "KEY_PERFORMANCE_DAYS":html_performance_days, - "KEY_PERFORMANCE_WEEKS":html_performance_weeks, - } - - return (replace,pushresources) diff --git a/maloja/web/wait.html b/maloja/web/wait.html deleted file mode 100644 index 3367376..0000000 --- a/maloja/web/wait.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - Maloja - Please wait - - - - - - - - -
-

Maloja


- Redbuilding the database - -

Please wait...

-
- - - - - -