Browse Source

Python 2-ized

marches
Graham Northup 3 years ago
parent
commit
20323c73b3
Signed by untrusted user: grissess GPG Key ID: 5D000E6F539376FB
  1. 16
      app/routes.py

16
app/routes.py

@ -76,22 +76,24 @@ def search():
def bucket_route(uri, dir, sing=None):
if sing is None:
sing = dir[:-1] # minus "s"
path = '../' + dir + '/*'
root = '/' + uri
def render_bucket():
return render_template('listing.html', title=dir, uri=uri, items=get_items(f'../{dir}/*'))
app.add_url_rule(f'/{uri}', f'render_{uri}', render_bucket)
return render_template('listing.html', title=dir, uri=uri, items=get_items(path))
app.add_url_rule(root, 'render_' + uri, render_bucket)
def random_bucket():
nm = choice(get_items(f'../{dir}/*'))[0]
return redirect(f'/{uri}#{nm}')
app.add_url_rule(f'/{uri}/random', f'random_{uri}', random_bucket)
nm = choice(get_items(path))[0]
return redirect(root + '#' + nm)
app.add_url_rule(root + '/random', 'random_' + uri, random_bucket)
def bucket_table(amt):
try:
return render_template('table.html', title=f'{sing} Table', items=sample(get_items(f'../{dir}/*'), amt), roll=amt)
return render_template('table.html', title=sing + ' Table', items=sample(get_items(path), amt), roll=amt)
except ValueError:
return render_template('table.html', title='you dun goofed', error="Can't construct that table (not enough items?)")
app.add_url_rule(f'/{uri}/table/<int:amt>', f'{uri}_table', bucket_table)
app.add_url_rule(root + '/table/<int:amt>', dir + '_table', bucket_table)
bucket_route('items', 'Items')
bucket_route('places', 'Places')

Loading…
Cancel
Save