solis: re-order endpoints (#32877)
This commit is contained in:
parent
d7abdba261
commit
ea7a20a3f2
|
@ -147,6 +147,70 @@ class Solis(BaseResource):
|
|||
def ping(self, request):
|
||||
return self.check_status()
|
||||
|
||||
@endpoint(name='referential', perm='can_access',
|
||||
pattern=r'^(?P<module>[\w-]+)/(?P<name>[\w-]+)/$',
|
||||
example_pattern='{module}/{name}/',
|
||||
description=_('Get module/name references'),
|
||||
parameters={
|
||||
'module': {'description': _('Referential module: asg, civi, trans'),
|
||||
'example_value': 'trans'},
|
||||
'name': {'description': _('Referential name in this module'),
|
||||
'example_value': 'lieu'},
|
||||
'codePays': {'example_value': '79'},
|
||||
'codeDepartement': {'example_value': '80'},
|
||||
'codeCommune': {'example_value': '21'},
|
||||
'q': {'description': _('Returns only items whose text matches'),
|
||||
'example_value': 'claudel'},
|
||||
'id': {'description': _('Returns only item with this id (code)')},
|
||||
'ignore': {'description': _('Do not return items with this id, '
|
||||
'or multiple ids separated with commas'),
|
||||
'example_value': '9999'},
|
||||
})
|
||||
def referential(self, request, module, name, q=None, id=None, ignore=None, **kwargs):
|
||||
endpoint = 'referentiels/%s/%s' % (module, name)
|
||||
args = [(code, value) for code, value in kwargs.items() if code.startswith('code')]
|
||||
if args:
|
||||
endpoint += '?' + urlencode(args)
|
||||
|
||||
content = self.request(endpoint)
|
||||
|
||||
if (not isinstance(content, dict) or len(content) != 1 or
|
||||
not isinstance(content.values()[0], list)):
|
||||
raise APIError('response is not a dictionnary with only one key '
|
||||
'and whose value is a list', data={'json_content': content})
|
||||
|
||||
items = content.values()[0]
|
||||
|
||||
if not all(isinstance(item, dict) and item.get('code') for item in items):
|
||||
raise APIError('items must be dictionnaries with a "code" key',
|
||||
data={'json_content': content})
|
||||
|
||||
for item in items:
|
||||
item['id'] = item['code']
|
||||
item['text'] = item.get('libelle', item['id'])
|
||||
|
||||
if ignore:
|
||||
ignore_ids = [ignore_id.strip() for ignore_id in ignore.split(',')
|
||||
if ignore_id.strip()]
|
||||
if q:
|
||||
q = simplify(q)
|
||||
|
||||
def condition(item):
|
||||
if id and item['id'] != id:
|
||||
return False
|
||||
if ignore and item['id'] in ignore_ids:
|
||||
return False
|
||||
if q and q not in simplify(item['text']):
|
||||
return False
|
||||
return True
|
||||
items = filter(condition, items)
|
||||
|
||||
return {'data': items}
|
||||
|
||||
#
|
||||
# APA endpoints
|
||||
#
|
||||
|
||||
def apa_token(self, user_id, code):
|
||||
response = self.request('asg/apa/generationJeton', data={
|
||||
'indexIndividu': user_id,
|
||||
|
@ -357,66 +421,6 @@ class Solis(BaseResource):
|
|||
'files_failed_pdf_conversion': files_failed_pdf_conversion
|
||||
}
|
||||
|
||||
@endpoint(name='referential', perm='can_access',
|
||||
pattern=r'^(?P<module>[\w-]+)/(?P<name>[\w-]+)/$',
|
||||
example_pattern='{module}/{name}/',
|
||||
description=_('Get module/name references'),
|
||||
parameters={
|
||||
'module': {'description': _('Referential module: asg, civi, trans'),
|
||||
'example_value': 'trans'},
|
||||
'name': {'description': _('Referential name in this module'),
|
||||
'example_value': 'lieu'},
|
||||
'codePays': {'example_value': '79'},
|
||||
'codeDepartement': {'example_value': '80'},
|
||||
'codeCommune': {'example_value': '21'},
|
||||
'q': {'description': _('Returns only items whose text matches'),
|
||||
'example_value': 'claudel'},
|
||||
'id': {'description': _('Returns only item with this id (code)')},
|
||||
'ignore': {'description': _('Do not return items with this id, '
|
||||
'or multiple ids separated with commas'),
|
||||
'example_value': '9999'},
|
||||
})
|
||||
def referential(self, request, module, name, q=None, id=None, ignore=None, **kwargs):
|
||||
endpoint = 'referentiels/%s/%s' % (module, name)
|
||||
args = [(code, value) for code, value in kwargs.items() if code.startswith('code')]
|
||||
if args:
|
||||
endpoint += '?' + urlencode(args)
|
||||
|
||||
content = self.request(endpoint)
|
||||
|
||||
if (not isinstance(content, dict) or len(content) != 1 or
|
||||
not isinstance(content.values()[0], list)):
|
||||
raise APIError('response is not a dictionnary with only one key '
|
||||
'and whose value is a list', data={'json_content': content})
|
||||
|
||||
items = content.values()[0]
|
||||
|
||||
if not all(isinstance(item, dict) and item.get('code') for item in items):
|
||||
raise APIError('items must be dictionnaries with a "code" key',
|
||||
data={'json_content': content})
|
||||
|
||||
for item in items:
|
||||
item['id'] = item['code']
|
||||
item['text'] = item.get('libelle', item['id'])
|
||||
|
||||
if ignore:
|
||||
ignore_ids = [ignore_id.strip() for ignore_id in ignore.split(',')
|
||||
if ignore_id.strip()]
|
||||
if q:
|
||||
q = simplify(q)
|
||||
|
||||
def condition(item):
|
||||
if id and item['id'] != id:
|
||||
return False
|
||||
if ignore and item['id'] in ignore_ids:
|
||||
return False
|
||||
if q and q not in simplify(item['text']):
|
||||
return False
|
||||
return True
|
||||
items = filter(condition, items)
|
||||
|
||||
return {'data': items}
|
||||
|
||||
|
||||
class SolisAPALink(models.Model):
|
||||
resource = models.ForeignKey(Solis)
|
||||
|
|
Loading…
Reference in New Issue