# HG changeset patch # User Daniele Nicolodi # Date 1314102847 -7200 # Node ID dcb2f0a97147c764f121e4fc6b980baf95ba4fe7 # Parent 1c18434e5e69a6fcf3d03a92b001942985ada135 Split activity view into its own blueprint. Do not wire it up yet. diff -r 1c18434e5e69 -r dcb2f0a97147 src/ltpdarepo/templates/database.html --- 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 @@

{{ database.description }}

diff -r 1c18434e5e69 -r dcb2f0a97147 src/ltpdarepo/tests/browse-database.txt --- 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: diff -r 1c18434e5e69 -r dcb2f0a97147 src/ltpdarepo/views/activity.py --- /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('//activity') +@app.route('//activity//') +@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 diff -r 1c18434e5e69 -r dcb2f0a97147 src/ltpdarepo/views/browse.py --- 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('//activity') -@app.route('//activity//') -@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('//') @require('user') def obj(database, objid):