class Meta: model = Contact fields = ( 'id', 'title', 'first_name', 'last_name', 'name', 'job_title', 'company', 'adviser', 'primary', 'telephone_countrycode', 'telephone_number', 'email', 'address_same_as_company', 'address_1', 'address_2', 'address_town', 'address_county', 'address_country', 'address_postcode', 'telephone_alternative', 'email_alternative', 'notes', 'accepts_dit_email_marketing', 'archived', 'archived_documents_url_path', 'archived_on', 'archived_reason', 'archived_by', 'created_on', 'modified_on', ) read_only_fields = ('archived_documents_url_path', ) validators = [ NotArchivedValidator(), RulesBasedValidator( ValidationRule( 'address_same_as_company_and_has_address', OperatorRule('address_same_as_company', not_), when=AnyIsNotBlankRule( *Contact.ADDRESS_VALIDATION_MAPPING.keys()), ), ValidationRule( 'no_address', OperatorRule('address_same_as_company', bool), when=AllIsBlankRule( *Contact.ADDRESS_VALIDATION_MAPPING.keys()), ), ), # Note: This is deliberately after RulesBasedValidator, so that # address_same_as_company rules run first. AddressValidator( lazy=True, fields_mapping=Contact.ADDRESS_VALIDATION_MAPPING), ] permissions = { f'company.{ContactPermission.view_contact_document}': 'archived_documents_url_path', }
class Meta: model = InvestorProfile fields = ALL_LARGE_CAPITAL_FIELDS validators = [ RulesBasedValidator( ValidationRule( 'invalid_required_checks_conducted_on', OperatorRule('required_checks_conducted_on', bool), when=InRule( 'required_checks_conducted', REQUIRED_CHECKS_THAT_NEED_ADDITIONAL_INFORMATION, ), ), ValidationRule( 'invalid_required_checks_conducted_by', OperatorRule('required_checks_conducted_by', bool), when=InRule( 'required_checks_conducted', REQUIRED_CHECKS_THAT_NEED_ADDITIONAL_INFORMATION, ), ), ValidationRule( 'required_checks_conducted_value', OperatorRule('required_checks_conducted', is_not_blank), when=AnyIsNotBlankRule( 'required_checks_conducted_by', 'required_checks_conducted_on', ), ), ), ]
class Meta: validators = [ RulesBasedValidator( ValidationRule( 'invalid_required_checks_conducted_on', IsFieldBeingUpdatedAndIsNotBlankRule( 'required_checks_conducted_on', ), when=AndRule( IsFieldBeingUpdatedRule('required_checks_conducted', ), InRule( 'required_checks_conducted', REQUIRED_CHECKS_THAT_NEED_ADDITIONAL_INFORMATION, ), ), ), ValidationRule( 'invalid_required_checks_conducted_by', IsFieldBeingUpdatedAndIsNotBlankRule( 'required_checks_conducted_by', ), when=AndRule( IsFieldBeingUpdatedRule('required_checks_conducted', ), InRule( 'required_checks_conducted', REQUIRED_CHECKS_THAT_NEED_ADDITIONAL_INFORMATION, ), ), ), ValidationRule( 'required_checks_conducted_value', OperatorRule( 'required_checks_conducted', is_not_blank, ), when=AnyIsNotBlankRule( 'required_checks_conducted_by', 'required_checks_conducted_on', ), ), ValidationRule( 'invalid_required_checks_conducted_on_must_be_within_12_months', IsFieldRule( 'required_checks_conducted_on', is_provided_and_is_date_less_than_a_year_ago, ), when=AndRule( IsFieldBeingUpdatedRule( 'required_checks_conducted_on', ), InRule( 'required_checks_conducted', REQUIRED_CHECKS_THAT_NEED_ADDITIONAL_INFORMATION, ), ), ), ), ]