Beispiel #1
0
class UserSatisfactionSurveyForm(GOVUKDesignSystemForm):
    how_satisfied = GOVUKDesignSystemRadioField(
        required=True,
        label=
        "1. Overall how satisfied are you with the current Data Workspace?",
        widget=GOVUKDesignSystemRadiosWidget(heading="h2",
                                             label_size="m",
                                             small=True),
        choices=[(t.value, t.label) for t in HowSatisfiedType],
    )

    trying_to_do = GOVUKDesignSystemMultipleChoiceField(
        required=False,
        label="2. What were you trying to do today? (optional)",
        help_text="Select all options that are relevant to you.",
        widget=GOVUKDesignSystemCheckboxesWidget(heading="h2",
                                                 label_size="m",
                                                 small=True),
        choices=[(t.value, t.label) for t in TryingToDoType],
    )

    improve_service = GOVUKDesignSystemTextareaField(
        required=False,
        label="3. How could we improve the service? (optional)",
        help_html=render_to_string(
            "core/partial/user-survey-improve-service-hint.html"),
        widget=GOVUKDesignSystemTextareaWidget(heading="h2", label_size="m"),
    )
Beispiel #2
0
class CreateTableSchemaForm(GOVUKDesignSystemForm):
    schema = GOVUKDesignSystemRadioField(
        label="In which schema would you like your table?",
        widget=GOVUKDesignSystemRadiosWidget,
        error_messages={"required": "You must select a schema."},
    )

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop("user")
        super().__init__(*args, **kwargs)
        if self.user.is_staff:
            all_schemas = get_all_schemas()
            all_choices = [(schema, schema) for schema in all_schemas] + [
                ("new", "None of the above - Create new schema")
            ]
        else:
            all_choices = []

        user_schema = get_schema_for_user(self.user)
        user_choice = [("user", f"{user_schema} (your private schema)")]

        team_schemas = get_team_schemas_for_user(self.user)
        team_choices = [
            (
                team_schema["name"],
                f"{team_schema['schema_name']} ({team_schema['name']} shared schema)",
            )
            for team_schema in team_schemas
        ]
        schema_choices = user_choice + team_choices + all_choices
        self.fields["schema"].choices = schema_choices
Beispiel #3
0
class PipelineTypeForm(GOVUKDesignSystemForm):
    pipeline_type = GOVUKDesignSystemRadioField(
        required=True,
        label="Select the type of pipeline you would like to create",
        widget=GOVUKDesignSystemRadiosWidget(
            heading="p", extra_label_classes="govuk-body-l"),
        choices=(
            ("sql", "SQL Pipeline"),
            ("sharepoint", "Sharepoint Pipeline"),
        ),
    )
Beispiel #4
0
class DataSetSubscriptionForm(GOVUKDesignSystemModelForm):
    class Meta:
        model = DataSetSubscription
        fields = ["notify_on_schema_change", "notify_on_data_change"]

    notification_type = GOVUKDesignSystemRadioField(
        required=True,
        label="What changes would you like to get emails about?",
        choices=NotificationType.choices,
        widget=GOVUKDesignSystemRadiosWidget,
    )
Beispiel #5
0
class RequestDataWhoAreYouForm(GOVUKDesignSystemModelForm):
    class Meta:
        model = DataRequest
        fields = ["requester_role"]

    requester_role = GOVUKDesignSystemRadioField(
        label="Are you the information asset owner or manager for the data?",
        choices=[(t.value, t.label) for t in RoleType],
        widget=GOVUKDesignSystemRadiosWidget,
        error_messages={
            "required": "You must declare your role in this request for data."
        },
    )
Beispiel #6
0
class RequestDataSecurityClassificationForm(GOVUKDesignSystemModelForm):
    class Meta:
        model = DataRequest
        fields = ["security_classification"]

    security_classification = GOVUKDesignSystemRadioField(
        label="What is the security classification of this data?",
        help_html=render_to_string(
            "request_data/security-classification-hint.html"),
        choices=[(t.value, t.label) for t in SecurityClassificationType],
        widget=GOVUKDesignSystemRadiosWidget,
        error_messages={
            "required":
            "You must declare the security classification of the data."
        },
    )
Beispiel #7
0
class SupportForm(GOVUKDesignSystemForm):
    class SupportTypes(models.TextChoices):
        TECH_SUPPORT = "tech", "I would like to have technical support"
        NEW_DATASET = "dataset", "I would like to add a new dataset"
        OTHER = "other", "Other"

    email = GOVUKDesignSystemEmailField(
        label="Your email address",
        required=False,
        widget=GOVUKDesignSystemEmailWidget(label_is_heading=False),
    )
    support_type = GOVUKDesignSystemRadioField(
        label="How can we help you?",
        help_text="Please choose one of the options below for help.",
        choices=SupportTypes.choices,
        widget=ConditionalSupportTypeRadioWidget(heading="h2"),
        error_messages={
            "required": "Please select the type of support you require."
        },
    )
    message = GOVUKDesignSystemTextareaField(
        required=False,
        label="Tell us how we can help you",
        widget=GOVUKDesignSystemTextareaWidget(
            label_is_heading=False,
            attrs={"rows": 5},
        ),
    )

    def clean(self):
        cleaned = super().clean()

        if cleaned["support_type"] in [
                self.SupportTypes.TECH_SUPPORT,
                self.SupportTypes.OTHER,
        ] and not cleaned.get("email"):
            raise forms.ValidationError(
                {"email": "Please enter your email address"})

        if cleaned["support_type"] == self.SupportTypes.OTHER and not cleaned[
                "message"]:
            raise forms.ValidationError(
                {"message": "Please enter your support message"})