Fix always order by created time

This commit is contained in:
allegroai 2019-09-13 19:08:49 +03:00
parent 289063e345
commit 13dd130c7d
3 changed files with 6 additions and 4 deletions

View File

@ -518,7 +518,7 @@ class Task(IdObjectBase, AccessMixin, SetupUploadMixin):
page=0, page=0,
page_size=10, page_size=10,
order_by='-created', order_by='-created',
only_fields=['id'] only_fields=['id', 'created']
) )
) )
model = get_single_result(entity='model', query=model_name, results=res.response.models, log=self.log) model = get_single_result(entity='model', query=model_name, results=res.response.models, log=self.log)

View File

@ -41,9 +41,11 @@ def get_single_result(entity, query, results, log=None, show_results=10, raise_o
if sort_by_date: if sort_by_date:
# sort results based on timestamp and return the newest one # sort results based on timestamp and return the newest one
if hasattr(results[0], 'last_update'): if hasattr(results[0], 'last_update'):
results = sorted(results, key=lambda x: int(x.last_update.strftime('%s')), reverse=True) results = sorted(results, key=lambda x: int(x.last_update.strftime('%s')
if x.last_update else 0), reverse=True)
elif hasattr(results[0], 'created'): elif hasattr(results[0], 'created'):
results = sorted(results, key=lambda x: int(x.created.strftime('%s')), reverse=True) results = sorted(results, key=lambda x: int(x.created.strftime('%s')
if x.created else 0), reverse=True)
for obj in (o if isinstance(o, dict) else o.to_dict() for o in results[:show_results]): for obj in (o if isinstance(o, dict) else o.to_dict() for o in results[:show_results]):
log.warn('Found {entity} `{obj[name]}` (id={obj[id]})'.format(**locals())) log.warn('Found {entity} `{obj[name]}` (id={obj[id]})'.format(**locals()))

View File

@ -381,7 +381,7 @@ class InputModel(BaseModel):
if Session.check_min_api_version('2.3') else {'tags': ["-" + ARCHIVED_TAG]} if Session.check_min_api_version('2.3') else {'tags': ["-" + ARCHIVED_TAG]}
result = _Model._get_default_session().send(models.GetAllRequest( result = _Model._get_default_session().send(models.GetAllRequest(
uri=[weights_url], uri=[weights_url],
only_fields=["id", "name"], only_fields=["id", "name", "created"],
**extra **extra
)) ))