view src/ltpdarepo/templates/query.html @ 19:76e6b6c5d5cb

Add a 'limits' property to the Pagination class. The 'limits' property returns the index boundaries for the current page in the paginated list and is usefull to implement SQL queries.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 27 Jun 2011 14:08:38 +0200
parents 9a835002fe49
children aa8b0bb724f6
line wrap: on
line source

{% extends "layout.html" %}
{% block title %}{{ database.id }}{% endblock %}
{% block head %}
    <script type="text/javascript" src="{{ url_for('.static', filename='jquery.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('.static', filename='querywidget.js') }}"></script>
    <script type="text/javascript">
      var criteria = {{ criteria|tojson|safe }};
    </script>
{% endblock %}
{% block body %}
<h2>Database &#x00AB;{{ database.id }}&#x00BB;</h2>
<p class="discrete">{{ database.description|default('&mdash;'|safe, true) }}</p>
<div class="query">
  <form method="GET" action="{{ url_for('browse.query', database=database.id) }}">
    <div id="criteria" class="wrapper">
      {% for field, op, value in query %}
      <div class="criteria wrapper">
        <span class="querywidget field">{{ criteria[field]['name'] }}</span>
        <input type="hidden" name="field" value="{{ field }}"></input>
        <select class="querywidget operator" name="operator">
          {% for name in criteria[field]['operators'] %}
          {% if op == name %}
          <option name="{{ name }}" selected="selected">{{ name }}</option>
          {% else %}
          <option name="{{ name }}">{{ name }}</option>
          {% endif %}
          {% endfor %}
        </select>
        {% if criteria[field]['type'] == 'enum' %}
        <select class="querywidget value" name="value">
          {% for name in criteria[field]['values'] %}
          {% if value == name %}
          <option name="{{ name }}" selected="selected">{{ name }}</option>
          {% else %}
          <option name="{{ name }}">{{ name }}</option>
          {% endif %}
          {% endfor %}
        </select>
        {% else %}
        <input class="querywidget value" autocomplete="off" type="text" name="value" value="{{ value }}"></input>
        {% endif %}
        <input class="querywidget remove" type="button" name="remove" value="&times;"></input>
      </div>
      {% endfor %}
    </div>

    <div>
      <select id="add">
        <option value="" selected="selected">Add criteria&hellip;</option>
        {% for c in criteria.values() %}
        <option value="{{ c['val'] }}">{{ c['name'] }}</option>
        {% endfor %}
      </select>
    </div>

    <div>
      <input type="submit" value="&raquo;" class="search"></input>
    </div>
    {% if 'admin' in g.identity.roles %}
    <div id="save-search-criteria">
      <input id="save" type="submit" name="save" value="save"></input>
    </div>
    {% endif %}

  </form>
</div>

{% if objs %}
<table class="listing">
  <thead>
    <tr>
      {% for field in fields %}
      <th>{{ field }}</th>
      {% endfor %}
    </tr>
  </thead>
  <tbody>
    {% for obj in objs %}
    <tr class="data {{ loop.cycle('odd', 'even') }}" id="{{ loop.index }}">
      {% for field in fields %}
      {% if field == 'name' %}
      <td class="{{ field }}"><a href="{{ url_for('browse.obj', database=database.id, objid=obj.id) }}">{{ obj[field] }}</a></td>
      {% else %}
      <td class="{{ field }}">{{ obj[field]|string|truncate(60, False, '…') }}</td>
      {% endif %}
      {% endfor %}
    </tr>
    <tr class="details" id="{{ loop.index }}">
      <td colspan="{{ fields|length }}" style="text-align: left;">details</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endif %}
{% endblock %}