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:
filename_tree = None
if orderby:
giveback_orderby = [
'%s-%s' % (column.replace('RANDOM()', 'random'), direction)
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')]
if give_back_parameters:
@ -807,7 +809,7 @@ class PDBPhotoMixin:
'within_directory': within_directory or None,
'limit': limit,
'offset': offset or None,
'orderby': giveback_orderby or None,
'orderby': giveback_orderby,
'yield_albums': yield_albums,
'yield_photos': yield_photos,
}

View file

@ -290,7 +290,10 @@ def normalize_orderby(orderby, warning_bag=None):
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:
orderby = []
@ -344,23 +347,25 @@ def normalize_orderby(orderby, warning_bag=None):
else:
raise exc
if column == 'random':
column = 'RANDOM()'
column_friendly = column
column_expanded = column
elif column == 'area':
column = '(width * height)'
if column_expanded == 'random':
column_expanded = 'RANDOM()'
elif column == 'basename':
column = 'COALESCE(override_filename, basename)'
elif column_expanded == 'area':
column_expanded = '(width * height)'
elif column == 'bitrate':
column = '((bytes / 128) / duration)'
elif column_expanded == 'basename':
column_expanded = 'COALESCE(override_filename, basename)'
elif column == 'ratio':
column = '(width / height)'
elif column_expanded == 'bitrate':
column_expanded = '((bytes / 128) / duration)'
requested_order = (column, direction)
final_orderby.append(requested_order)
elif column_expanded == 'ratio':
column_expanded = '(width / height)'
final_orderby.append( (column_friendly, column_expanded, direction) )
return final_orderby

View file

@ -168,13 +168,13 @@
<li class="search_builder_orderby_li">
<select onchange="return orderby_hide_direction_hook(event);">
<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="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="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="random" {{"selected" if selected_column=="random" else ""}}>Random</option>
</select>