Mercurial > hg > ltpdarepo
changeset 104:dcb2f0a97147
Split activity view into its own blueprint. Do not wire it up yet.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Tue, 23 Aug 2011 14:34:07 +0200 |
parents | 1c18434e5e69 |
children | f4cbab388ed0 |
files | src/ltpdarepo/templates/database.html src/ltpdarepo/tests/browse-database.txt src/ltpdarepo/views/activity.py src/ltpdarepo/views/browse.py |
diffstat | 4 files changed, 48 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/templates/database.html Sun Aug 21 20:34:22 2011 +0200 +++ b/src/ltpdarepo/templates/database.html Tue Aug 23 14:34:07 2011 +0200 @@ -5,7 +5,7 @@ <p class="discrete">{{ database.description }}</p> <ul class="actions"> <li><a href="{{ url_for('browse.browse', database=database.id) }}">Browse</a></li> - <li><a href="{{ url_for('browse.activity', database=database.id) }}">Show activity</a></li> + {# <li><a href="{{ url_for('browse.activity', database=database.id) }}">Show activity</a></li> #} <li><a href="{{ url_for('browse.query', database=database.id) }}">Advanced search</a></li> <li><a href="{{ url_for('browse.timeseries', database=database.id) }}">Timeseries search</a></li> </ul>
--- a/src/ltpdarepo/tests/browse-database.txt Sun Aug 21 20:34:22 2011 +0200 +++ b/src/ltpdarepo/tests/browse-database.txt Tue Aug 23 14:34:07 2011 +0200 @@ -60,10 +60,10 @@ Activity view:: - >>> browser.open('/browse/db1') - >>> browser.getLink('Show activity').click() - >>> browser.url - 'http://localhost/browse/db1/activity' + # >>> browser.open('/browse/db1') + # >>> browser.getLink('Show activity').click() + # >>> browser.url + # 'http://localhost/browse/db1/activity' # Local Variables:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/views/activity.py Tue Aug 23 14:34:07 2011 +0200 @@ -0,0 +1,43 @@ +import datetime + +from flask import Blueprint, g, abort, render_template + +from ltpdarepo.database import Database +from ltpdarepo.security import require, view + +app = Blueprint('activity', __name__) + + +@app.route('/<database>/activity') +@app.route('/<database>/activity/<period>/<date>') +@require('user') +def activity(database, period='week', date=None): + with view('database', database): + db = Database().load(database) + if db is None: + # not found + abort(404) + + curs = g.db.cursor() + + if date is None: + today = datetime.date.today() + else: + today = datetime.datetime.strptime(date, '%Y-%m-%d').date() + + activity = [] + + for i in range(0, 7): + start = today - datetime.timedelta(days=1 * i) + stop = today - datetime.timedelta(days=1 * (i - 1)) + curs.execute("""SELECT COUNT(*) AS n + FROM `%s`.objmeta + WHERE submitted > %%s + AND submitted < %%s""" % database, (start, stop)) + n = curs.fetchone()[0] + activity.append((str(start), n)) + + return render_template('activity.html', database=db, activity=activity) + + +module = app
--- a/src/ltpdarepo/views/browse.py Sun Aug 21 20:34:22 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Tue Aug 23 14:34:07 2011 +0200 @@ -1,6 +1,4 @@ import re -import sys -import datetime from operator import itemgetter from flask import Blueprint, abort, g, request, render_template, json, make_response @@ -172,38 +170,6 @@ return render_template('browse.html', objs=objs, fields=FIELDS, database=db, batch=batch) -@app.route('/<database>/activity') -@app.route('/<database>/activity/<period>/<date>') -@require('user') -def activity(database, period='week', date=None): - with view('database', database): - db = Database().load(database) - if db is None: - # not found - abort(404) - - curs = g.db.cursor() - - if date is None: - today = datetime.date.today() - else: - today = datetime.datetime.strptime(date, '%Y-%m-%d').date() - - activity = [] - - for i in range(0, 7): - start = today - datetime.timedelta(days=1 * i) - stop = today - datetime.timedelta(days=1 * (i - 1)) - curs.execute("""SELECT COUNT(*) AS n - FROM `%s`.objmeta - WHERE submitted > %%s - AND submitted < %%s""" % database, (start, stop)) - n = curs.fetchone()[0] - activity.append((str(start), n)) - - return render_template('activity.html', database=db, activity=activity) - - @app.route('/<database>/<int:objid>') @require('user') def obj(database, objid):