Display what points your team has already made

This commit is contained in:
Neale Pickett 2009-10-07 15:16:15 -06:00
parent ca86e03fd3
commit 742d1a0c35
4 changed files with 49 additions and 31 deletions

View File

@ -77,3 +77,7 @@ p {
margin-bottom: 20px;
color: #f4f4f4;
}
.solved {
text-decoration: line-through;
}

View File

@ -66,3 +66,23 @@ def datafile(filename):
def url(path):
return base_url + path
def start_html(title):
if os.environ.get('GATEWAY_INTERFACE'):
print('Content-type: text/html')
print()
print('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s</title>
<link rel="stylesheet" href="%s" type="text/css" />
</head>
<body>
<h1>%s</h1>
''' % (title, css, title))
def end_html():
print('</body></html>')

View File

@ -27,7 +27,7 @@ cat_re = re.compile(r'^[a-z]+$')
points_re = re.compile(r'^[0-9]+$')
def dbg(*vals):
print('<--: \nContent-type: text/html\n\n--><pre>')
print('<!--: \nContent-type: text/html\n\n--><pre>')
print(*vals)
print('</pre>')
@ -59,32 +59,16 @@ passwd = f.getfirst('w', passwd)
key = f.getfirst('k')
def start_html(title):
if os.environ.get('GATEWAY_INTERFACE'):
print('Content-type: text/html')
if team or passwd:
c = http.cookies.SimpleCookie()
if team:
c['team'] = team
if passwd:
c['passwd'] = passwd
print(c)
print()
print('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s</title>
<link rel="stylesheet" href="%s" type="text/css" />
</head>
<body>
<h1>%s</h1>
''' % (title, config.css, title))
def end_html():
print('</body></html>')
if team or passwd:
c = http.cookies.SimpleCookie()
if team:
c['team'] = team
if passwd:
c['passwd'] = passwd
print(c)
config.start_html(title)
end_html = config.end_html
def safe_join(*args):
safe = list(args[:1])
@ -125,7 +109,17 @@ def show_puzzles(cat, cat_dir):
if puzzles:
print('<ul>')
for p in puzzles:
print('<li><a href="%s/%s/%d">%d</a></li>' % (base_url, cat, p, p))
cls = ''
try:
if p in points_by_team[(team, cat)]:
cls = 'solved'
except KeyError:
pass
print('<li><a href="%(base)s/%(cat)s/%(points)d" class="%(class)s">%(points)d</a></li>' %
{'base': base_url,
'cat': cat,
'points': p,
'class': cls})
if p > opened:
break
print('</ul>')

View File

@ -33,7 +33,7 @@ def main():
pw = f.getfirst('pw')
confirm_pw = f.getfirst('confirm_pw')
html = string.Template(head('Team Registration') +
html = string.Template(config.start_html('Team Registration') +
('''
<p>
Pick a short team name: you'll be typing it a lot.
@ -58,7 +58,7 @@ def main():
<input type="submit" value="Register" />
</fieldset>
</form>''' % config.url('register.cgi')) +
foot())
config.end_html())
if not (team and pw and confirm_pw): # If we're starting from the beginning?
html = html.substitute(team_error='',
@ -71,9 +71,9 @@ def main():
pw_match_error='Passwords do not match')
else:
teams.add(team, pw)
html = (head('Team registered') +
html = (config.start_html('Team registered') +
('<p>Congratulations, <samp>%s</samp> is now registered. Go <a href="%s">back to the front page</a> and start playing!</p>' % (team, config.url(''))) +
foot())
config.end_html())
print(html)