Add ?synonyms to show/hide synonyms.

This commit is contained in:
voussoir 2017-04-22 21:12:43 -07:00
parent 6fcdb2f0cd
commit 72aaf3460d
2 changed files with 20 additions and 8 deletions

View file

@ -607,7 +607,15 @@ def get_tags_html(specific_tag=None):
specific_tag = P_tag(specific_tag, response_type='html') 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) include_synonyms = request.args.get('synonyms')
include_synonyms = include_synonyms is None or helpers.truthystring(include_synonyms)
response = flask.render_template(
'tags.html',
include_synonyms=include_synonyms,
session=session,
tags=tags,
)
return response
@site.route('/tags.json') @site.route('/tags.json')
@site.route('/tags/<specific_tag>.json') @site.route('/tags/<specific_tag>.json')
@ -616,7 +624,9 @@ def get_tags_json(specific_tag=None):
if specific_tag is not None: if specific_tag is not None:
specific_tag = P_tag(specific_tag, response_type='json') specific_tag = P_tag(specific_tag, response_type='json')
tags = get_tags_core(specific_tag) tags = get_tags_core(specific_tag)
tags = [jsonify.tag(tag, include_synonyms=True) for tag in tags] include_synonyms = request.args.get('synonyms')
include_synonyms = include_synonyms is None or helpers.truthystring(include_synonyms)
tags = [jsonify.tag(tag, include_synonyms=include_synonyms) for tag in tags]
return jsonify.make_json_response(tags) return jsonify.make_json_response(tags)

View file

@ -74,12 +74,14 @@ body
<a target="_blank" class="tag_object" href="/search?tag_musts={{tag.name}}">{{qualname}}</a><!-- <a target="_blank" class="tag_object" href="/search?tag_musts={{tag.name}}">{{qualname}}</a><!--
--><button class="remove_tag_button" onclick="delete_tag('{{tag.name}}', receive_callback);"></button> --><button class="remove_tag_button" onclick="delete_tag('{{tag.name}}', receive_callback);"></button>
</li> </li>
{% for synonym in tag.synonyms() %} {% if include_synonyms %}
<li> {% for synonym in tag.synonyms() %}
<a target="_blank" class="tag_object" href="/search?tag_musts={{tag.name}}">{{qualname + "+" + synonym}}</a><!-- <li>
--><button class="remove_tag_button" onclick="delete_tag_synonym('{{synonym}}', receive_callback);"></button> <a target="_blank" class="tag_object" href="/search?tag_musts={{tag.name}}">{{qualname + "+" + synonym}}</a><!--
</li> --><button class="remove_tag_button" onclick="delete_tag_synonym('{{synonym}}', receive_callback);"></button>
{% endfor %} </li>
{% endfor %}
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>