예제 #1
0
 def is_valid(self, check_forms: typing.Dict[CheckId, "typing.Type[BaseCheckForm]"]) -> bool:  # type: ignore
     if not super().is_valid():
         return False
     checks = self.cleaned_data.get("checks", {})
     rforms = {
         name: check_forms[name](data=value)
         for name, value in checks.items()
         if name in check_forms
     }
     if forms.all_valid(rforms.values()):  # type: ignore
         self.cleaned_data["checks"] = {
             name: f.cleaned_data for name, f in rforms.items()
         }
         return True
     self.errors["checks"] = {name: form.errors for name, form in rforms.items()}
     return False
예제 #2
0
 def __init__(
     self,
     checks: Dict["Type[BaseCheck]", Sequence[str]],
     config: Optional[Dict[CheckId, dict]] = None,
     errors: Optional[forms.utils.ErrorDict] = None,
 ) -> None:
     checks = checks or {}
     config = config or {CheckId.X001: {}}
     self.errors = errors
     self.registered_checks: Dict[str, List["BaseCheck"]] = {}
     self.ignored: Dict[Union[CheckId, str], set] = {}
     for obj, ids in _IGNORED.items():
         for id_ in ids:
             self.ignored.setdefault(id_, set()).add(obj)
     for check_class, tags in checks.items():
         if check_class.Id in config:
             check = check_class(
                 ignored_objects=self.ignored.get(check_class.Id, set()),
                 **config[check_class.Id],
             )
             for tag in tags:
                 self.registered_checks.setdefault(tag, []).append(check)