Cleanups.

This commit is contained in:
Timothy Allen 2018-08-14 11:02:56 +02:00
parent 6c1e9d82a0
commit 53abd4e151
6 changed files with 31 additions and 25 deletions

View File

@ -144,7 +144,7 @@ def read_db(listing=None, event=None, person=None, licence=None, search=dict(),
pass
if listing:
if listing == 'race':
if listing == 'races':
select = 'event, date'
group = 'GROUP BY event'
elif listing == 'runners':
@ -171,19 +171,20 @@ def read_db(listing=None, event=None, person=None, licence=None, search=dict(),
select = 'COUNT(*)'
close = ''
if listing:
if listing == 'race':
if listing == 'races':
select = 'COUNT(*) FROM ( SELECT COUNT(event)'
close = ') race'
close = ') AS races'
elif listing == 'runners':
select = 'COUNT(*) FROM ( SELECT COUNT(name)'
group = 'GROUP BY CONCAT_WS(" ", name, surname)'
close = ') runners'
close = ') AS runners'
elif listing == 'rankings':
select = 'COUNT(*) FROM ( SELECT COUNT(name)'
group = 'GROUP BY CONCAT_WS(" ", name, surname)'
close = ') rankings'
close = ') AS rankings'
elif listing == 'licence':
pass
select = 'COUNT(*) FROM ( SELECT COUNT(licence)'
close = ') AS licence'
sql = 'SELECT {} FROM `results` {} {} {};'.format(select, where, group, close)
app.logger.debug(sql)
@ -206,7 +207,7 @@ def list(title=None, year=None):
year = now().year
title = 'runners'
title = urllib.parse.unquote_plus(title)
if title not in ( 'race', 'rankings', 'runners', 'licence', ):
if title not in ( 'races', 'rankings', 'runners', 'licence', ):
abort(404)
''' In early January, we'll be left with blank pages in listings, since there won't
@ -227,21 +228,20 @@ def list(title=None, year=None):
@app.route('/all')
@app.route('/all/<int:year>')
@app.route('/all/<int:year>/<title>') # this does nothing, and is simply here to prevent title from being added to the query string
def index(title=None, year=None):
if title is not None:
title = urllib.parse.unquote_plus(title)
results = read_db(year=year)
return render_template('index.html', ltype='index',
results=results, year=year,
return render_template('index.html', ltype='index', title=title,
results=results, year=year,
request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/race/<int:year>/<title>')
def race(year=None, title=None):
@app.route('/races/<int:year>/<title>')
def races(year=None, title=None):
if title is not None:
title = urllib.parse.unquote_plus(title)
results = read_db(event=title, year=year)
return render_template('index.html', ltype='race', title=title,
return render_template('index.html', ltype='races', title=title,
results=results, year=year,
request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@ -267,7 +267,7 @@ def licence(year=now().year, title=None):
@app.route('/search')
def search():
results = read_db(search=request.args)
return render_template('index.html', ltype='search', title='Search',
return render_template('index.html', ltype='search', title=None,
results=results, year=None,
request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)

View File

@ -2,11 +2,13 @@
{% include 'head.html' with context %}
<article>
<h1>AAC Results{% if title %}: {% if ltype == 'licence' %}Licence {% endif %}{{ title }}{% endif %}{% if year %} ({{ year }}){% endif %}</h1>
{% if ltype == 'search' -%}
<h1>AAC Results: Search</h1>
{% include 'search.html' with context %}
{% else %}
<h1>AAC Results{% if title %}: {% if ltype == 'licence' %}Licence {% endif %}{{ title }}{% endif %}{% if year %} ({{ year }}){% endif %}</h1>
{%- endif -%}
{% if results -%}
{%- set ns.total = 0 -%}
{%- if 'count' in results -%}
@ -37,7 +39,7 @@
<td><span class="label">Time</span> <span>{{ row.time|e }}</span></td>
<td class="nowrap"><span class="label">Average Pace</span> <span>{% if row.distance is number and row.distance|int != 0 %}{{ (row.time / row.distance) | pace }} min/KM{% endif %}</span></td>
{%- if ltype != 'event' -%}
<td class="long"><span class="label">Race</span> <span><a href="{{ url_for('race', title=row.event|trim|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.event|trim|e }} ({{ row.distance|trim|e }} KM)</a></span></td>
<td class="long"><span class="label">Race</span> <span><a href="{{ url_for('races', title=row.event|trim|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.event|trim|e }} ({{ row.distance|trim|e }} KM)</a></span></td>
{%- endif -%}
<td class="nowrap"><span class="label">Date</span> <span>{{ row.date|cleandate|e }}</span></td>
<td class="long"><span class="label">Notes</span> <span>

View File

@ -20,7 +20,7 @@
{%- for row in results['rows'] -%}
<tr>
<td><span class="label">Licence</span> <span><a href="{{ url_for('licence', title=row.licence|trim|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.licence|trim|e }}</a></span></td>
<td><span class="label">Name</span> <span><a href="{{ url_for('person', title=row.person|trim|urlescape, year=year, start=None, show=ns.show) }}">{{ row.person|trim|e }}</a></span></td>
<td><span class="label">Name</span> <span><a href="{{ url_for('person', title=row.person|trim|urlescape, year=None, start=None, show=ns.show) }}">{{ row.person|trim|e }}</a></span></td>
<td><span class="label">Year</span> <span>{{ row.date | year }}</a></span></td>
</tr>
{%- endfor -%}

View File

@ -2,24 +2,24 @@
{% include 'head.html' with context %}
<article>
<h1>AAC Statistics: {% if year %} {{ year }}{% endif %}{% if title %} {{ title | title }}{% endif %}</h1>
<h1>AAC Results: Races {% if year %} in {{ year }}{% endif %}</h1>
{% if results -%}
{%- set ns.total = 0 -%}
{%- if 'count' in results -%}
{%- set ns.total = results['count'] -%}
{%- endif -%}
<table>
<table class="narrow">
<thead>
<tr>
<th>Event</th>
<th>Race</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{%- for row in results['rows'] -%}
<tr>
<td><a href="{{ url_for('race', title=row.event, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.event }}</a></td>
<td>{{ row.date | cleandate }}</td>
<td><span class="label">Race</span> <span><a href="{{ url_for('races', title=row.event|trim|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.event|trim|e }}</a></span></td>
<td><span class="label">Date</span> <span>{{ row.date | cleandate }}</span></td>
</tr>
{%- endfor -%}
</tbody>

View File

@ -23,7 +23,11 @@
{% for page in range(1, totalpages+1) %}
{% if page < 4 or page > (totalpages+1-4) or (page > (thispage-3) and page < (thispage+3)) %}
{%- if page != thispage -%}
<span class="nav link"><a href="{{ url_for(request.endpoint, title=title, year=year, start=(page - 1) * getshow, show=ns.show, **ns.query) }}">{{ page }}</a></span>
{% set goto = (page - 1) * getshow %}
{%- if goto == 0 -%}
{%- set goto = None -%}
{%- endif -%}
<span class="nav link"><a href="{{ url_for(request.endpoint, title=title, year=year, start=goto, show=ns.show, **ns.query) }}">{{ page }}</a></span>
{%- else -%}
<span class="nav plain"><strong>{{ page }}</strong></span>
{%- endif %}

View File

@ -1,7 +1,7 @@
<nav class="tabs">
<span><a href="{{ url_for('list', title='runners', year=now|year, start=None, show=ns.show) }}">Runners</a></span>
<span><a href="{{ url_for('list', title='rankings', year=now|year, start=None, show=ns.show) }}">Rankings</a></span>
<span><a href="{{ url_for('list', title='race', year=now|year, start=None, show=ns.show) }}">Races</a></span>
<span><a href="{{ url_for('list', title='races', year=None, start=None, show=ns.show) }}">Races</a></span>
<span><a href="{{ url_for('list', title='licence', year=now|year, start=None, show=ns.show) }}">Licences</a></span>
<span><a href="{{ url_for('index', title=None, year=None, start=None, show=ns.show) }}">All Results</a></span>
<span><a href="{{ url_for('search', title=None, year=None, start=None, show=ns.show) }}">Search</a></span>