# HG changeset patch # User Daniele Nicolodi # Date 1318622578 -7200 # Node ID 66b8360a41c9146b95ff780a439e812b4c254cdc # Parent 57dbb265a02a876f5c2641423ef756ff5742093f Fold activity blueprint into browse blueprint. diff -r 57dbb265a02a -r 66b8360a41c9 src/ltpdarepo/__init__.py --- 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') diff -r 57dbb265a02a -r 66b8360a41c9 src/ltpdarepo/templates/activity.html --- 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 @@

Objects submitted per day in {{ curr.strftime('%B %Y') }}

- prev - next - today + prev + next + today
diff -r 57dbb265a02a -r 66b8360a41c9 src/ltpdarepo/templates/database.html --- 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 @@
  • Browse
  • Advanced search
  • Timeseries search
  • -
  • Activity
  • +
  • Activity
  • Quick search

    Search objects by name:

    diff -r 57dbb265a02a -r 66b8360a41c9 src/ltpdarepo/views/activity.py --- 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('//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 diff -r 57dbb265a02a -r 66b8360a41c9 src/ltpdarepo/views/browse.py --- 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('//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