-
Notifications
You must be signed in to change notification settings - Fork 5
Endpoint de validacion de catalogos #187
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
Open
FScaccheri
wants to merge
10
commits into
master
Choose a base branch
from
176-endpoint-validacion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
816bdc0
Agrego frontend y form con view simple. Agrego archivos estaticos del…
FScaccheri b159038
Agrego validciones para antes y despues del post del form de validacion
FScaccheri 2b9384e
Linter fix
FScaccheri fd34bb3
Fijado de version de django-rq
FScaccheri 635b3f5
Agrego tests para los casos de prueba del validador
FScaccheri 7857011
Clickear en el logo de los templates del validator redirecciona al va…
FScaccheri dad52fc
Cambio assert de un test
FScaccheri 7c8f0e5
Cambio en test
FScaccheri 8cda9a6
Cambio forma de testear mensajes
FScaccheri e7a31fa
Cambio mensaje de error
FScaccheri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import logging | ||
|
|
||
| import requests | ||
| from requests import RequestException | ||
| from django import forms | ||
| from django.core.exceptions import ValidationError | ||
| from pydatajson import DataJson | ||
| from pydatajson.custom_exceptions import NonParseableCatalog | ||
|
|
||
|
|
||
| class ValidatorForm(forms.Form): | ||
| FORMAT_CHOICES = [ | ||
| ('json', 'JSON'), | ||
| ('xlsx', 'XLSX') | ||
| ] | ||
|
|
||
| catalog_url = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'})) | ||
| format = forms.ChoiceField(choices=FORMAT_CHOICES, | ||
| widget=forms.Select(attrs={'class': 'format form-control'})) | ||
|
|
||
| def validate_fields(self): | ||
| cleaned_data = super().clean() | ||
| url = cleaned_data.get('catalog_url') | ||
| catalog_format = cleaned_data.get('format') | ||
|
|
||
| try: | ||
| requests.head(url).raise_for_status() | ||
| except RequestException: | ||
| raise ValidationError("Error descargando el catálogo") | ||
|
|
||
| parse_error_message = "No se pudo parsear el catálogo ingresado" | ||
| try: | ||
| DataJson(url, catalog_format=catalog_format) | ||
| except NonParseableCatalog: | ||
| raise ValidationError(parse_error_message) | ||
| except Exception as e: | ||
| logging.getLogger(__file__).error(e) | ||
| raise ValidationError(parse_error_message) | ||
|
|
||
| def get_error_messages(self): | ||
| catalog_url = self.cleaned_data['catalog_url'] | ||
| catalog_format = self.cleaned_data['format'] | ||
| catalog = DataJson(catalog=catalog_url, catalog_format=catalog_format) | ||
|
|
||
| all_errors = catalog.validate_catalog(only_errors=True) | ||
| error_messages = [] | ||
|
|
||
| catalog_validation = all_errors['error']['catalog'] | ||
| if catalog_validation['errors']: | ||
| error_messages.append("En catálogo {}: {}". format(catalog_validation['title'], | ||
| catalog_validation['errors'])) | ||
|
|
||
| for dataset_validation in all_errors['error']['dataset']: | ||
| for error in dataset_validation['errors']: | ||
| error_messages.append("En dataset {}: {}".format(dataset_validation['title'], | ||
| error['message'])) | ||
|
|
||
| return error_messages | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.