Esempio n. 1
0
class PreviousAttemptsForm(DynamicallyRequiredBoolMixin, forms.ModelForm):
    class Meta:
        model = models.HPActionDetails
        fields = [
            FILED_WITH_311,
            THIRTY_DAYS_SINCE_311,
            HPD_ISSUED_VIOLATIONS,
            THIRTY_DAYS_SINCE_VIOLATIONS,
        ]

    filed_with_311 = YesNoRadiosField()
    thirty_days_since_311 = YesNoRadiosField(required=False)
    hpd_issued_violations = YesNoRadiosField(required=False)
    thirty_days_since_violations = YesNoRadiosField(required=False)

    def clean(self):
        cleaned_data = super().clean()
        filed_with_311 = YesNoRadiosField.coerce(cleaned_data.get(FILED_WITH_311))

        if filed_with_311 is True:
            hpd_issued_violations = self.require_bool_field(
                HPD_ISSUED_VIOLATIONS, cleaned_data)
            if hpd_issued_violations is False:
                self.require_bool_field(THIRTY_DAYS_SINCE_311, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''
            elif hpd_issued_violations is True:
                self.require_bool_field(THIRTY_DAYS_SINCE_VIOLATIONS, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_311] = ''
        elif filed_with_311 is False:
            cleaned_data[HPD_ISSUED_VIOLATIONS] = ''
            cleaned_data[THIRTY_DAYS_SINCE_311] = ''
            cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''

        return cleaned_data
Esempio n. 2
0
class HarassmentApartmentForm(forms.ModelForm):
    class Meta:
        model = models.HarassmentDetails
        fields = [
            'two_or_less_apartments_in_building',
            'more_than_one_family_per_apartment',
        ]

    two_or_less_apartments_in_building = YesNoRadiosField()
    more_than_one_family_per_apartment = YesNoRadiosField()
Esempio n. 3
0
class PublicAssistanceForm(forms.ModelForm):
    class Meta:
        model = OnboardingInfo
        fields = ("receives_public_assistance",)

    receives_public_assistance = YesNoRadiosField(
        help_text=OnboardingInfo._meta.get_field("receives_public_assistance").help_text
    )
Esempio n. 4
0
class ReliefAttemptsForm(forms.ModelForm):
    class Meta:
        model = OnboardingInfo
        fields = ("has_called_311",)

    has_called_311 = YesNoRadiosField(
        help_text=OnboardingInfo._meta.get_field("has_called_311").help_text
    )
Esempio n. 5
0
class UrgentAndDangerousForm(forms.ModelForm):
    class Meta:
        model = models.HPActionDetails
        fields = [
            'urgent_and_dangerous'
        ]

    urgent_and_dangerous = YesNoRadiosField()
Esempio n. 6
0
class PreviousAttemptsForm(forms.ModelForm):
    class Meta:
        model = models.HPActionDetails
        fields = [
            FILED_WITH_311,
            THIRTY_DAYS_SINCE_311,
            HPD_ISSUED_VIOLATIONS,
            THIRTY_DAYS_SINCE_VIOLATIONS,
        ]

    filed_with_311 = YesNoRadiosField()
    thirty_days_since_311 = YesNoRadiosField(required=False)
    hpd_issued_violations = YesNoRadiosField(required=False)
    thirty_days_since_violations = YesNoRadiosField(required=False)

    def add_dynamically_required_error(self, field: str):
        msg = forms.Field.default_error_messages['required']
        self.add_error(field, ValidationError(msg, code='required'))

    def require_bool_field(self, field: str, cleaned_data) -> Optional[bool]:
        value = YesNoRadiosField.coerce(cleaned_data.get(field))
        if value is None:
            self.add_dynamically_required_error(field)
        else:
            assert isinstance(value, bool)
        return value

    def clean(self):
        cleaned_data = super().clean()
        filed_with_311 = YesNoRadiosField.coerce(cleaned_data.get(FILED_WITH_311))

        if filed_with_311 is True:
            hpd_issued_violations = self.require_bool_field(
                HPD_ISSUED_VIOLATIONS, cleaned_data)
            if hpd_issued_violations is False:
                self.require_bool_field(THIRTY_DAYS_SINCE_311, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''
            elif hpd_issued_violations is True:
                self.require_bool_field(THIRTY_DAYS_SINCE_VIOLATIONS, cleaned_data)
                cleaned_data[THIRTY_DAYS_SINCE_311] = ''
        elif filed_with_311 is False:
            cleaned_data[HPD_ISSUED_VIOLATIONS] = ''
            cleaned_data[THIRTY_DAYS_SINCE_311] = ''
            cleaned_data[THIRTY_DAYS_SINCE_VIOLATIONS] = ''

        return cleaned_data
Esempio n. 7
0
class OnboardingStep3Form(forms.ModelForm):
    class Meta:
        model = OnboardingInfo
        fields = ('lease_type', 'receives_public_assistance')

    receives_public_assistance = YesNoRadiosField(
        help_text=OnboardingInfo._meta.get_field(
            'receives_public_assistance').help_text)
Esempio n. 8
0
class OnboardingStep3Form(forms.ModelForm):
    class Meta:
        model = OnboardingInfo
        fields = ("lease_type", "receives_public_assistance")

    receives_public_assistance = YesNoRadiosField(
        help_text=OnboardingInfo._meta.get_field("receives_public_assistance").help_text
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields["lease_type"].required = True
Esempio n. 9
0
class HarassmentApartmentForm(DynamicallyRequiredBoolMixin, forms.ModelForm):
    class Meta:
        model = models.HarassmentDetails
        fields = [
            TWO_OR_LESS_APARTMENTS_IN_BUILDING,
            MORE_THAN_ONE_FAMILY_PER_APARTMENT,
        ]

    two_or_less_apartments_in_building = YesNoRadiosField()
    more_than_one_family_per_apartment = YesNoRadiosField(required=False)

    def clean(self):
        cleaned_data = super().clean()
        two_or_less = YesNoRadiosField.coerce(cleaned_data.get(TWO_OR_LESS_APARTMENTS_IN_BUILDING))

        if two_or_less is True:
            self.require_bool_field(MORE_THAN_ONE_FAMILY_PER_APARTMENT, cleaned_data)
        elif two_or_less is False:
            cleaned_data[MORE_THAN_ONE_FAMILY_PER_APARTMENT] = ''

        return cleaned_data
Esempio n. 10
0
class IndexNumberForm(DynamicallyRequiredFieldsMixin, forms.ModelForm):
    class Meta:
        model = HardshipDeclarationDetails
        fields = ("index_number",)

    has_current_case = YesNoRadiosField()

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

        has_current_case = YesNoRadiosField.coerce(cleaned_data.get("has_current_case"))

        if has_current_case is True:
            self.require_text_field("index_number", cleaned_data)
        elif has_current_case is False:
            cleaned_data["index_number"] = ""

        return cleaned_data
Esempio n. 11
0
class FeeWaiverPublicAssistanceForm(forms.ModelForm):
    class Meta:
        model = models.FeeWaiverDetails
        fields = ['receives_public_assistance']

    receives_public_assistance = YesNoRadiosField()
Esempio n. 12
0
class FeeWaiverMiscForm(forms.ModelForm):
    class Meta:
        model = models.FeeWaiverDetails
        fields = ['asked_before']

    asked_before = YesNoRadiosField()