add get-data endpoint
This commit is contained in:
parent
d709c5bbf5
commit
ac9ca6d7da
|
@ -367,6 +367,38 @@ query getDossiers($demarcheNumber: Int!, $createdSince: ISO8601DateTime, $first:
|
|||
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
|
||||
return response
|
||||
|
||||
@endpoint(
|
||||
methods=['get'], perm='can_access', name='get-data',
|
||||
description=_('Get data by sequence or siren')
|
||||
)
|
||||
def get_data(self, request, sequence=None, siren=None):
|
||||
|
||||
def build_result(entreprise):
|
||||
return {
|
||||
'data': {attr: getattr(entreprise, attr) for attr in COLUMNS_KEYNAMES}
|
||||
}
|
||||
|
||||
if sequence is None and siren is None:
|
||||
raise APIError('Need sequence or siren')
|
||||
|
||||
if sequence:
|
||||
try:
|
||||
entreprise = Entreprise.objects.get(resource=self, sequence=sequence)
|
||||
return build_result(entreprise)
|
||||
except Entreprise.DoesNotExist:
|
||||
pass
|
||||
|
||||
if siren:
|
||||
try:
|
||||
entreprise = Entreprise.objects.get(resource=self, siren=siren)
|
||||
return build_result(entreprise)
|
||||
except Entreprise.DoesNotExist:
|
||||
pass
|
||||
|
||||
return {
|
||||
'data': {}
|
||||
}
|
||||
|
||||
|
||||
class Entreprise(models.Model):
|
||||
|
||||
|
|
Reference in New Issue