# HG changeset patch # User Daniele Nicolodi # Date 1318622561 -7200 # Node ID 57dbb265a02a876f5c2641423ef756ff5742093f # Parent 5757ae81d57e7b81771a6c481bb31a4720d8fdec Make activity view to work. diff -r 5757ae81d57e -r 57dbb265a02a src/ltpdarepo/__init__.py --- a/src/ltpdarepo/__init__.py Fri Oct 14 21:59:42 2011 +0200 +++ b/src/ltpdarepo/__init__.py Fri Oct 14 22:02:41 2011 +0200 @@ -127,6 +127,9 @@ 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 5757ae81d57e -r 57dbb265a02a src/ltpdarepo/static/style.css --- a/src/ltpdarepo/static/style.css Fri Oct 14 21:59:42 2011 +0200 +++ b/src/ltpdarepo/static/style.css Fri Oct 14 22:02:41 2011 +0200 @@ -355,7 +355,12 @@ /* activity view */ .activity { - margin: 1em; + border: 1px solid #CCC; + padding: 2px; + margin: 0; + box-shadow: 0px 0px 2px #DDD; + -moz-box-shadow: 0px 0px 2px #DDD; + -webkit-box-shadow: 0px 0px 2px #DDD; } .activity table { @@ -365,13 +370,25 @@ .activity td { margin: 0; - padding: 0.3em; + padding: 4px 0; border: none; font-size: 90%; } +.activity td span.num { + display: inline-block; + width: 2em; + visibility: hidden; +} + +.activity td:hover span.num { + visibility: visible; + color: red; +} + .activity td.bars { - padding: 0 2px; + padding: 0 1px; + margin: 0; vertical-align: bottom; } @@ -381,6 +398,31 @@ width: 100%; } +.monthes { + float: right; + font-size: 90%; +} + +.monthes a, .monthes span { + text-align: center; + text-decoration: none; + color: #888; + display: inline-block; + float: left; + padding: 0px; + margin: 5px; + border-bottom: 1px solid white; +} + +.monthes a:hover { + border-bottom: 1px solid #888; +} + +.day { + color: #888; + font-size: 90%; +} + /* search form */ .search { diff -r 5757ae81d57e -r 57dbb265a02a src/ltpdarepo/templates/activity.html --- a/src/ltpdarepo/templates/activity.html Fri Oct 14 21:59:42 2011 +0200 +++ b/src/ltpdarepo/templates/activity.html Fri Oct 14 22:02:41 2011 +0200 @@ -1,57 +1,32 @@ {% extends "layout.html" %} {% block title %}{{ database.id }}{% endblock %} -{% block head %} - - -{% endblock %} {% block body %}

Database «{{ database.id }}»

{{ database.description }}

-{# +

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

- +
+ prev + next + today +
- -#} -
+
- {% set nmax = 300 %} - {% for when, n in activity %} - {% set height = n * 300 / nmax %} - + {% for day, num in activity %} + {% set height = num * 300 / nmax %} + {% endfor %} - - - {% for when, number in activity %} - + {% for when, num in activity %} + {% endfor %} -
 
+ {{ num }}
 
+
«{{ when }}{{ when.strftime('%d') }}»
- -{# - -#} {% endblock %} diff -r 5757ae81d57e -r 57dbb265a02a src/ltpdarepo/templates/database.html --- a/src/ltpdarepo/templates/database.html Fri Oct 14 21:59:42 2011 +0200 +++ b/src/ltpdarepo/templates/database.html Fri Oct 14 22:02:41 2011 +0200 @@ -5,9 +5,9 @@

{{ database.description }}

Quick search

Search objects by name:

diff -r 5757ae81d57e -r 57dbb265a02a src/ltpdarepo/views/activity.py --- a/src/ltpdarepo/views/activity.py Fri Oct 14 21:59:42 2011 +0200 +++ b/src/ltpdarepo/views/activity.py Fri Oct 14 22:02:41 2011 +0200 @@ -1,6 +1,7 @@ -import datetime +from datetime import datetime +from dateutil.relativedelta import relativedelta, MO -from flask import Blueprint, g, abort, render_template +from flask import Blueprint, g, abort, render_template, request from ltpdarepo.database import Database from ltpdarepo.security import require, view @@ -9,35 +10,39 @@ @app.route('//activity') -@app.route('//activity//') @require('user') -def activity(database, period='week', date=None): +def activity(database, date=None): with view('database', database): db = Database().load(database) if db is None: # not found abort(404) - curs = g.db.cursor() + today = datetime.today().date() + date = request.args.get('date') + if date is not None: + today = datetime.strptime(date, '%Y-%m-%d').date() - if date is None: - today = datetime.date.today() - else: - today = datetime.datetime.strptime(date, '%Y-%m-%d').date() - - activity = [] + begin = today + relativedelta(day=1) + end = begin + relativedelta(months=1, days=-1) + prev = begin + relativedelta(months=-1) + next = begin + relativedelta(months=+1) - 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)) + curs = g.db.cursor() + + # prepare timeintervals table with proper intervals + curs.execute("""CALL makeintervals(%s, %s, 1, 'DAY')""", (begin, end)) - return render_template('activity.html', database=db, activity=activity) + # 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