コード例 #1
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class SharepointPipelineCreateForm(BasePipelineCreateForm):
    pipeline_type = PipelineType.SHAREPOINT
    site_name = GOVUKDesignSystemCharField(
        label="The site name that the sharepoint list is published under",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        error_messages={"required": "Enter a valid site name."},
    )
    list_name = GOVUKDesignSystemCharField(
        label="The name of the sharepoint list",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        error_messages={"required": "Enter a valid list name."},
    )

    class Meta:
        model = Pipeline
        fields = ["table_name", "site_name", "list_name", "type"]

    def save(self, commit=True):
        pipeline = super().save(commit=False)
        pipeline.config = {
            "site_name": self.cleaned_data["site_name"],
            "list_name": self.cleaned_data["list_name"],
        }
        if commit:
            pipeline.save()
        return pipeline
コード例 #2
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class BasePipelineCreateForm(GOVUKDesignSystemModelForm):
    pipeline_type = None
    type = ChoiceField(
        choices=PipelineType.choices,
        widget=widgets.HiddenInput(),
    )
    table_name = GOVUKDesignSystemCharField(
        label="Schema and table name the pipeline ingests into",
        help_text="This cannot be changed later",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        error_messages={"required": "Enter a table name."},
        validators=(
            RegexValidator(
                message=
                "Table name must be in the format <schema>.<table name>",
                regex=r"^[a-zA-Z_][a-zA-Z0-9_]*.[a-zA-Z_][a-zA-Z0-9_]*$",
            ),
            validate_schema_and_table,
        ),
    )

    class Meta:
        model = Pipeline
        fields = ["table_name"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.initial["type"] = self.pipeline_type.value
コード例 #3
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class TechnicalSupportForm(GOVUKDesignSystemForm):
    email = forms.EmailField(widget=forms.HiddenInput())
    what_were_you_doing = GOVUKDesignSystemCharField(
        required=False,
        label="What were you trying to do?",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
    )
    what_happened = GOVUKDesignSystemTextareaField(
        required=False,
        label="What happened?",
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            attrs={"rows": 5},
        ),
    )
    what_should_have_happened = GOVUKDesignSystemTextareaField(
        required=False,
        label="What should have happened?",
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            attrs={"rows": 5},
        ),
    )

    def clean(self):
        cleaned = super().clean()
        if (not cleaned["what_were_you_doing"] and not cleaned["what_happened"]
                and not cleaned["what_should_have_happened"]):
            raise forms.ValidationError(
                "Please add some detail to the support request")
コード例 #4
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class ToolsAccessRequestFormPart3(GOVUKDesignSystemModelForm):
    class Meta:
        model = AccessRequest
        fields = ["line_manager_email_address", "reason_for_spss_and_stata"]

    line_manager_email_address = GOVUKDesignSystemCharField(
        label="What is your line manager's email address?",
        help_text=
        "We will use this to email your line manager to ask for approval.",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        error_messages={
            "required": "You must provide your line manager's email address."
        },
    )

    reason_for_spss_and_stata = GOVUKDesignSystemTextareaField(
        label="What is your reason for needing SPSS and Stata?",
        help_text=
        "We're asking these questions to give you access to SPSS and Stata tools.",
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold",
            attrs={"rows": 5},
        ),
        error_messages={
            "required": "Enter a reason for needing SPSS and STATA."
        },
    )
コード例 #5
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class SharepointPipelineEditForm(SharepointPipelineCreateForm):
    table_name = GOVUKDesignSystemCharField(
        label="Schema and table name the pipeline ingests into",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        disabled=True,
    )
コード例 #6
0
class CreateTableForm(GOVUKDesignSystemForm):
    path = forms.CharField(required=True, widget=forms.HiddenInput())
    schema = forms.CharField(required=True, widget=forms.HiddenInput())
    table_name = GOVUKDesignSystemCharField(
        label="How do you want to name your table?",
        help_text="This will be the name you will see your table with, in your personal database schema.",
        required=True,
        widget=GOVUKDesignSystemTextWidget(label_size="xl", label_is_heading=True),
        validators=[
            RegexValidator(
                regex=r"^[a-zA-Z][a-zA-Z0-9_]*$",
                message="Table names can contain only letters, numbers and underscores",
                code="invalid-table-name",
            ),
            MaxLengthValidator(
                42, message="Table names must be no longer than 42 characters long"
            ),
        ],
    )
    force_overwrite = forms.BooleanField(required=False, widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user")
        super().__init__(*args, **kwargs)
        if self.initial.get("force_overwrite"):
            self.fields["table_name"].widget = forms.HiddenInput()

    def clean_path(self):
        path = self.cleaned_data["path"]
        client = get_s3_client()

        if not path.startswith(get_s3_prefix(str(self.user.profile.sso_id))):
            raise ValidationError("You don't have permission to access this file")

        if not path.endswith(".csv"):
            raise ValidationError("Invalid file type. Only CSV files are currently supported")

        try:
            client.head_object(Bucket=settings.NOTEBOOKS_BUCKET, Key=path)
        except ClientError:
            # pylint: disable=raise-missing-from
            raise ValidationError("This file does not exist in S3")

        return path
コード例 #7
0
ファイル: forms.py プロジェクト: uktrade/data-workspace
class DatasetAccessRequestForm(GOVUKDesignSystemModelForm):
    class Meta:
        model = AccessRequest
        fields = ["id", "contact_email", "reason_for_access"]

    id = forms.IntegerField(widget=forms.HiddenInput, required=False)
    contact_email = GOVUKDesignSystemCharField(
        label="Contact email",
        widget=GOVUKDesignSystemTextWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold"),
        error_messages={
            "required": "You must provide your contact email address."
        },
    )

    reason_for_access = GOVUKDesignSystemTextareaField(
        label="Why do you need this data?",
        help_html=render_to_string(
            "request_access/reason-for-access-hint.html"),
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            extra_label_classes="govuk-!-font-weight-bold",
            attrs={"rows": 5},
        ),
        error_messages={
            "required": "Enter a reason for requesting this data."
        },
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        initial_email = self.initial.get("contact_email")
        if initial_email:
            self.fields[
                "contact_email"].help_text = f"You are logged in as {initial_email}"
            self.fields["contact_email"].widget.custom_context[
                "help_text"] = f"You are logged in as {initial_email}"
コード例 #8
0
class ShareQueryForm(GOVUKDesignSystemForm):
    to_user = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Who would you like to share the query with?",
        help_text="Recipient's email",
        queryset=get_user_model().objects.all(),
        to_field_name="email",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=True,
        error_messages={
            "invalid_email":
            "Enter the email address in the correct format, for example [email protected]",
            "invalid_choice":
            "The user you are sharing with must have a DIT staff SSO account",
        },
    )
    message = GOVUKDesignSystemTextareaField(
        label="Message",
        required=True,
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            attrs={"rows": 20},
        ),
    )
    query = CharField(required=True, widget=HiddenInput())
    copy_sender = GOVUKDesignSystemBooleanField(
        label="Send me a copy of the email",
        required=False,
    )

    def clean(self):
        cleaned_data = super().clean()
        if len(cleaned_data["query"]) > 1950:
            raise ValidationError(
                f"The character length of your query ({len(cleaned_data['query'])} characters), "
                "is longer than the current shared query length limit (1950 characters).",
                code="SQLTooLong",
            )
        return cleaned_data
コード例 #9
0
class VisualisationsUICatalogueItemForm(GOVUKDesignSystemModelForm):
    short_description = GOVUKDesignSystemCharField(
        label="Short description",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        error_messages={"required": "The visualisation must have a summary"},
    )

    enquiries_contact = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Enquiries contact",
        queryset=get_user_model().objects.all(),
        to_field_name="email",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the enquiries contact",
            "invalid_choice":
            "The enquiries contact must have previously visited Data Workspace",
        },
    )
    secondary_enquiries_contact = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Secondary enquiries contact",
        queryset=get_user_model().objects.all(),
        to_field_name="email",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the secondary enquiries contact",
            "invalid_choice":
            "The secondary enquiries contact must have previously visited Data Workspace",
        },
    )
    information_asset_manager = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Information asset manager",
        queryset=get_user_model().objects.all(),
        to_field_name="email",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the information asset manager",
            "invalid_choice":
            "The information asset manager must have previously visited Data Workspace",
        },
    )
    information_asset_owner = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Information asset owner",
        queryset=get_user_model().objects.all(),
        to_field_name="email",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the information asset owner",
            "invalid_choice":
            "The information asset owner must have previously visited Data Workspace",
        },
    )
    licence = GOVUKDesignSystemCharField(
        label="Licence",
        required=False,
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
    )
    retention_policy = GOVUKDesignSystemCharField(
        label="Retention policy",
        required=False,
        widget=GOVUKDesignSystemTextareaWidget(label_is_heading=False),
    )
    personal_data = GOVUKDesignSystemCharField(
        label="Personal data",
        required=False,
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
    )
    restrictions_on_usage = GOVUKDesignSystemCharField(
        label="Restrictions on usage",
        required=False,
        widget=GOVUKDesignSystemTextareaWidget(label_is_heading=False),
    )
    user_access_type = GOVUKDesignSystemChoiceField(
        label="Open to all Data Workspace users",
        initial=UserAccessType.REQUIRES_AUTHORIZATION,
        choices=UserAccessType.choices,
        widget=GOVUKDesignSystemSelectWidget(label_is_heading=False, ),
    )
    eligibility_criteria = DWSplitArrayField(
        CharField(required=False),
        widget=BulletListSplitArrayWidget(
            label="Eligibility criteria",
            input_prefix="Eligibility criterion",
            widget=GOVUKDesignSystemTextWidget(
                label_is_heading=False,
                extra_label_classes="govuk-visually-hidden",
            ),
            size=5,
        ),
        required=False,
        size=5,
        remove_trailing_nulls=True,
        label="Eligibility criteria",
    )

    class Meta:
        model = VisualisationCatalogueItem
        fields = [
            "short_description",
            "description",
            "enquiries_contact",
            "secondary_enquiries_contact",
            "information_asset_manager",
            "information_asset_owner",
            "licence",
            "retention_policy",
            "personal_data",
            "restrictions_on_usage",
            "user_access_type",
            "eligibility_criteria",
        ]
        widgets = {
            "retention_policy": Textarea,
            "restrictions_on_usage": Textarea
        }
        labels = {"description": "Description"}

    def __init__(self, *args, **kwargs):
        kwargs["initial"] = kwargs.get("initial", {})
        super().__init__(*args, **kwargs)

        self._email_fields = [
            "enquiries_contact",
            "secondary_enquiries_contact",
            "information_asset_manager",
            "information_asset_owner",
        ]

        # Set the form field data for email fields to the actual user email address - by default it's the User ID.
        for field in self._email_fields:
            if getattr(self.instance, field):
                self.initial[field] = getattr(self.instance, field).email
コード例 #10
0
ファイル: forms.py プロジェクト: OmaPanton/data-workspace
class VisualisationsUICatalogueItemForm(GOVUKDesignSystemModelForm):
    short_description = GOVUKDesignSystemCharField(
        label="Short description",
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        error_messages={"required": "The visualisation must have a summary"},
    )

    enquiries_contact = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Enquiries contact",
        queryset=get_user_model().objects.all(),
        to_field_name='email',
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the enquiries contact",
            "invalid_choice":
            "The enquiries contact must have previously visited Data Workspace",
        },
    )
    secondary_enquiries_contact = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Secondary enquiries contact",
        queryset=get_user_model().objects.all(),
        to_field_name='email',
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the secondary enquiries contact",
            "invalid_choice":
            "The secondary enquiries contact must have previously visited Data Workspace",
        },
    )
    information_asset_manager = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Information asset manager",
        queryset=get_user_model().objects.all(),
        to_field_name='email',
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the information asset manager",
            "invalid_choice":
            "The information asset manager must have previously visited Data Workspace",
        },
    )
    information_asset_owner = GOVUKDesignSystemEmailValidationModelChoiceField(
        label="Information asset owner",
        queryset=get_user_model().objects.all(),
        to_field_name='email',
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
        required=False,
        error_messages={
            "invalid_email":
            "Enter a valid email address for the information asset owner",
            "invalid_choice":
            "The information asset owner must have previously visited Data Workspace",
        },
    )
    licence = GOVUKDesignSystemCharField(
        label="Licence",
        required=False,
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
    )
    retention_policy = GOVUKDesignSystemCharField(
        label="Retention policy",
        required=False,
        widget=GOVUKDesignSystemTextareaWidget(label_is_heading=False),
    )
    personal_data = GOVUKDesignSystemCharField(
        label="Personal data",
        required=False,
        widget=GOVUKDesignSystemTextWidget(label_is_heading=False),
    )
    restrictions_on_usage = GOVUKDesignSystemCharField(
        label="Restrictions on usage",
        required=False,
        widget=GOVUKDesignSystemTextareaWidget(label_is_heading=False),
    )
    user_access_type = GOVUKDesignSystemBooleanField(
        label='Each user must be individually authorized to access the data',
        required=False,
        widget=GOVUKDesignSystemSingleCheckboxWidget(
            check_test=lambda val: val == 'REQUIRES_AUTHORIZATION', ),
    )
    eligibility_criteria = DWSplitArrayField(
        CharField(required=False),
        widget=BulletListSplitArrayWidget(
            label="Eligibility criteria",
            input_prefix="Eligibility criterion",
            widget=GOVUKDesignSystemTextWidget(
                label_is_heading=False,
                extra_label_classes='govuk-visually-hidden',
            ),
            size=5,
        ),
        required=False,
        size=5,
        remove_trailing_nulls=True,
        label="Eligibility criteria",
    )

    class Meta:
        model = VisualisationCatalogueItem
        fields = [
            'short_description',
            'description',
            'enquiries_contact',
            'secondary_enquiries_contact',
            'information_asset_manager',
            'information_asset_owner',
            'licence',
            'retention_policy',
            'personal_data',
            'restrictions_on_usage',
            'user_access_type',
            'eligibility_criteria',
        ]
        widgets = {
            "retention_policy": Textarea,
            "restrictions_on_usage": Textarea
        }
        labels = {"description": "Description"}

    def __init__(self, *args, **kwargs):
        kwargs['initial'] = kwargs.get("initial", {})
        super().__init__(*args, **kwargs)
        is_instance = 'instance' in kwargs and kwargs['instance']

        self._email_fields = [
            'enquiries_contact',
            'secondary_enquiries_contact',
            'information_asset_manager',
            'information_asset_owner',
        ]

        # Set the form field data for email fields to the actual user email address - by default it's the User ID.
        for field in self._email_fields:
            if getattr(self.instance, field):
                self.initial[field] = getattr(self.instance, field).email

        self.fields['user_access_type'].initial = (
            kwargs['instance'].user_access_type == 'REQUIRES_AUTHORIZATION'
            if is_instance else True)

    def clean_user_access_type(self):
        return ('REQUIRES_AUTHORIZATION'
                if self.cleaned_data['user_access_type'] else
                'REQUIRES_AUTHENTICATION')