-
Notifications
You must be signed in to change notification settings - Fork 5
/
listlevels.py
executable file
·74 lines (62 loc) · 2.48 KB
/
listlevels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
from __future__ import division
# This script takes a username and spits out a list of links to all
# works drawn by that user.
import cgi
import cgitb
import math
from database_tables import Level, LevelObject, Score
from webserver_utils import render_template_file, verify_id
def formatTime(ms):
s = math.floor(ms / 1000)
ms = ms % 1000
m = math.floor(s / 60)
s = s % 60
return "%d:%2d.%2d" % (m, s, ms)
def printList(player):
print "Content-type: text/html"
print
matches = Level.select(orderBy = "-modified")
work_list = ""
for level in matches:
title = level.name
date = level.modified
edit_link = ""
if level.creator != None:
if level.creator == player:
creator = "You"
edit_link = "<a href=\"designer.html?level=%s\">Edit</a>" % title
else:
creator = level.creator.name
else:
creator = "Nobody"
scores = Score.selectBy(level = level)
best = ""
if (scores.count() > 0):
best = "%s by %s with %d trinkets" % (formatTime(scores[0].completionTime),
scores[0].player.name,
scores[0].trinkets)
else:
best = "Nobody Yet!"
scores = Score.selectBy(player = player, level = level)
your_time = ""
if (scores.count() > 0):
your_time = "%s with %d trinkets" % (formatTime(scores[0].completionTime),
scores[0].trinkets)
work_list += render_template_file( "list-level-row.html",
{"moddate": date,
"title": title,
"creator": creator,
"editlink": edit_link,
"best": best,
"yourtime": your_time} )
print render_template_file( "list-levels.html", {"work_list": work_list,
"player": player.name,
"avatarURL": player.avatarURL})
if __name__ == "__main__":
cgitb.enable()
q = cgi.FieldStorage()
player = verify_id()
# action = q.getfirst("action", "")
# title = q.getfirst("title", "")
printList(player)