from __future__ import annotations
from onegov.form.i18n import _
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from wtforms import Field
[docs]
class InvalidMimeType(FormError):
pass
[docs]
class UnableToComplete(FormError):
pass
[docs]
class _FormParsingErrorWithLineContext(FormParsingError):
def __init__(self, line: int):
[docs]
def field_message(self, field: Field) -> str:
return super().field_message(field).format(line=self.line)
[docs]
def __repr__(self) -> str:
return f'{self.__class__.__name__}(line={self.line})'
[docs]
class InvalidIndentSyntax(_FormParsingErrorWithLineContext):
[docs]
message_template = _(
'The indentation on line {line} is not valid. '
'Please use a multiple of 4 spaces'
)
[docs]
class _FormParsingErrorWithLabelContext(FormParsingError):
def __init__(self, label: str):
[docs]
def field_message(self, field: Field) -> str:
return super().field_message(field).format(label=self.label)
[docs]
def __repr__(self) -> str:
return f'{self.__class__.__name__}(label={self.label!r})'
[docs]
class DuplicateLabelError(_FormParsingErrorWithLabelContext):
[docs]
message_template = _("The field '{label}' exists more than once.")
[docs]
class EmptyFieldsetError(_FormParsingErrorWithLabelContext):
[docs]
message_template = _(
"The '{label}' group is empty and will not be visible. Either remove "
"the empty group or add fields to it."
)
[docs]
class FieldCompileError(_FormParsingErrorWithLabelContext):
[docs]
message_template = _(
"The field '{label}' has no type defined. "
"For example use '___' for a text field."
)
[docs]
class MixedTypeError(_FormParsingErrorWithLabelContext):
[docs]
message_template = _(
"The field '{label}' cannot mix radio buttons and checkboxes."
)