Mercurial > hg > ltpdarepo
changeset 136:66b8360a41c9
Fold activity blueprint into browse blueprint.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Fri, 14 Oct 2011 22:02:58 +0200 |
parents | 57dbb265a02a |
children | e55537dfbe2b |
files | src/ltpdarepo/__init__.py src/ltpdarepo/templates/activity.html src/ltpdarepo/templates/database.html src/ltpdarepo/views/activity.py src/ltpdarepo/views/browse.py |
diffstat | 5 files changed, 41 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/__init__.py Fri Oct 14 22:02:41 2011 +0200 +++ b/src/ltpdarepo/__init__.py Fri Oct 14 22:02:58 2011 +0200 @@ -127,9 +127,6 @@ from .views.browse import module app.register_blueprint(module, url_prefix='/browse') -from .views.activity import module -app.register_blueprint(module, url_prefix='/browse') - from .views.profile import module app.register_blueprint(module, url_prefix='/user')
--- a/src/ltpdarepo/templates/activity.html Fri Oct 14 22:02:41 2011 +0200 +++ b/src/ltpdarepo/templates/activity.html Fri Oct 14 22:02:58 2011 +0200 @@ -6,9 +6,9 @@ <p class="discrete">Objects submitted per day in <em>{{ curr.strftime('%B %Y') }}</em></p> <div class="wrapper"> <div class="monthes wrapper"> - <a title="{{ prev.strftime('%B %Y') }}" href="{{ url_for('activity.activity', database=database.id, date=prev) }}">prev</a> - <a title="{{ next.strftime('%B %Y') }}" href="{{ url_for('activity.activity', database=database.id, date=next) }}">next</a> - <a href="{{ url_for('activity.activity', database=database.id) }}">today</a> + <a href="{{ url_for('browse.activity', database=database.id, date=prev) }}" title="{{ prev.strftime('%B %Y') }}">prev</a> + <a href="{{ url_for('browse.activity', database=database.id, date=next) }}" title="{{ next.strftime('%B %Y') }}">next</a> + <a href="{{ url_for('browse.activity', database=database.id) }}">today</a> </div> </div> <div class="activity" style="">
--- a/src/ltpdarepo/templates/database.html Fri Oct 14 22:02:41 2011 +0200 +++ b/src/ltpdarepo/templates/database.html Fri Oct 14 22:02:58 2011 +0200 @@ -7,7 +7,7 @@ <li><a href="{{ url_for('browse.browse', database=database.id) }}">Browse</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> - <li><a href="{{ url_for('activity.activity', database=database.id) }}">Activity</a></li> + <li><a href="{{ url_for('browse.activity', database=database.id) }}">Activity</a></li> </ul> <h2>Quick search</h2> <p class="discrete">Search objects by name:</p>
--- a/src/ltpdarepo/views/activity.py Fri Oct 14 22:02:41 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -from datetime import datetime -from dateutil.relativedelta import relativedelta, MO - -from flask import Blueprint, g, abort, render_template, request - -from ltpdarepo.database import Database -from ltpdarepo.security import require, view - -app = Blueprint('activity', __name__) - - -@app.route('/<database>/activity') -@require('user') -def activity(database, date=None): - with view('database', database): - db = Database().load(database) - if db is None: - # not found - abort(404) - - today = datetime.today().date() - date = request.args.get('date') - if date is not None: - today = datetime.strptime(date, '%Y-%m-%d').date() - - begin = today + relativedelta(day=1) - end = begin + relativedelta(months=1, days=-1) - prev = begin + relativedelta(months=-1) - next = begin + relativedelta(months=+1) - - curs = g.db.cursor() - - # prepare timeintervals table with proper intervals - curs.execute("""CALL makeintervals(%s, %s, 1, 'DAY')""", (begin, end)) - - # collect number of objects for each interval - curs.execute("""SELECT ts.begin AS date, COUNT(objmeta.obj_id) AS count - FROM ltpda.timeintervals AS ts - LEFT OUTER JOIN `%s`.objmeta ON (objmeta.submitted BETWEEN ts.begin AND ts.end) - GROUP BY ts.begin, ts.end""" % database) - - activity = curs.fetchall() - - return render_template('activity.html', database=db, activity=activity, - curr=today, prev=prev, next=next, dt=relativedelta(days=1)) - - -module = app
--- a/src/ltpdarepo/views/browse.py Fri Oct 14 22:02:41 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Fri Oct 14 22:02:58 2011 +0200 @@ -1,5 +1,6 @@ import re from datetime import datetime +from dateutil.relativedelta import relativedelta import dateutil.tz import dateutil.parser @@ -581,4 +582,40 @@ indexes=indexes, query=r.criteria, timerange=t) +@app.route('/<database>/activity') +@require('user') +def activity(database, date=None): + with view('database', database): + db = Database().load(database) + if db is None: + # not found + abort(404) + + today = datetime.today().date() + date = request.args.get('date') + if date is not None: + today = datetime.strptime(date, '%Y-%m-%d').date() + + begin = today + relativedelta(day=1) + end = begin + relativedelta(months=1, days=-1) + prev = begin + relativedelta(months=-1) + next = begin + relativedelta(months=+1) + + curs = g.db.cursor() + + # prepare timeintervals table with proper intervals + curs.execute("""CALL makeintervals(%s, %s, 1, 'DAY')""", (begin, end)) + + # collect number of objects for each interval + curs.execute("""SELECT ts.begin AS date, COUNT(objmeta.obj_id) AS count + FROM ltpda.timeintervals AS ts + LEFT OUTER JOIN `%s`.objmeta ON (objmeta.submitted BETWEEN ts.begin AND ts.end) + GROUP BY ts.begin, ts.end""" % database) + + activity = curs.fetchall() + + return render_template('activity.html', database=db, activity=activity, + curr=today, prev=prev, next=next, dt=relativedelta(days=1)) + + module = app