def insert_ecriture(db): """ Create an ecriture """ entity = App.check_data(Ecriture, request.body.readline()) if entity: ecriture = Ecriture() for column, value in entity.iteritems(): if column == 'date': ecriture.date = datetime.strptime(value, "%Y/%m/%d") #else: # setattr(ecriture, column, value) elif column == 'nom': ecriture.nom = value elif column == 'type': ecriture.type = value elif column == 'valide': ecriture.valide = value elif column == 'compte_id': ecriture.compte_id = value elif column == 'nom_id': ecriture.nom_id = value try: db.add(ecriture) db.commit() except IntegrityError as ex: print ex abort(404, ex.args) montant = Montant() for column, value in entity.iteritems(): if column == 'montant': montant.montant = int(round(locale.atof(value)*100,2)) elif column == 'description': montant.description = value elif column == 'categorie_id': montant.categorie_id = value try: ecriture.montant.append(montant) db.commit() except IntegrityError as ex: print ex abort(404, ex.args) response.status = 201 response.headers["Location"] = "/ecriture/%s/" % (ecriture.id,) ecriture = loads(list_ecriture(db, ecriture.id)) return ecriture[0]