Skip to content

Commit

Permalink
Validation is finished view (#968)
Browse files Browse the repository at this point in the history
* validation status api view

* Changed to token authentication

* Added api url.

* fixed url
  • Loading branch information
HuwHaigh97 authored Nov 28, 2024
1 parent ea347e4 commit d46d249
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
download_comparison_table, get_comparison_metrics, get_spatial_extent
from api.views.user_view import signup_post, user_update, user_delete
from api.views.validation_run_view import published_results, my_results, validation_run_by_id, \
custom_tracked_validation_runs, get_validations_for_comparison, get_copied_validations
custom_tracked_validation_runs, get_validations_for_comparison, get_copied_validations, is_validation_finished
from api.views.dataset_configuration_view import dataset_configuration, dataset_configuration_by_validation
from api.views.global_params_view import global_params
from api.views.modify_validation_view import *
Expand Down Expand Up @@ -70,6 +70,7 @@
name='Dataset_variable_by_dataset'),
path('published-results', published_results, name='Published results'),
re_path(r'^validation-runs/(?P<id>.+)$', validation_run_by_id, name='Validation run by id'),
re_path(r'^is-validation-finished/(?P<id>.+)$', is_validation_finished, name='Is validation finished'),
path('dataset-configuration', dataset_configuration, name='Configuration'),
re_path(r'^dataset-configuration/(?P<validation_id>.+)$', dataset_configuration_by_validation,
name='Configuration'),
Expand Down
16 changes: 14 additions & 2 deletions api/views/validation_run_view.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.db.models import Q, ExpressionWrapper, F, BooleanField

from django.http import JsonResponse
from django.shortcuts import get_object_or_404

from rest_framework import status
from rest_framework.decorators import api_view, permission_classes
from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.serializers import ModelSerializer
from rest_framework.authentication import TokenAuthentication

from api.views.auxiliary_functions import get_fields_as_list
from validator.models import ValidationRun, CopiedValidations
Expand Down Expand Up @@ -155,6 +156,17 @@ def get_copied_validations(request, **kwargs):
return JsonResponse(serializer.data, status=status.HTTP_200_OK)


@api_view(['GET'])
@authentication_classes([TokenAuthentication])
def is_validation_finished(request, **kwargs):

val_run = get_object_or_404(ValidationRun, pk=kwargs['id'])
if not val_run:
return JsonResponse(status=status.HTTP_404_NOT_FOUND)

ifFinished = (val_run.progress == 100 and val_run.end_time is not None)
return JsonResponse({'validation_complete': ifFinished}, status=status.HTTP_200_OK)

class ValidationRunSerializer(ModelSerializer):
class Meta:
model = ValidationRun
Expand Down

0 comments on commit d46d249

Please sign in to comment.