Example #1
0
def refresh_measurements(request, step_id):
    """View that starts the task to refresh all the quality measurements
    On the dashboard, the user can press a button to call this view/task."""
    step = ChosenExperimentSteps.objects.get(pk=step_id)
    verify_and_get_experiment(request, step.experiment_id)
    task_complete_quality_check.delay(step_id)
    return JsonResponse({'refresh': True})
Example #2
0
def dataschemafield_edit(request, pk, experiment_id):
    experiment = verify_and_get_experiment(request, experiment_id)
    dataschema = DataSchemaField.objects.get(pk=pk)
    constraints = dataschema.constraints
    context = {'schema_id': dataschema.pk, 'experiment_id': experiment.id}
    if request.POST:
        edit_form = DataSchemaFieldForm(request.POST, instance=dataschema)
        constraint_form = DataSchemaConstraintForm(request.POST,
                                                   instance=constraints)
        if edit_form.is_valid() and constraint_form.is_valid():
            constraints.save()
            dataschema.constraint = constraints
            dataschema.save()
            logger.info('edit data schema for %s: %s', experiment, dataschema)
            return redirect(to=experiment.success_url_dict(
                hash='#edit')['schema'])
        else:
            context['form'] = edit_form
            context['edit'] = True
            context['constraint_form'] = constraint_form
            return render(request,
                          'dataschema_manager/dataschemafield_edit.html',
                          context)
    else:
        context['form'] = DataSchemaFieldForm(instance=dataschema)
        context['constraint_form'] = DataSchemaConstraintForm(
            instance=constraints)
        context['edit'] = True
        return render(request, 'dataschema_manager/dataschemafield_edit.html',
                      context)
Example #3
0
 def get_success_url(self):
     if self.kwargs['object_type'] == self.EXPERIMENT_TYPE:
         experiment = verify_and_get_experiment(self.request, self.kwargs['object_id'])
         success_url = experiment.success_url_dict('#edit')['dependencies']
     elif self.kwargs['object_type']  == self.PACKAGE_TYPE:
         success_url = reverse('internalpackage_dashboard', kwargs={'pk': self.kwargs['object_id']})
     return success_url
Example #4
0
def dataschemafield_new(request, experiment_id):
    """Creates new data schema field"""
    experiment = verify_and_get_experiment(request, experiment_id)
    context = {}
    if request.POST:
        edit_form = DataSchemaFieldForm(request.POST)
        constraint_form = DataSchemaConstraintForm(request.POST)
        if edit_form.is_valid() and constraint_form.is_valid():
            with transaction.atomic():
                constraint_form.save()
                edit_form.instance.constraints = constraint_form.instance
                edit_form.save()
                data_schema = experiment.schema
                data_schema.fields.add(edit_form.instance)
                data_schema.save()
            logger.info('new data schema created for %s: %s', experiment,
                        data_schema)
            return redirect(to=experiment.success_url_dict(
                hash='#edit')['schema'])
        else:
            context['form'] = edit_form
            context['constraint_form'] = constraint_form
            context['experiment_id'] = experiment_id
            context['edit'] = False
            logger.info('invalid data schema form for %s: %s', experiment,
                        context)
            return render(request,
                          'dataschema_manager/dataschemafield_edit.html',
                          context)
Example #5
0
def get_experiment_from_request_post(request):
    """Get an experiment from the request object
    Expects object_id present in request.POST
    (code coverage currently only for experiments, so no internalpackages)"""
    assert 'object_id' in request.POST
    experiment_id = request.POST['object_id']
    return verify_and_get_experiment(request, experiment_id)
Example #6
0
def dataschema_write(request, experiment_id):
    """Starts task to update the data schema in the GitHub repository,
    if a user clicked Save changes"""
    experiment = verify_and_get_experiment(request, experiment_id)
    task_write_data_schema.delay(experiment_id)
    send_message(request.user.username, MessageStatus.INFO,
                 'Task started to update data schema...')
    logger.info('started updating schema for: %s', experiment)
    return JsonResponse({'success': True})
Example #7
0
    def get_context_data(self, **kwargs):
        context = super(MeasurementMixin, self).get_context_data(**kwargs)
        experiment = verify_and_get_experiment(self.request, self.kwargs['pk'])

        step = experiment.get_active_step()
        context[
            'measurements'] = self._get_measurement_messages_for_experiment(
                step)
        return context
Example #8
0
def get_package_or_experiment_with_context(context, request, object_type, object_id):
    """Gets package or experiment and adds it to the context object with key object"""
    if object_type == ExperimentPackageTypeMixin.EXPERIMENT_TYPE:
        context['object'] = verify_and_get_experiment(request, object_id)
        return context
    elif object_type == ExperimentPackageTypeMixin.PACKAGE_TYPE:
        context['package'] = InternalPackage.objects.get(id=object_id)
        context['object'] = InternalPackage.objects.get(id=object_id)
        return context
Example #9
0
def get_package_or_experiment(request, object_type, object_id):
    """Gets either a package or an experiment
    :param request: Request object of view
    :param object_type: One of the options from ExperimentPackageTypeMixin
    :param object_id: PK of the object

    :return: Returns package, or returns experiment, for experiment the owner is first checked"""
    if object_type == ExperimentPackageTypeMixin.EXPERIMENT_TYPE:
        return verify_and_get_experiment(request, object_id)
    elif object_type == ExperimentPackageTypeMixin.PACKAGE_TYPE:
        return InternalPackage.objects.get(id=object_id)
Example #10
0
 def get(self, request, experiment_id):
     experiment = verify_and_get_experiment(request, experiment_id)
     context = {}
     data_schema = experiment.schema
     context['data_schema_list'] = data_schema.fields.all()
     context['experiment_id'] = experiment.id
     context['object'] = experiment
     context['object_type'] = experiment.get_object_type()
     context['form'] = DataSchemaFieldForm()
     context['constraint_form'] = DataSchemaConstraintForm()
     context['schema_active'] = True
     logger.info('data schema overview for: %s', experiment)
     return render(request, self.template_name, context)
def internalpackage_install(request, pk):
    """View for installing a package in own project.
    Adds this package to the requirements file of the chosen experiment and starts
    task to update this file in GitHub"""
    internal_package = InternalPackage.objects.get(pk=pk)
    assert 'experiment_id' in request.POST
    experiment_id = request.POST['experiment_id']
    experiment = verify_and_get_experiment(request, experiment_id)
    result = add_internalpackage_to_experiment(internal_package, experiment)
    if result:
        logger.info('%s installed the package %s in experiment %s',
                    request.user, internal_package, experiment)
        messages.add_message(request, messages.SUCCESS,
                             'Added package to your experiment')
        return JsonResponse({'added': True})
    else:
        messages.add_message(request, messages.ERROR,
                             'Could not add package to your experiment')
        return JsonResponse({'added': False})
Example #12
0
 def get(self, request, experiment_id):
     experiment = verify_and_get_experiment(request, experiment_id)
     raw_values, key_values = get_nr_of_commits_last_week(experiment)
     return JsonResponse({'values': raw_values, 'keys': key_values})
Example #13
0
 def get(self, request, object_id):
     self.experiment = verify_and_get_experiment(request, object_id)
     context = {}
     context['object'] = self.experiment
     context['object_id'] = self.experiment.id
     return context
 def get_experiment(self):
     experiment_id = self.kwargs['experiment_id']
     experiment = verify_and_get_experiment(self.request, experiment_id)
     return experiment