Return friendly and expanded orderby column separately.

Previously, the UI had to un-transform the expanded column back
into the friendly name, which was silly and cumbersome.
This commit is contained in:
voussoir 2021-01-01 13:37:17 -08:00
parent 79327de0f0
commit 2c29c196a7
3 changed files with 30 additions and 23 deletions

View file

@ -776,12 +776,14 @@ class PDBPhotoMixin:
else: else:
filename_tree = None filename_tree = None
giveback_orderby = [ if orderby:
'%s-%s' % (column.replace('RANDOM()', 'random'), direction) giveback_orderby = [
for (column, direction) in orderby f'{friendly}-{direction}'
] for (friendly, expanded, direction) in orderby
]
if not orderby: orderby = [(expanded, direction) for (friendly, expanded, direction) in orderby]
else:
giveback_orderby = None
orderby = [('created', 'desc')] orderby = [('created', 'desc')]
if give_back_parameters: if give_back_parameters:
@ -807,7 +809,7 @@ class PDBPhotoMixin:
'within_directory': within_directory or None, 'within_directory': within_directory or None,
'limit': limit, 'limit': limit,
'offset': offset or None, 'offset': offset or None,
'orderby': giveback_orderby or None, 'orderby': giveback_orderby,
'yield_albums': yield_albums, 'yield_albums': yield_albums,
'yield_photos': yield_photos, 'yield_photos': yield_photos,
} }

View file

@ -290,7 +290,10 @@ def normalize_orderby(orderby, warning_bag=None):
With no direction, direction is implied desc. With no direction, direction is implied desc.
Returns: A list of tuples of (column, direction) Returns: A list of tuples of (column_friendly, column_expanded, direction)
where friendly is the name as the user would see it and expanded is the
expression to be used in the SQL query. This is important for columns like
"area" which is expanded into width*height.
''' '''
if orderby is None: if orderby is None:
orderby = [] orderby = []
@ -344,23 +347,25 @@ def normalize_orderby(orderby, warning_bag=None):
else: else:
raise exc raise exc
if column == 'random': column_friendly = column
column = 'RANDOM()' column_expanded = column
elif column == 'area': if column_expanded == 'random':
column = '(width * height)' column_expanded = 'RANDOM()'
elif column == 'basename': elif column_expanded == 'area':
column = 'COALESCE(override_filename, basename)' column_expanded = '(width * height)'
elif column == 'bitrate': elif column_expanded == 'basename':
column = '((bytes / 128) / duration)' column_expanded = 'COALESCE(override_filename, basename)'
elif column == 'ratio': elif column_expanded == 'bitrate':
column = '(width / height)' column_expanded = '((bytes / 128) / duration)'
requested_order = (column, direction) elif column_expanded == 'ratio':
final_orderby.append(requested_order) column_expanded = '(width / height)'
final_orderby.append( (column_friendly, column_expanded, direction) )
return final_orderby return final_orderby

View file

@ -168,13 +168,13 @@
<li class="search_builder_orderby_li"> <li class="search_builder_orderby_li">
<select onchange="return orderby_hide_direction_hook(event);"> <select onchange="return orderby_hide_direction_hook(event);">
<option value="created" {{"selected" if selected_column=="created" else ""}}>Creation date</option> <option value="created" {{"selected" if selected_column=="created" else ""}}>Creation date</option>
<option value="area" {{"selected" if selected_column=="(width * height)" else ""}}>Area</option> <option value="area" {{"selected" if selected_column=="area" else ""}}>Area</option>
<option value="width" {{"selected" if selected_column=="width" else ""}}>Width</option> <option value="width" {{"selected" if selected_column=="width" else ""}}>Width</option>
<option value="height" {{"selected" if selected_column=="height" else ""}}>Height</option> <option value="height" {{"selected" if selected_column=="height" else ""}}>Height</option>
<option value="ratio" {{"selected" if selected_column=="(width / height)" else ""}}>Aspect Ratio</option> <option value="ratio" {{"selected" if selected_column=="ratio" else ""}}>Aspect Ratio</option>
<option value="bytes" {{"selected" if selected_column=="bytes" else ""}}>File size</option> <option value="bytes" {{"selected" if selected_column=="bytes" else ""}}>File size</option>
<option value="duration" {{"selected" if selected_column=="duration" else ""}}>Duration</option> <option value="duration" {{"selected" if selected_column=="duration" else ""}}>Duration</option>
<option value="bitrate" {{"selected" if selected_column=="((bytes / 128) / duration)" else ""}}>Bitrate</option> <option value="bitrate" {{"selected" if selected_column=="bitrate" else ""}}>Bitrate</option>
<option value="tagged_at" {{"selected" if selected_column=="tagged_at" else ""}}>Recently tagged</option> <option value="tagged_at" {{"selected" if selected_column=="tagged_at" else ""}}>Recently tagged</option>
<option value="random" {{"selected" if selected_column=="random" else ""}}>Random</option> <option value="random" {{"selected" if selected_column=="random" else ""}}>Random</option>
</select> </select>