From b9b187917924de8a1a7c70faa15085b41758c13d Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 4 Mar 2017 19:59:16 -0800 Subject: [PATCH] Make /tags.json return tag objects instead of just easybake text --- etiquette/jsonify.py | 4 +++- etiquette_site.py | 18 ++++++++++-------- templates/tags.html | 15 +++++++++------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/etiquette/jsonify.py b/etiquette/jsonify.py index 9dd08a7..395e940 100644 --- a/etiquette/jsonify.py +++ b/etiquette/jsonify.py @@ -49,12 +49,14 @@ def photo(p, include_albums=True, include_tags=True): return j -def tag(t): +def tag(t, include_synonyms=False): j = { 'id': t.id, 'name': t.name, 'qualified_name': t.qualified_name(), } + if include_synonyms: + j['synonyms'] = list(t.synonyms()) return j def user(u): diff --git a/etiquette_site.py b/etiquette_site.py index 81cede4..fa8a6a3 100644 --- a/etiquette_site.py +++ b/etiquette_site.py @@ -578,19 +578,19 @@ def get_search_json(): def get_tags_core(specific_tag=None): - try: - tags = P.export_tags(photodb.tag_export_easybake, specific_tag=specific_tag) - except exceptions.NoSuchTag: - flask.abort(404, 'That tag doesnt exist') - tags = tags.split('\n') - tags = [t for t in tags if t != ''] - tags = [(t, t.split('.')[-1].split('+')[0]) for t in tags] + if specific_tag is None: + tags = P.get_tags() + else: + tags = specific_tag.walk_children() + tags = list(tags) return tags @site.route('/tags') @site.route('/tags/') @session_manager.give_token def get_tags_html(specific_tag=None): + if specific_tag is not None: + specific_tag = P_tag(specific_tag, response_type='html') tags = get_tags_core(specific_tag) session = session_manager.get(request) return flask.render_template('tags.html', tags=tags, session=session) @@ -599,8 +599,10 @@ def get_tags_html(specific_tag=None): @site.route('/tags/.json') @session_manager.give_token def get_tags_json(specific_tag=None): + if specific_tag is not None: + specific_tag = P_tag(specific_tag, response_type='json') tags = get_tags_core(specific_tag) - tags = [t[0] for t in tags] + tags = [jsonify.tag(tag, include_synonyms=True) for tag in tags] return jsonify.make_json_response(tags) diff --git a/templates/tags.html b/templates/tags.html index 371148b..1516d03 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -65,14 +65,17 @@ body
    {% for tag in tags %} + {% set qualname = tag.qualified_name() %}
  • - {{tag[0]}} - {% if "+" in tag[0] %} - - {% else %} - - {% endif %} + {{qualname}}
  • + {% for synonym in tag.synonyms() %} +
  • + {{qualname + "+" + synonym}} + +
  • + {% endfor %} {% endfor %}