Projet

Général

Profil

0003-api_entreprise-do-not-use-Publik-json-format-when-no.patch

Emmanuel Cazenave, 25 octobre 2022 18:13

Télécharger (3,09 ko)

Voir les différences:

Subject: [PATCH 3/7] api_entreprise: do not use Publik json format when not
 needed (#70610)

 passerelle/apps/api_entreprise/models.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
passerelle/apps/api_entreprise/models.py
91 91
    class Meta:
92 92
        verbose_name = _('API Entreprise')
93 93

  
94
    def get(self, path, **kwargs):
94
    def get(self, path, raw=False, **kwargs):
95 95
        params = {'token': self.token}
96 96
        for param in ('context', 'object'):
97 97
            if not kwargs.get(param):
......
132 132
                },
133 133
            )
134 134
        normalize_results(data)
135
        if raw:
136
            return data
135 137
        return {
136 138
            'err': 0,
137 139
            'data': data,
......
194 196
    )
195 197
    def documents_associations(self, request, association_id, **kwargs):
196 198
        data = []
197
        resp = self.get('v2/documents_associations/%s/' % association_id, **kwargs)
198
        for item in resp['data'].get('documents', []):
199
        resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
200
        for item in resp.get('documents', []):
199 201
            # ignore documents with no type
200 202
            if not item.get('type'):
201 203
                continue
......
268 270
    )
269 271
    def get_last_document_of_type(self, request, association_id, document_type, **kwargs):
270 272
        document = None
271
        resp = self.get('v2/documents_associations/%s/' % association_id, **kwargs)
272
        documents = [item for item in resp['data'].get('documents', []) if item.get('type') == document_type]
273
        resp = self.get('v2/documents_associations/%s/' % association_id, raw=True, **kwargs)
274
        documents = [item for item in resp.get('documents', []) if item.get('type') == document_type]
273 275
        if documents:
274 276
            documents.sort(key=lambda doc: doc['timestamp'])
275 277
            document = documents[-1]
......
436 438
    ):
437 439
        entreprise = self.get(
438 440
            'v2/entreprises/%s/' % siren,
441
            raw=True,
439 442
            **kwargs,
440 443
        )
441 444
        methods = {
......
444 447
        }
445 448
        if method not in methods:
446 449
            return {'err': 1, 'err_desc': 'method %s not implemented' % method}
447
        for mandataire in entreprise['data'].get('entreprise', {}).get('mandataires_sociaux', []):
450
        for mandataire in entreprise.get('entreprise', {}).get('mandataires_sociaux', []):
448 451
            if methods[method](mandataire, first_name, last_name, birthdate):
449 452
                return {'err': 0, 'data': mandataire}
450 453
        return {'err': 0, 'data': {}}
451
-