diff --git a/benefits/core/models.py b/benefits/core/models.py index 3a09aa0c3..ef9541b8d 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -592,13 +592,13 @@ def enrollment_success_template(self): return self.enrollment_success_template_override or f"{prefix}--{self.agency_card_name}.html" def clean(self): - supports_expiration = self.supports_expiration - expiration_days = self.expiration_days - expiration_reenrollment_days = self.expiration_reenrollment_days - reenrollment_error_template = self.reenrollment_error_template + errors = {} + + if self.supports_expiration: + expiration_days = self.expiration_days + expiration_reenrollment_days = self.expiration_reenrollment_days + reenrollment_error_template = self.reenrollment_error_template - if supports_expiration: - errors = {} message = "When support_expiration is True, this value must be greater than 0." if expiration_days is None or expiration_days <= 0: errors.update(expiration_days=ValidationError(message)) @@ -607,8 +607,25 @@ def clean(self): if reenrollment_error_template is None: errors.update(reenrollment_error_template=ValidationError("Required when supports expiration is True.")) - if errors: - raise ValidationError(errors) + if self.transit_agency and self.transit_agency.active: + self.transit_agency.clean() + + templates = dict( + selection_label_template=self.selection_label_template, + eligibility_start_template=self.eligibility_start_template, + eligibility_unverified_template=self.eligibility_unverified_template, + enrollment_index_template=self.enrollment_index_template, + enrollment_success_template=self.enrollment_success_template, + ) + if self.supports_expiration: + templates.update(reenrollment_error_template=self.reenrollment_error_template) + + for name, tmpl in templates.items(): + if not template_path(tmpl): + errors.update({name: ValidationError(f"Template not found: {tmpl}")}) + + if errors: + raise ValidationError(errors) def eligibility_form_instance(self, *args, **kwargs): """Return an instance of this flow's EligibilityForm, or None."""