Removed JSON schema validation, Added support for 'mandataire' and 'pouvoir_mandat', fixed bugs
This commit is contained in:
parent
4eddc1d502
commit
6b4106ae25
|
@ -331,18 +331,18 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
|||
parameters={
|
||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'}
|
||||
},
|
||||
post={'description': _("Create an openADS 'dossier'"),
|
||||
'request_body': {
|
||||
'schema': {
|
||||
'application/json': JSON_SCHEMA_CREATE_DOSSIER_IN
|
||||
}
|
||||
},
|
||||
#~ post={'description': _("Create an openADS 'dossier'"),
|
||||
#~ 'request_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_IN
|
||||
#~ }
|
||||
#~ },
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
}
|
||||
#~ }
|
||||
)
|
||||
def create_dossier(self, request, type_dossier, *args, **kwargs):
|
||||
|
||||
|
@ -350,7 +350,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
|||
json_data = json.loads(request.body)
|
||||
|
||||
# every field key that might contain a file content
|
||||
file_keys = ['cerfa'] + ['plan_cadastral_%s' % i for i in range(1,5)]
|
||||
file_keys = ['cerfa'] + ['plan_cadastral_%s' % i for i in range(1,5)] + ['pouvoir_mandat']
|
||||
|
||||
# detect if there evolutions data to filter them out of logging
|
||||
# TODO replace when wildcard filtering is implement in 'dict_replace_content_by_paths()'
|
||||
|
@ -394,26 +394,45 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
|||
"numero" : normalize(ref[2])
|
||||
})
|
||||
|
||||
prefix = ''
|
||||
if json_data['fields']['proprietaire'] != 'Oui':
|
||||
prefix = 'mandataire_'
|
||||
# setup requerant variable prefix
|
||||
prefixes = {"demandeurs": ''}
|
||||
if normalize(json_data['fields']['proprietaire']) != 'Oui':
|
||||
prefixes["mandataires"] = 'mandataire_'
|
||||
|
||||
demandeur = {
|
||||
"type_personne": 'particulier' if normalize(json_data['fields']['proprietaire_qualite']) == 'Un particulier' else 'personne morale',
|
||||
"typologie" : 'petitionnaire' if normalize(json_data['fields']['proprietaire']) == 'Oui' else 'mandataire',
|
||||
"nom" : normalize(json_data['fields']['%snom' % prefix]),
|
||||
"prenom" : normalize(json_data['fields']['%sprenom' % prefix]),
|
||||
"adresse": {
|
||||
"numero_voie": normalize(json_data['fields']['%snumero_voie' % prefix]),
|
||||
"nom_voie" : normalize(json_data['fields']['%snom_voie' % prefix]),
|
||||
"code_postal": normalize(json_data['fields']['%scode_postal' % prefix]),
|
||||
"localite" : normalize(json_data['fields']['%slocalite' % prefix])
|
||||
# for each type of requerant with associated prefix
|
||||
for key,prefix in prefixes.items():
|
||||
|
||||
# "qualité" of the requerant
|
||||
qualite = normalize(json_data['fields']['%squalite' % prefix])
|
||||
|
||||
# get the requerant informations
|
||||
requerant = {
|
||||
"type_personne": 'particulier' if qualite == 'Un particulier' else 'personne_morale',
|
||||
"typologie" : 'petitionnaire' if key == 'demandeurs' else 'delegataire',
|
||||
"nom" : normalize(json_data['fields']['%snom' % prefix]),
|
||||
"prenom" : normalize(json_data['fields']['%sprenom' % prefix]),
|
||||
"adresse": {
|
||||
"numero_voie": normalize(json_data['fields']['%snumero_voie' % prefix]),
|
||||
"nom_voie" : normalize(json_data['fields']['%snom_voie' % prefix]),
|
||||
"code_postal": normalize(json_data['fields']['%scode_postal' % prefix]),
|
||||
"localite" : normalize(json_data['fields']['%slocalite' % prefix])
|
||||
}
|
||||
}
|
||||
}
|
||||
if '%slieu_dit' % prefix in json_data['fields'] and json_data['fields']['%slieu_dit' % prefix]:
|
||||
demandeur["adresse"]["lieu_dit"] = normalize(json_data['fields']['%slieu_dit' % prefix])
|
||||
|
||||
payload["demandeurs"] = [demandeur]
|
||||
# add fields if the requerant is not an individual
|
||||
if qualite != 'Un particulier':
|
||||
requerant["raison_sociale"] = normalize(json_data['fields']['%sraison_sociale' % prefix])
|
||||
requerant["denomination"] = normalize(json_data['fields']['%sdenomination' % prefix])
|
||||
self.logger.debug("%s %s => '%s', '%s'", requerant['prenom'], requerant['nom'], requerant['raison_sociale'], requerant['denomination'])
|
||||
|
||||
# add optional lieu_dit field
|
||||
if '%slieu_dit' % prefix in json_data['fields'] and json_data['fields']['%slieu_dit' % prefix]:
|
||||
requerant["adresse"]["lieu_dit"] = normalize(json_data['fields']['%slieu_dit' % prefix])
|
||||
|
||||
# add it to the payload
|
||||
payload[key] = [requerant]
|
||||
|
||||
self.logger.debug("Added '%s' to payload: %s %s", key, requerant['prenom'], requerant['nom'])
|
||||
|
||||
# log the payload
|
||||
self.log_json_payload(payload)
|
||||
|
@ -438,8 +457,9 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
|||
self.logger.warning("CERFA content type is '%s' instead of '%s'", content_type, 'application/pdf')
|
||||
if 'filename' in json_data['fields'][k]:
|
||||
filename = json_data['fields'][k]['filename']
|
||||
type_fichier = re.sub(r'_.*$', '', k)[:10]
|
||||
files.append({
|
||||
'type_fichier' : 'CERFA' if k == 'cerfa' else 'plan',
|
||||
'type_fichier' : type_fichier,
|
||||
'orig_filename': filename,
|
||||
'content_type' : content_type,
|
||||
'file_hash' : file_hash,
|
||||
|
|
Reference in New Issue