You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import transport
|
|
from io import StringIO
|
|
import cms
|
|
import copy
|
|
import json
|
|
|
|
@cms.Plugin(mimetype='application/json',method='GET')
|
|
def get (**_args) :
|
|
"""
|
|
This function will return the list of labels available
|
|
"""
|
|
transport.registry.load()
|
|
_data = copy.copy(transport.registry.DATA)
|
|
_context = _args['config']['system']['context']
|
|
_labels = []
|
|
for _key in _data :
|
|
|
|
if _key not in ['default','email','version'] :
|
|
print (_key)
|
|
_provider = _data[_key]['provider']
|
|
_name = None
|
|
if 'table' in _data[_key] :
|
|
_name = 'table'
|
|
elif 'collection' in _data[_key] :
|
|
_name = 'collection'
|
|
_table = 'NA' if not _name else _data[_key][_name]
|
|
_plugins = [] if 'plugins' not in _data[_key]else _data[_key]['plugins']
|
|
_icon = f'{_context}/api/disk/read?uri=www/html/_assets/images/{_provider}.png'
|
|
_labels.append({"label":_key,"provider":_provider,'table':_table,'icon':_icon})
|
|
else:
|
|
continue
|
|
return _labels
|
|
|
|
@cms.Plugin(mimetype="application/json",method="POST")
|
|
def add(**_args):
|
|
"""
|
|
adding a label to the registry
|
|
"""
|
|
_request = _args['request']
|
|
_entry = _request.json
|
|
_label = _entry['label']
|
|
del _entry['label']
|
|
f = StringIO(json.dumps(_entry))
|
|
#
|
|
# @TODO: We need to test the parameters and return the response to the client
|
|
#
|
|
transport.registry.set(_label,f)
|
|
|
|
#
|
|
# now we can/should get the rest of the list
|
|
return get(**_args)
|