mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Add app list sort
This commit is contained in:
parent
d26c545293
commit
8f2ce51ccb
3 changed files with 34 additions and 14 deletions
|
@ -218,12 +218,6 @@ app:
|
|||
list:
|
||||
action_help: List apps
|
||||
arguments:
|
||||
--fields:
|
||||
help: fields to fetch
|
||||
nargs: "+"
|
||||
-f:
|
||||
full: --filter
|
||||
help: LDAP filter used to search
|
||||
-l:
|
||||
full: --limit
|
||||
help: Maximum number of app fetched
|
||||
|
|
|
@ -35,17 +35,43 @@ def app_updatelist(url=None):
|
|||
win_msg(_("List updated successfully"))
|
||||
|
||||
|
||||
def app_list(filter=None, fields=None, offset=None, limit=None):
|
||||
def app_list(offset=None, limit=None):
|
||||
"""
|
||||
List available applications
|
||||
|
||||
Keyword arguments:
|
||||
offset -- App to begin with
|
||||
limit -- Number of apps to list
|
||||
|
||||
Returns:
|
||||
Dict of apps
|
||||
|
||||
"""
|
||||
|
||||
# TODO: List installed applications
|
||||
# TODO: Implement fields to fetch
|
||||
|
||||
if offset: offset = int(offset)
|
||||
else: offset = 0
|
||||
if limit: limit = int(limit)
|
||||
else: limit = 1000
|
||||
with open('/var/cache/yunohost/apps/list.json') as json_list:
|
||||
app_dict = json.loads(str(json_list.read()))
|
||||
|
||||
list_dict = {}
|
||||
|
||||
for app_id, app_info in app_dict.items():
|
||||
list_dict[app_id] = {
|
||||
'Name': app_info['manifest']['name'],
|
||||
'Version': app_info['manifest']['version'],
|
||||
'Description': app_info['manifest']['description']
|
||||
}
|
||||
if len(app_dict) > (0 + offset) and limit > 0:
|
||||
i = 0 + offset
|
||||
sorted_app_dict = {}
|
||||
for sorted_keys in sorted(app_dict.keys())[i:]:
|
||||
if i <= limit:
|
||||
sorted_app_dict[sorted_keys] = app_dict[sorted_keys]
|
||||
i += 1
|
||||
for app_id, app_info in sorted_app_dict.items():
|
||||
list_dict[app_id] = {
|
||||
'Name': app_info['manifest']['name'],
|
||||
'Version': app_info['manifest']['version'],
|
||||
'Description': app_info['manifest']['description']
|
||||
}
|
||||
|
||||
return list_dict
|
||||
|
|
|
@ -46,7 +46,7 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
|
|||
if result and len(result) > (0 + offset) and limit > 0:
|
||||
i = 0 + offset
|
||||
for user in result[i:]:
|
||||
if i < limit:
|
||||
if i <= limit:
|
||||
entry = {
|
||||
'Username': user['uid'],
|
||||
'Fullname': user['cn'],
|
||||
|
|
Loading…
Add table
Reference in a new issue