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={
|
parameters={
|
||||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'}
|
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'}
|
||||||
},
|
},
|
||||||
post={'description': _("Create an openADS 'dossier'"),
|
#~ post={'description': _("Create an openADS 'dossier'"),
|
||||||
'request_body': {
|
#~ 'request_body': {
|
||||||
'schema': {
|
#~ 'schema': {
|
||||||
'application/json': JSON_SCHEMA_CREATE_DOSSIER_IN
|
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_IN
|
||||||
}
|
#~ }
|
||||||
},
|
#~ },
|
||||||
#~ 'response_body': {
|
#~ 'response_body': {
|
||||||
#~ 'schema': {
|
#~ 'schema': {
|
||||||
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_OUT
|
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_OUT
|
||||||
#~ }
|
#~ }
|
||||||
#~ }
|
#~ }
|
||||||
}
|
#~ }
|
||||||
)
|
)
|
||||||
def create_dossier(self, request, type_dossier, *args, **kwargs):
|
def create_dossier(self, request, type_dossier, *args, **kwargs):
|
||||||
|
|
||||||
|
@ -350,7 +350,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
||||||
json_data = json.loads(request.body)
|
json_data = json.loads(request.body)
|
||||||
|
|
||||||
# every field key that might contain a file content
|
# 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
|
# detect if there evolutions data to filter them out of logging
|
||||||
# TODO replace when wildcard filtering is implement in 'dict_replace_content_by_paths()'
|
# 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])
|
"numero" : normalize(ref[2])
|
||||||
})
|
})
|
||||||
|
|
||||||
prefix = ''
|
# setup requerant variable prefix
|
||||||
if json_data['fields']['proprietaire'] != 'Oui':
|
prefixes = {"demandeurs": ''}
|
||||||
prefix = 'mandataire_'
|
if normalize(json_data['fields']['proprietaire']) != 'Oui':
|
||||||
|
prefixes["mandataires"] = 'mandataire_'
|
||||||
|
|
||||||
demandeur = {
|
# for each type of requerant with associated prefix
|
||||||
"type_personne": 'particulier' if normalize(json_data['fields']['proprietaire_qualite']) == 'Un particulier' else 'personne morale',
|
for key,prefix in prefixes.items():
|
||||||
"typologie" : 'petitionnaire' if normalize(json_data['fields']['proprietaire']) == 'Oui' else 'mandataire',
|
|
||||||
"nom" : normalize(json_data['fields']['%snom' % prefix]),
|
# "qualité" of the requerant
|
||||||
"prenom" : normalize(json_data['fields']['%sprenom' % prefix]),
|
qualite = normalize(json_data['fields']['%squalite' % prefix])
|
||||||
"adresse": {
|
|
||||||
"numero_voie": normalize(json_data['fields']['%snumero_voie' % prefix]),
|
# get the requerant informations
|
||||||
"nom_voie" : normalize(json_data['fields']['%snom_voie' % prefix]),
|
requerant = {
|
||||||
"code_postal": normalize(json_data['fields']['%scode_postal' % prefix]),
|
"type_personne": 'particulier' if qualite == 'Un particulier' else 'personne_morale',
|
||||||
"localite" : normalize(json_data['fields']['%slocalite' % prefix])
|
"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
|
# log the payload
|
||||||
self.log_json_payload(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')
|
self.logger.warning("CERFA content type is '%s' instead of '%s'", content_type, 'application/pdf')
|
||||||
if 'filename' in json_data['fields'][k]:
|
if 'filename' in json_data['fields'][k]:
|
||||||
filename = json_data['fields'][k]['filename']
|
filename = json_data['fields'][k]['filename']
|
||||||
|
type_fichier = re.sub(r'_.*$', '', k)[:10]
|
||||||
files.append({
|
files.append({
|
||||||
'type_fichier' : 'CERFA' if k == 'cerfa' else 'plan',
|
'type_fichier' : type_fichier,
|
||||||
'orig_filename': filename,
|
'orig_filename': filename,
|
||||||
'content_type' : content_type,
|
'content_type' : content_type,
|
||||||
'file_hash' : file_hash,
|
'file_hash' : file_hash,
|
||||||
|
|
Reference in New Issue