Skip to content
Snippets Groups Projects
forms.py 2.16 KiB
Newer Older
Fanna Lautenbach's avatar
Fanna Lautenbach committed
from .models import WorkSpecification, DataProductFilter

Nico Vermaas's avatar
Nico Vermaas committed
from django.forms import ModelForm


class WorkSpecificationForm(ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
Fanna Lautenbach's avatar
Fanna Lautenbach committed
        self.fields['predecessor_specification'].required = False
        self.fields['filters'].required = False

    def _extract_filters(self):
        filter_names = [filter_name[0] for filter_name in DataProductFilter.objects.all().values_list('field')]
        filters = {}
        for filter_name in filter_names:
Fanna Lautenbach's avatar
Fanna Lautenbach committed
            if filter_name in self.data and self.data[filter_name] != "":
Fanna Lautenbach's avatar
Fanna Lautenbach committed
                filters[filter_name] = self.data[filter_name]
        return filters

    def clean(self):
        self.cleaned_data = super().clean()
        self.cleaned_data["filters"] = self._extract_filters()
        return self.cleaned_data

Nico Vermaas's avatar
Nico Vermaas committed
    class Meta:
        model = WorkSpecification
Fanna Lautenbach's avatar
Fanna Lautenbach committed
        fields = ['filters', 'selected_workflow', 'selected_workflow_tag', 'processing_site',
                  'predecessor_specification', 'batch_size',
                  'is_auto_submit']
Nico Vermaas's avatar
Nico Vermaas committed
        labels = {
            'selected_workflow': 'Selected workflow',
Fanna Lautenbach's avatar
Fanna Lautenbach committed
            'selected_workflow_tag': 'Workflow tag',
Nico Vermaas's avatar
Nico Vermaas committed
            'processing_site': 'Processing Site (ATDB)',
Fanna Lautenbach's avatar
Fanna Lautenbach committed
            'predecessor_specification': 'Predecessor',
            'batch_size': 'Files per task',
            'is_auto_submit': 'Auto submit'
Fanna Lautenbach's avatar
Fanna Lautenbach committed
        help_texts = {'selected_workflow': "The pipeline to run on the processing site.",
                      'selected_workflow_tag': "The pipeline's tag as specified in ATDB.",
                      'processing_site': "The ATDB processing site to run a specific workflow in.",
                      'predecessor_specification': "The related predecessor of the current work specification.",
                      'batch_size': "The number of files every task generated by this work specification should have. Example: 10 files in total can be split into 5 tasks of 2 files.",
                      'is_auto_submit': "By checking this box, the work specification will be directly sent to the processing site and thus does not need inspection."
                      }