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

View File

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

View File

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

View File

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