Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Feb 20, 2017
2 parents 55431ba + e034ecf commit 8fb504f
Showing 1 changed file with 60 additions and 51 deletions.
111 changes: 60 additions & 51 deletions apptax/taxonomie/routesbibnoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ def getOne_bibtaxonsInfo(cd_nom):
@json_resp
def getOneSimple_bibtaxons(id_nom):
bibTaxon =db.session.query(BibNoms).filter_by(id_nom=id_nom).first()

obj = bibTaxon.as_dict()

#Ajout des listes
obj['listes'] = []
for liste in bibTaxon.listes :
o = dict(liste.as_dict().items())
o.update(dict(liste.bib_liste.as_dict().items()))
obj['listes'].append(o)

return obj


Expand Down Expand Up @@ -143,61 +149,64 @@ def getOneFull_bibtaxons(id_nom):
@adresses.route('/<int:id_nom>', methods=['POST', 'PUT'])
@fnauth.check_auth(3, True)
def insertUpdate_bibtaxons(id_nom=None, id_role=None):
try:
data = request.get_json(silent=True)
if id_nom:
bibTaxon =db.session.query(BibNoms).filter_by(id_nom=id_nom).first()
if 'nom_francais' in data :
bibTaxon.nom_francais = data['nom_francais']
action = 'UPDATE'
message = "Taxon mis à jour"
else :
bibTaxon = BibNoms(
cd_nom = data['cd_nom'],
cd_ref = data['cd_ref'],
nom_francais =data['nom_francais'] if 'nom_francais' in data else None
)
action = 'INSERT'
message = "Taxon ajouté"
db.session.add(bibTaxon)
db.session.commit()

data = request.get_json(silent=True)
if id_nom:
bibTaxon =db.session.query(BibNoms).filter_by(id_nom=id_nom).first()
if 'nom_francais' in data :
bibTaxon.nom_francais = data['nom_francais']
action = 'UPDATE'
message = "Taxon mis à jour"
else :
bibTaxon = BibNoms(
cd_nom = data['cd_nom'],
cd_ref = data['cd_ref'],
nom_francais =data['nom_francais'] if 'nom_francais' in data else None
)
action = 'INSERT'
message = "Taxon ajouté"
db.session.add(bibTaxon)
db.session.commit()

id_nom = bibTaxon.id_nom
id_nom = bibTaxon.id_nom

####--------------Traitement des attibuts-----------------
#Suppression des attributs existants
for bibTaxonAtt in bibTaxon.attributs:
db.session.delete(bibTaxonAtt)
db.session.commit()

if 'attributs_values' in data :
for att in data['attributs_values']:
if data['attributs_values'][att] != '' :
attVal = CorTaxonAttribut(
id_attribut = att,
cd_ref = bibTaxon.cd_ref,
valeur_attribut =data['attributs_values'][att]
)
db.session.add(attVal)
####--------------Traitement des attibuts-----------------
#Suppression des attributs existants
for bibTaxonAtt in bibTaxon.attributs:
db.session.delete(bibTaxonAtt)
db.session.commit()

####--------------Traitement des listes-----------------
#Suppression des listes existantes
for bibTaxonLst in bibTaxon.listes:
db.session.delete(bibTaxonLst)
db.session.commit()
if 'listes' in data :
for lst in data['listes']:
listTax = CorNomListe (
id_liste = lst['id_liste'],
id_nom = id_nom
)
db.session.add(listTax)
if 'attributs_values' in data :
for att in data['attributs_values']:
if data['attributs_values'][att] != '' :
attVal = CorTaxonAttribut(
id_attribut = att,
cd_ref = bibTaxon.cd_ref,
valeur_attribut =data['attributs_values'][att]
)
db.session.add(attVal)
db.session.commit()

####--------------Traitement des listes-----------------
#Suppression des listes existantes
for bibTaxonLst in bibTaxon.listes:
db.session.delete(bibTaxonLst)
db.session.commit()

##Log
logmanager.log_action(id_role, 'bib_nom', id_nom, repr(bibTaxon),action,message)
return json.dumps({'success':True, 'id_nom':id_nom}), 200, {'ContentType':'application/json'}
if 'listes' in data :
for lst in data['listes']:
listTax = CorNomListe (
id_liste = lst['id_liste'],
id_nom = id_nom
)
db.session.add(listTax)
db.session.commit()

##Log
logmanager.log_action(id_role, 'bib_nom', id_nom, repr(bibTaxon),action,message)
return json.dumps({'success':True, 'id_nom':id_nom}), 200, {'ContentType':'application/json'}
except Exception as e:
db.session.rollback()
return json.dumps({'success':True, 'message':e}), 500, {'ContentType':'application/json'}

@adresses.route('/<int:id_nom>', methods=['DELETE'])
@fnauth.check_auth(6, True)
Expand Down

0 comments on commit 8fb504f

Please sign in to comment.