Let search_core return tags as real lists.

This lets search.html deal with real objects instead of playing with
dumed-down strings.
This commit is contained in:
voussoir 2020-09-09 13:09:48 -07:00
parent d585fe92a9
commit 6d5cd11612
2 changed files with 11 additions and 13 deletions

View file

@ -382,13 +382,6 @@ def get_search_core():
search_kwargs = next(search_generator) search_kwargs = next(search_generator)
# print(search_kwargs) # print(search_kwargs)
# The search has converted many arguments into sets or other types.
# Convert them back into something that will display nicely on the search form.
tagname_helper = lambda tags: [tag.name for tag in tags] if tags else None
search_kwargs['tag_musts'] = tagname_helper(search_kwargs['tag_musts'])
search_kwargs['tag_mays'] = tagname_helper(search_kwargs['tag_mays'])
search_kwargs['tag_forbids'] = tagname_helper(search_kwargs['tag_forbids'])
warnings = set() warnings = set()
search_results = [] search_results = []
for item in search_generator: for item in search_generator:
@ -474,6 +467,11 @@ def get_search_json():
author_helper = lambda users: ', '.join(user.username for user in users) if users else None author_helper = lambda users: ', '.join(user.username for user in users) if users else None
search_kwargs['author'] = author_helper(search_kwargs['author']) search_kwargs['author'] = author_helper(search_kwargs['author'])
tagname_helper = lambda tags: [tag.name for tag in tags] if tags else None
search_kwargs['tag_musts'] = tagname_helper(search_kwargs['tag_musts'])
search_kwargs['tag_mays'] = tagname_helper(search_kwargs['tag_mays'])
search_kwargs['tag_forbids'] = tagname_helper(search_kwargs['tag_forbids'])
search_results['results'] = [ search_results['results'] = [
etiquette.jsonify.photo(result, include_albums=False) etiquette.jsonify.photo(result, include_albums=False)
if isinstance(result, etiquette.objects.Photo) else if isinstance(result, etiquette.objects.Photo) else

View file

@ -185,11 +185,11 @@
<ul class="search_builder_tagger"> <ul class="search_builder_tagger">
{% set key="tag_" + tagtype %} {% set key="tag_" + tagtype %}
{% if search_kwargs[key] %} {% if search_kwargs[key] %}
{% for tagname in search_kwargs[key] %} {% for tag in search_kwargs[key] %}
<li class="search_builder_{{tagtype}}_inputted"> <li class="search_builder_{{tagtype}}_inputted">
<span class="tag_object">{{tagname}}</span>{{-''-}} {{tag_object.tag_object(tag, link='info', with_alt_description=True)}}<!--
<button class="remove_tag_button red_button" --><button class="remove_tag_button red_button"
onclick="return remove_searchtag(ul_{{tagtype}}, '{{tagname}}', inputted_{{tagtype}});"></button> onclick="return remove_searchtag(ul_{{tagtype}}, '{{tag.name}}', inputted_{{tagtype}});"></button>
</li> </li>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -664,8 +664,8 @@ var inputted_forbids = [];
{% for tagtype in ["musts", "mays", "forbids"] %} {% for tagtype in ["musts", "mays", "forbids"] %}
{% set key="tag_" + tagtype %} {% set key="tag_" + tagtype %}
{% if search_kwargs[key] %} {% if search_kwargs[key] %}
{% for tagname in search_kwargs[key] %} {% for tag in search_kwargs[key] %}
inputted_{{tagtype}}.push("{{tagname}}"); inputted_{{tagtype}}.push("{{tag.name}}");
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}