# HG changeset patch # User Daniele Nicolodi # Date 1308152922 -7200 # Node ID 8e1c24d9067ddb7d8a67b76117281ab9b00ec12d # Parent d6bedd937d102f04f4590eb78ea1c7f321a22d34 Fix object display. Implement xml and binary representations download. diff -r d6bedd937d10 -r 8e1c24d9067d src/ltpdarepo/static/style.css --- a/src/ltpdarepo/static/style.css Wed Jun 15 15:56:33 2011 +0200 +++ b/src/ltpdarepo/static/style.css Wed Jun 15 17:48:42 2011 +0200 @@ -493,3 +493,19 @@ #save-search-criteria { float: right; } + +/* object display */ + +table.obj th { + text-align: right; + border: none; +} + +table.obj td { + text-align: left; + border: none; +} + +table.obj tr:hover td { + border: none; +} diff -r d6bedd937d10 -r 8e1c24d9067d src/ltpdarepo/templates/obj.html --- a/src/ltpdarepo/templates/obj.html Wed Jun 15 15:56:33 2011 +0200 +++ b/src/ltpdarepo/templates/obj.html Wed Jun 15 17:48:42 2011 +0200 @@ -2,7 +2,11 @@ {% block title %}{{ dbname }}{% endblock %} {% block body %}

{{ database.id }} - {{ obj.name }}

-{% for name, value in obj.iteritems() %} -

{{ name }}: {{ value }}

-{% endfor %} + + {% for field in fields %} + + {% endfor %} + + +
{{ field }}:{{ obj[field] }}
xml:download
binary:download
{% endblock %} diff -r d6bedd937d10 -r 8e1c24d9067d src/ltpdarepo/views/browse.py --- a/src/ltpdarepo/views/browse.py Wed Jun 15 15:56:33 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Wed Jun 15 17:48:42 2011 +0200 @@ -2,7 +2,7 @@ from textwrap import dedent from operator import itemgetter -from flask import Module, abort, g, request, render_template, redirect, current_app, url_for, json +from flask import Module, abort, g, request, render_template, redirect, current_app, url_for, json, make_response from MySQLdb.cursors import DictCursor from ltpdarepo.security import require, view @@ -167,12 +167,50 @@ if db is None: # not found abort(404) + objs = Objs(database=database, where='obj_id=%s') curs = g.db.cursor(DictCursor) - curs.execute(''' - SELECT obj_id AS id, name, obj_type AS type, experiment_title, experiment_desc, analysis_desc, - quantity, keywords, submitted, created FROM `%s`.objmeta WHERE obj_id = %%s''' % database, objid) + curs.execute(objs.query, objid) obj = curs.fetchone() - return render_template('obj.html', obj=obj, database=db) + return render_template('obj.html', database=db, obj=obj, fields=ALLFIELDS) + + +@app.route('///') +@require('user') +def download(database, objid, frmt): + with view('database', database): + db = Database().load(database) + if db is None: + # not found + abort(404) + + if frmt == 'xml': + curs = g.db.cursor() + n = curs.execute("""SELECT xml FROM `%s`.objs WHERE id=%%s""" % database, objid) + if n != 1: + # not found + abort(404) + data = curs.fetchone()[0] or '' + response = make_response(data) + response.mimetype = 'text/xml' + filename = '%s-%s.%s' % (database, objid, 'xml') + response.headers.add('Content-Disposition' , 'attachment', filename=filename) + return response + + if frmt == 'binary': + curs = g.db.cursor() + n = curs.execute("""SELECT mat FROM `%s`.bobjs WHERE obj_id=%%s""" % database, objid) + if n != 1: + # not found + abort(404) + data = curs.fetchone()[0] or '' + response = make_response(data) + response.mimetype = 'application/matlab' + filename = '%s-%s.%s' % (database, objid, 'mat') + response.headers.add('Content-Disposition' , 'attachment', filename=filename) + return response + + # unauthorized + abort(403) @app.route('//search')