示例#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
示例#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()
示例#3
0
 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
示例#4
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
    )
示例#5
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
    )
示例#6
0
class UrgentAndDangerousForm(forms.ModelForm):
    class Meta:
        model = models.HPActionDetails
        fields = [
            'urgent_and_dangerous'
        ]

    urgent_and_dangerous = YesNoRadiosField()
示例#7
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
示例#8
0
文件: forms.py 项目: ma8642/tenants2
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)
示例#9
0
    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
示例#10
0
    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
示例#11
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
示例#12
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
示例#13
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
示例#14
0
    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
示例#15
0
 def test_reverse_coerce_to_str_works(self, value, expected):
     assert YesNoRadiosField.reverse_coerce_to_str(value) == expected
示例#16
0
 def test_coerce_works(self, value, expected):
     assert YesNoRadiosField.coerce(value) is expected
示例#17
0
class FeeWaiverMiscForm(forms.ModelForm):
    class Meta:
        model = models.FeeWaiverDetails
        fields = ['asked_before']

    asked_before = YesNoRadiosField()
示例#18
0
 def test_raises_value_error_on_unexpected_value(self):
     with pytest.raises(ValueError,
                        match="Invalid YesNoRadiosField value: blah"):
         YesNoRadiosField.coerce("blah")
示例#19
0
class FeeWaiverPublicAssistanceForm(forms.ModelForm):
    class Meta:
        model = models.FeeWaiverDetails
        fields = ['receives_public_assistance']

    receives_public_assistance = YesNoRadiosField()