-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Validata): Import achats: ajout d'appels à Validata et renvoyer les erreurs #4949
Changes from all commits
10baf99
3f54c89
51a2766
81f944a
854a2e2
48a3ad6
1560e7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
siret;description;fournisseur;date;prix_ht;famille_produits;caracteristiques;definition_local | ||
82399356058716;"Pommes vertes"; Le bon traiteur;2022-05-02; 90.11; PRODUITS_LAITIERS;"BIO, LOCAL"; DEPARTMENT | ||
82399356058716;"Pommes vertes"; Le bon traiteur;2022-05-02;90.11; PRODUITS_LAITIERS;"BIO, LOCAL"; DEPARTMENT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import requests | ||
|
||
|
||
def validate_file_against_schema(file, schema_url): | ||
# Reset the file pointer to the beginning | ||
file.seek(0) | ||
response = requests.post( | ||
"https://api.validata.etalab.studio/validate", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. à noter que ca fait des appels API à chaque lancement de tests CI 👀 |
||
files={ | ||
"file": ("file.csv", file.read(), file.content_type), | ||
}, | ||
data={"schema": schema_url, "header_case": True}, | ||
) | ||
return response.json()["report"] | ||
|
||
|
||
def process_errors(report): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question à trancher : est-ce qu'on pre-process les erreurs Validata ici (dans le backend), ou coté frontend ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Côté front +1 ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes go pour le front ! du coup je renvoi un maximum d'infos dans l'objet |
||
errors = [] | ||
for error in report["tasks"][0]["errors"]: | ||
errors.append( | ||
{ | ||
# cells, description, fieldNumber, name, note, rowNumber, tags, type | ||
"row": error["rowPosition"], | ||
"column": error["fieldPosition"], | ||
"field": error["fieldName"], | ||
"cell": error["cell"], | ||
"title": error["title"], # Cellule vide, Format incorrect, Format de date incorrect | ||
"message": error["message"], | ||
"code": error["code"], | ||
"status": 400, | ||
} | ||
) | ||
return errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On peut aussi en profiter pour refactor la fonction validate en passant le fichier directement
voir code compl'alim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dans ton exemple le schema est aussi une url il me semble ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui pardon, j'ai confondu avec le fichier