Make /tags.json return tag objects instead of just easybake text
This commit is contained in:
parent
93b878bb3e
commit
b9b1879179
3 changed files with 22 additions and 15 deletions
|
@ -49,12 +49,14 @@ def photo(p, include_albums=True, include_tags=True):
|
||||||
|
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def tag(t):
|
def tag(t, include_synonyms=False):
|
||||||
j = {
|
j = {
|
||||||
'id': t.id,
|
'id': t.id,
|
||||||
'name': t.name,
|
'name': t.name,
|
||||||
'qualified_name': t.qualified_name(),
|
'qualified_name': t.qualified_name(),
|
||||||
}
|
}
|
||||||
|
if include_synonyms:
|
||||||
|
j['synonyms'] = list(t.synonyms())
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def user(u):
|
def user(u):
|
||||||
|
|
|
@ -578,19 +578,19 @@ def get_search_json():
|
||||||
|
|
||||||
|
|
||||||
def get_tags_core(specific_tag=None):
|
def get_tags_core(specific_tag=None):
|
||||||
try:
|
if specific_tag is None:
|
||||||
tags = P.export_tags(photodb.tag_export_easybake, specific_tag=specific_tag)
|
tags = P.get_tags()
|
||||||
except exceptions.NoSuchTag:
|
else:
|
||||||
flask.abort(404, 'That tag doesnt exist')
|
tags = specific_tag.walk_children()
|
||||||
tags = tags.split('\n')
|
tags = list(tags)
|
||||||
tags = [t for t in tags if t != '']
|
|
||||||
tags = [(t, t.split('.')[-1].split('+')[0]) for t in tags]
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
@site.route('/tags')
|
@site.route('/tags')
|
||||||
@site.route('/tags/<specific_tag>')
|
@site.route('/tags/<specific_tag>')
|
||||||
@session_manager.give_token
|
@session_manager.give_token
|
||||||
def get_tags_html(specific_tag=None):
|
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)
|
tags = get_tags_core(specific_tag)
|
||||||
session = session_manager.get(request)
|
session = session_manager.get(request)
|
||||||
return flask.render_template('tags.html', tags=tags, session=session)
|
return flask.render_template('tags.html', tags=tags, session=session)
|
||||||
|
@ -599,8 +599,10 @@ def get_tags_html(specific_tag=None):
|
||||||
@site.route('/tags/<specific_tag>.json')
|
@site.route('/tags/<specific_tag>.json')
|
||||||
@session_manager.give_token
|
@session_manager.give_token
|
||||||
def get_tags_json(specific_tag=None):
|
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 = 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)
|
return jsonify.make_json_response(tags)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,14 +65,17 @@ body
|
||||||
<div id="left">
|
<div id="left">
|
||||||
<ul>
|
<ul>
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
|
{% set qualname = tag.qualified_name() %}
|
||||||
<li>
|
<li>
|
||||||
<a target="_blank" class="tag_object" href="/search?tag_musts={{tag[1]}}">{{tag[0]}}</a>
|
<a target="_blank" class="tag_object" href="/search?tag_musts={{tag[1]}}">{{qualname}}</a><!--
|
||||||
{% if "+" in tag[0] %}
|
--><button class="remove_tag_button" onclick="delete_tag('{{tag[0]}}', receive_callback);"></button>
|
||||||
<button class="remove_tag_button" onclick="delete_tag_synonym('{{tag[0]}}', receive_callback);"></button>
|
|
||||||
{% else %}
|
|
||||||
<button class="remove_tag_button" onclick="delete_tag('{{tag[0]}}', receive_callback);"></button>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
</li>
|
||||||
|
{% for synonym in tag.synonyms() %}
|
||||||
|
<li>
|
||||||
|
<a target="_blank" class="tag_object" href="/search?tag_musts={{tag.name}}">{{qualname + "+" + synonym}}</a>
|
||||||
|
<button class="remove_tag_button" onclick="delete_tag_synonym('{{synonym}}', receive_callback);"></button>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue