some semantic variable renaing
This commit is contained in:
parent
89996f929d
commit
eec3734d2f
1 changed files with 24 additions and 24 deletions
|
@ -101,12 +101,12 @@ FILE_SORT_FIELD_NAME = 'name'
|
|||
FILE_SORT_FIELD_DATE = 'date'
|
||||
FILE_SORT_FIELD_PRICE = 'price'
|
||||
|
||||
FILE_SORT_ORDER_ASCENDING = 'asc'
|
||||
FILE_SORT_ORDER_DESCENDING = 'desc'
|
||||
FILE_SORT_ORDERS = [
|
||||
FILE_SORT_ORDER_ASCENDING,
|
||||
FILE_SORT_ORDER_DESCENDING,
|
||||
]
|
||||
FILE_SORT_DIRECTION_ASCENDING = 'asc'
|
||||
FILE_SORT_DIRECTION_DESCENDING = 'desc'
|
||||
FILE_SORT_DIRECTIONS = (
|
||||
FILE_SORT_DIRECTION_ASCENDING,
|
||||
FILE_SORT_DIRECTION_DESCENDING,
|
||||
)
|
||||
|
||||
class IterableContainer(object):
|
||||
def __iter__(self):
|
||||
|
@ -935,13 +935,13 @@ class Daemon(AuthJSONRPCServer):
|
|||
defer.returnValue(lbry_file)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _get_lbry_files(self, return_json=False, full_status=True, sorts=None, **kwargs):
|
||||
def _get_lbry_files(self, return_json=False, full_status=True, sort_by=None, **kwargs):
|
||||
lbry_files = list(self.lbry_file_manager.lbry_files)
|
||||
if kwargs:
|
||||
for search_type, value in iter_lbry_file_search_values(kwargs):
|
||||
lbry_files = [l_f for l_f in lbry_files if l_f.__dict__[search_type] == value]
|
||||
if sorts:
|
||||
lbry_files = self._sort_lbry_files(lbry_files, sorts)
|
||||
if sort_by:
|
||||
lbry_files = self._sort_lbry_files(lbry_files, sort_by)
|
||||
if return_json:
|
||||
file_dicts = []
|
||||
for lbry_file in lbry_files:
|
||||
|
@ -951,15 +951,15 @@ class Daemon(AuthJSONRPCServer):
|
|||
log.debug("Collected %i lbry files", len(lbry_files))
|
||||
defer.returnValue(lbry_files)
|
||||
|
||||
def _sort_lbry_files(self, lbry_files, sorts):
|
||||
for field, order in sorts:
|
||||
reverse = order == FILE_SORT_ORDER_DESCENDING
|
||||
def _sort_lbry_files(self, lbry_files, sort_by):
|
||||
for field, direction in sort_by:
|
||||
is_reverse = direction == FILE_SORT_DIRECTION_DESCENDING
|
||||
if field == FILE_SORT_FIELD_NAME:
|
||||
lbry_files = sorted(lbry_files, key=lambda f: f.file_name, reverse=reverse)
|
||||
lbry_files = sorted(lbry_files, key=lambda f: f.file_name, reverse=is_reverse)
|
||||
elif field == FILE_SORT_FIELD_DATE:
|
||||
lbry_files = sorted(lbry_files, reverse=reverse)
|
||||
lbry_files = sorted(lbry_files, reverse=is_reverse)
|
||||
elif field == FILE_SORT_FIELD_PRICE:
|
||||
lbry_files = sorted(lbry_files, key=lambda f: f.points_paid, reverse=reverse)
|
||||
lbry_files = sorted(lbry_files, key=lambda f: f.points_paid, reverse=is_reverse)
|
||||
else:
|
||||
raise Exception('Unrecognized sort field "{}"'.format(field))
|
||||
return lbry_files
|
||||
|
@ -967,16 +967,16 @@ class Daemon(AuthJSONRPCServer):
|
|||
def _parse_lbry_files_sort(self, sort):
|
||||
"""
|
||||
Given a sort string like 'name, desc' or 'price',
|
||||
parse the string into a tuple of (field, order).
|
||||
Order defaults to ascending.
|
||||
parse the string into a tuple of (field, direction).
|
||||
Direction defaults to ascending.
|
||||
"""
|
||||
|
||||
pieces = sort.rsplit(',', 1)
|
||||
field = pieces[0].strip()
|
||||
order = pieces[1].strip().lower() if len(pieces) > 1 else None
|
||||
if order and order not in FILE_SORT_ORDERS:
|
||||
raise Exception('Sort order must be one of {}'.format(FILE_SORT_ORDERS))
|
||||
return (field, order or FILE_SORT_ORDER_ASCENDING)
|
||||
direction = pieces[1].strip().lower() if len(pieces) > 1 else None
|
||||
if direction and direction not in FILE_SORT_DIRECTIONS:
|
||||
raise Exception('Sort direction must be one of {}'.format(FILE_SORT_DIRECTIONS))
|
||||
return (field, direction or FILE_SORT_DIRECTION_ASCENDING)
|
||||
|
||||
def _get_single_peer_downloader(self):
|
||||
downloader = SinglePeerDownloader()
|
||||
|
@ -1423,7 +1423,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
--full_status : (bool) full status, populate the
|
||||
'message' and 'size' fields
|
||||
--sort=<sort_method> : (str) sort by any of 'name', 'date', or 'price'
|
||||
to specify order append ',asc' or ',desc'
|
||||
to specify direction append ',asc' or ',desc'
|
||||
|
||||
Returns:
|
||||
(list) List of files
|
||||
|
@ -1459,8 +1459,8 @@ class Daemon(AuthJSONRPCServer):
|
|||
]
|
||||
"""
|
||||
|
||||
sorts = [self._parse_lbry_files_sort(s) for s in sort] if sort else None
|
||||
result = yield self._get_lbry_files(return_json=True, sorts=sorts, **kwargs)
|
||||
sort_by = [self._parse_lbry_files_sort(s) for s in sort] if sort else None
|
||||
result = yield self._get_lbry_files(return_json=True, sort_by=sort_by, **kwargs)
|
||||
response = yield self._render_response(result)
|
||||
defer.returnValue(response)
|
||||
|
||||
|
|
Loading…
Reference in a new issue