# HG changeset patch # User Daniele Nicolodi # Date 1314115452 -7200 # Node ID 22b950fee548befb92c6ca00c7a45db594680ace # Parent 0d259fd52ca0f0823e53f5515b9480fef47fd867 Complete named queries support. diff -r 0d259fd52ca0 -r 22b950fee548 src/ltpdarepo/query.py --- a/src/ltpdarepo/query.py Tue Aug 23 14:38:17 2011 +0200 +++ b/src/ltpdarepo/query.py Tue Aug 23 18:04:12 2011 +0200 @@ -1,13 +1,13 @@ import re -from flask import g +from flask import Markup, g, json from MySQLdb.cursors import DictCursor - -from ltpdarepo.form import Form from wtforms.fields import TextField, HiddenField from wtforms import validators from wtforms.validators import ValidationError +from ltpdarepo.form import Form + class IQuery(Form): query = HiddenField() @@ -63,3 +63,10 @@ curs = g.db.cursor() curs.execute("""DELETE FROM queries WHERE id=%s""", self.id) g.db.commit() + + def tostring(self): + criteria = json.loads(self.query) + print criteria + query = ["%s %s '%s'" % (field, op, value) for field, op, value in criteria] + string = ' AND '.join(s.replace(' ', ' ') for s in query) + return Markup(string) diff -r 0d259fd52ca0 -r 22b950fee548 src/ltpdarepo/static/style.css --- a/src/ltpdarepo/static/style.css Tue Aug 23 14:38:17 2011 +0200 +++ b/src/ltpdarepo/static/style.css Tue Aug 23 18:04:12 2011 +0200 @@ -505,6 +505,12 @@ padding: 4px 4px 5px 5px; } +.querystring { + margin-top: 3em; + color: #888; + white-space: pre-wrap; +} + /* permisions display */ .permissions { diff -r 0d259fd52ca0 -r 22b950fee548 src/ltpdarepo/templates/namedquery.html --- a/src/ltpdarepo/templates/namedquery.html Tue Aug 23 14:38:17 2011 +0200 +++ b/src/ltpdarepo/templates/namedquery.html Tue Aug 23 18:04:12 2011 +0200 @@ -1,3 +1,6 @@ {% extends "objs.html" %} {% block title %}{{ query.title }} — {{ database.id }}{% endblock %} {% block pagetitle %}{{ query.title }} — Database «{{ database.id }}»{% endblock %} +{% block below %} +
{{ querystring }}
+{% endblock %} diff -r 0d259fd52ca0 -r 22b950fee548 src/ltpdarepo/templates/queries/view.html --- a/src/ltpdarepo/templates/queries/view.html Tue Aug 23 14:38:17 2011 +0200 +++ b/src/ltpdarepo/templates/queries/view.html Tue Aug 23 18:04:12 2011 +0200 @@ -3,7 +3,7 @@ {% block body %}

Query «{{ query.title }}»

Database: {{ query.db }}

-

Criteria: {{ query.query }}

+

Query: {{ query.tostring() }}