Add support for colors and references

pull/2/head
Raphaël Vinot 2016-10-12 14:22:19 +02:00
parent 4c0b6e7e8a
commit c3e5ee9ff8
4 changed files with 36 additions and 15 deletions

View File

@ -15,12 +15,13 @@ except ImportError:
class Entry():
def __init__(self, value, expanded, description):
def __init__(self, value, expanded, colour, description):
self.value = value
self.expanded = expanded.encode('utf-8')
self.expanded = expanded
self.colour = colour
self.description = None
if description:
self.description = description.encode('utf-8')
self.description = description
def __str__(self):
return self.value
@ -28,11 +29,12 @@ class Entry():
class Predicate(collections.Mapping):
def __init__(self, predicate, description, entries):
def __init__(self, predicate, description, colour, entries):
self.predicate = predicate
self.description = None
self.colour = colour
if description:
self.description = description.encode('utf-8')
self.description = description
self.entries = {}
if entries:
self.__init_entries(entries)
@ -40,7 +42,7 @@ class Predicate(collections.Mapping):
def __init_entries(self, entries):
for e in entries:
self.entries[e['value']] = Entry(e['value'], e['expanded'],
e.get('description'))
e.get('colour'), e.get('description'))
def __str__(self):
return self.predicate
@ -63,6 +65,7 @@ class Taxonomy(collections.Mapping):
self.description = self.taxonomy['description']
self.version = self.taxonomy['version']
self.expanded = self.taxonomy.get('expanded')
self.refs = self.taxonomy.get('refs')
self.__init_predicates()
def __init_predicates(self):
@ -75,7 +78,7 @@ class Taxonomy(collections.Mapping):
entries[v['predicate']] += v['entry']
for p in self.taxonomy['predicates']:
self.predicates[p['value']] = Predicate(p['value'], p.get('expanded'),
entries.get(p['value']))
p.get('colour'), entries.get(p['value']))
def has_entries(self):
if self.predicates.values() and list(self.predicates.values())[0].entries:

View File

@ -10,6 +10,7 @@ from pytaxonomies import Taxonomies
nav = Nav()
@nav.navigation()
def mynavbar():
return Navbar(
@ -31,6 +32,7 @@ t = Taxonomies()
def index():
return taxonomies()
@app.route('/taxonomies/', defaults={'name': None})
@app.route('/taxonomies/<name>', methods=['GET'])
def taxonomies(name=None):
@ -52,9 +54,5 @@ def search():
return render_template('search.html', query=None, entries=None)
def main():
app.run()
if __name__ == '__main__':
main()

View File

@ -14,9 +14,14 @@
</script>
{% endblock %}
{% block head %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='dataTables.bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='pytaxonomies.css') }}">
{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block navbar %}

View File

@ -5,6 +5,16 @@
<div class="container">
<h1>{% if taxonomy.expanded %}{{ taxonomy.expanded }} {%else%} {{taxonomy.name}} {%endif%} (Version {{ taxonomy.version }})</h1>
<h3>{{ taxonomy.description }}</h3>
{% if taxonomy.refs %}
<div>
References:
<ul>
{% for r in taxonomy.refs %}
<li><a href="{{r}}">{{r}}</a></li>
{%endfor%}
</ul>
</div>
{% endif %}
<table class="table table-striped table-bordered" id="pytaxonomies_table">
<thead>
<tr>
@ -13,6 +23,7 @@
{% if taxonomy.has_entries() %}
<th>Values</th>
{% else %}
<th>Colour</th>
<th>Machinetag</th>
{% endif %}
</tr>
@ -24,6 +35,7 @@
{% if taxonomy.has_entries() %}
<th>Values</th>
{% else %}
<th>Colour</th>
<th>Machinetag</th>
{% endif %}
</tr>
@ -31,7 +43,7 @@
<tbody>
{% for p in taxonomy.predicates.values() %}
<tr>
<td>{% if p.description %}{{ p.description.decode() }}{% endif %}</td>
<td>{% if p.description %}{{ p.description }}{% endif %}</td>
<td>{{ p.predicate }}</td>
{% if p.entries %}
<td>
@ -41,6 +53,7 @@
<th>Value</th>
<th>Expanded</th>
<th>Description</th>
<th>Colour</th>
<th>Machinetag</th>
</tr>
</thead>
@ -48,8 +61,9 @@
{% for e in p.entries.values() %}
<tr>
<td>{{ e.value }}</td>
<td>{% if e.expanded %}{{ e.expanded.decode() }}{% endif %}</td>
<td>{% if e.description %}{{ e.description.decode() }}{% endif %}</td>
<td>{% if e.expanded %}{{ e.expanded }}{% endif %}</td>
<td>{% if e.description %}{{ e.description }}{% endif %}</td>
<td>{% if p.colour %}<div class='colorbox' background={{ p.colour }}></div>{% endif %}</td>
<td>{{ taxonomy.make_machinetag(p, e) }}</td>
</tr>
{% endfor %}
@ -57,6 +71,7 @@
</table>
</td>
{% else %}
<td>{% if p.colour %}<div class='colorbox' style="background: {{ p.colour }};"></div>{% endif %}</td>
<td>{{ taxonomy.make_machinetag(p) }}</td>
{% endif %}
</tr>