view web/scoring/high.cgi @ 74:900da50ee11c

Merge lighttpd configuration into one include file. The lighttpd configuration was previously spread across several files which were intended to overwrite the defaults. They often became outdated. Now all customization is in lighttpd/rlgallery.conf, which should be included at the end of whatever main lighttpd configuration file is in use. It should require minimal updates for new lighttpd versions or distribution changes.
author John "Elwin" Edwards
date Wed, 28 Dec 2016 13:12:04 -0500
parents 1d8dc3ed22cf
children
line wrap: on
line source

#!/usr/bin/python3

import sys
import cgi
import rlgall

checkstr = '{0}:<input type="checkbox" name="g" value="{1}" checked="checked"> '
uncheckstr = '{0}:<input type="checkbox" name="g" value="{1}"> '

cgidata = cgi.FieldStorage()

formgames = cgidata.getlist("g")
if "all" in formgames:
  games = rlgall.gamelist
else:
  games = []
  for g in rlgall.gamelist:
    if g.uname in formgames:
      games.append(g)
  if not games:
    games = rlgall.gamelist

formstart = cgidata.getfirst("s")
if not formstart:
  start = 0
else:
  try:
    start = int(formstart)
  except ValueError:
    start = 0
if start < 0:
  start = 0

deflimit = 10
formlimit = cgidata.getfirst("l")
if not formlimit:
  limit = deflimit
else:
  try:
    limit = int(formlimit)
  except ValueError:
    limit = deflimit
if limit <= 0:
  limit = deflimit


sys.stdout.write("Content-Type: text/html; charset=utf-8\r\n\r\n")
sys.stdout.write(rlgall.phead.format("High Scores"))
sys.stdout.write(rlgall.ptop)
sys.stdout.write(rlgall.navscore.format("High Scores"))
if len(games) == 1:
  if start == 0:
    intitle = "Top {0} scores for {1}".format(limit, games[0].name)
  else:
    intitle = "Scores {0} - {1} for {2}".format(start + 1, start + limit, 
                games[0].name)
  sys.stdout.write(rlgall.pti.format(intitle))
  highlist = games[0].getHigh(limit, start)
  rlgall.printTable(highlist, games[0].rankfields, sys.stdout)
else:
  if start == 0:
    intitle = "Top {0} scores".format(limit)
  else:
    intitle = "Scores {0} - {1}".format(start + 1, start + limit)
  sys.stdout.write(rlgall.pti.format(intitle))
  for g in games:
    sys.stdout.write(rlgall.secthead.format(g.name))
    highlist = g.getHigh(limit, start)
    rlgall.printTable(highlist, g.rankfields, sys.stdout)
sys.stdout.write('<form action="/scoring/high.cgi" method="get">\n')
sys.stdout.write('<div>Number of scores: ')
sys.stdout.write('<input type="text" name="l" value="{0}">'.format(limit))
sys.stdout.write(' Skip the first: ')
sys.stdout.write('<input type="text" name="s" value="{0}">'.format(start))
sys.stdout.write('</div><div>')
for game in rlgall.gamelist:
  if game in games:
    sys.stdout.write(checkstr.format(game.name, game.uname))
  else:
    sys.stdout.write(uncheckstr.format(game.name, game.uname))
sys.stdout.write('</div><div><input type="submit" value="Get Scores">')
sys.stdout.write('</div></form>')
sys.stdout.write(rlgall.pend)
exit()