Let search_core return extension as real list.
This lets search.html deal with real objects instead of playing with dumed-down strings.
This commit is contained in:
parent
8ed5f0be51
commit
94b811b3b1
4 changed files with 20 additions and 9 deletions
|
@ -33,6 +33,7 @@ site.jinja_env.add_extension('jinja2.ext.do')
|
||||||
site.jinja_env.trim_blocks = True
|
site.jinja_env.trim_blocks = True
|
||||||
site.jinja_env.lstrip_blocks = True
|
site.jinja_env.lstrip_blocks = True
|
||||||
site.jinja_env.filters['bytestring'] = jinja_filters.bytestring
|
site.jinja_env.filters['bytestring'] = jinja_filters.bytestring
|
||||||
|
site.jinja_env.filters['comma_join'] = jinja_filters.comma_join
|
||||||
site.jinja_env.filters['file_link'] = jinja_filters.file_link
|
site.jinja_env.filters['file_link'] = jinja_filters.file_link
|
||||||
site.jinja_env.filters['sort_tags'] = jinja_filters.sort_tags
|
site.jinja_env.filters['sort_tags'] = jinja_filters.sort_tags
|
||||||
site.jinja_env.filters['timestamp_to_8601'] = jinja_filters.timestamp_to_8601
|
site.jinja_env.filters['timestamp_to_8601'] = jinja_filters.timestamp_to_8601
|
||||||
|
|
|
@ -376,18 +376,14 @@ def get_search_core():
|
||||||
'warning_bag': warning_bag,
|
'warning_bag': warning_bag,
|
||||||
'give_back_parameters': True
|
'give_back_parameters': True
|
||||||
}
|
}
|
||||||
#print(search_kwargs)
|
# print(search_kwargs)
|
||||||
search_generator = common.P.search(**search_kwargs)
|
search_generator = common.P.search(**search_kwargs)
|
||||||
# Because of the giveback, first element is cleaned up kwargs
|
# Because of the giveback, first element is cleaned up kwargs
|
||||||
search_kwargs = next(search_generator)
|
search_kwargs = next(search_generator)
|
||||||
|
# print(search_kwargs)
|
||||||
|
|
||||||
# The search has converted many arguments into sets or other types.
|
# The search has converted many arguments into sets or other types.
|
||||||
# Convert them back into something that will display nicely on the search form.
|
# Convert them back into something that will display nicely on the search form.
|
||||||
join_helper = lambda x: ', '.join(x) if x else None
|
|
||||||
search_kwargs['extension'] = join_helper(search_kwargs['extension'])
|
|
||||||
search_kwargs['extension_not'] = join_helper(search_kwargs['extension_not'])
|
|
||||||
search_kwargs['mimetype'] = join_helper(search_kwargs['mimetype'])
|
|
||||||
|
|
||||||
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'])
|
||||||
|
|
||||||
|
@ -469,6 +465,15 @@ def get_search_html():
|
||||||
@session_manager.give_token
|
@session_manager.give_token
|
||||||
def get_search_json():
|
def get_search_json():
|
||||||
search_results = get_search_core()
|
search_results = get_search_core()
|
||||||
|
search_kwargs = search_results['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.
|
||||||
|
join_helper = lambda x: ', '.join(x) if x else None
|
||||||
|
search_kwargs['extension'] = join_helper(search_kwargs['extension'])
|
||||||
|
search_kwargs['extension_not'] = join_helper(search_kwargs['extension_not'])
|
||||||
|
search_kwargs['mimetype'] = join_helper(search_kwargs['mimetype'])
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -10,6 +10,11 @@ def bytestring(x):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return '??? b'
|
return '??? b'
|
||||||
|
|
||||||
|
def comma_join(l):
|
||||||
|
if not l:
|
||||||
|
return ''
|
||||||
|
return ', '.join(l)
|
||||||
|
|
||||||
def file_link(photo, short=False):
|
def file_link(photo, short=False):
|
||||||
if short:
|
if short:
|
||||||
return f'/file/{photo.id}{photo.dot_extension}'
|
return f'/file/{photo.id}{photo.dot_extension}'
|
||||||
|
|
|
@ -259,15 +259,15 @@
|
||||||
name="filename" placeholder="Filename">
|
name="filename" placeholder="Filename">
|
||||||
|
|
||||||
<input type="text" class="basic_param"
|
<input type="text" class="basic_param"
|
||||||
{%if search_kwargs['mimetype']%} value="{{search_kwargs['mimetype']}}" {%endif%}
|
value="{{search_kwargs['mimetype']|comma_join}}"
|
||||||
name="mimetype" placeholder="Mimetype(s)">
|
name="mimetype" placeholder="Mimetype(s)">
|
||||||
|
|
||||||
<input type="text" class="basic_param"
|
<input type="text" class="basic_param"
|
||||||
{%if search_kwargs['extension']%} value="{{search_kwargs['extension']}}" {%endif%}
|
value="{{search_kwargs['extension']|comma_join}}"
|
||||||
name="extension" placeholder="Extension(s)">
|
name="extension" placeholder="Extension(s)">
|
||||||
|
|
||||||
<input type="text" class="basic_param"
|
<input type="text" class="basic_param"
|
||||||
{%if search_kwargs['extension_not']%} value="{{search_kwargs['extension_not']}}" {%endif%}
|
value="{{search_kwargs['extension_not']|comma_join}}"
|
||||||
name="extension_not" placeholder="Forbid extension(s)">
|
name="extension_not" placeholder="Forbid extension(s)">
|
||||||
|
|
||||||
<input type="text" class="basic_param"
|
<input type="text" class="basic_param"
|
||||||
|
|
Loading…
Reference in a new issue