ui/identity: remove _AsyncValidatedMixin
_AsyncValidatedMixin has been merged into the parent UsernameEditor, reluctantly. I like the concept of _AsyncValidatedMixin, but what's happening here is that UsernameEditor has inherited from 3 classes, the first of which is in urwid, and when the constructor / super().__init__() status changed in urwid, _AsyncValidatedMixin.__init__() stopped being called. OK cool, so maybe we'll just manually run initializers in the case where it matters. That's semi-better, but with old urwid we end up calling _AsyncValidatedMixin.__init__() twice (once directly, once by the urwid __init__ using super()). Further workarounds could be employed but at the moment there is one user of _AsyncValidatedMixin, so just merge it into UsernameEditor.
This commit is contained in:
parent
29b3f361d1
commit
a695329216
|
@ -53,9 +53,7 @@ class RealnameEditor(StringEditor, WantsToKnowFormField):
|
|||
return super().valid_char(ch)
|
||||
|
||||
|
||||
class _AsyncValidatedMixin:
|
||||
"""Provides Editor widgets with async validation capabilities"""
|
||||
|
||||
class UsernameEditor(StringEditor, WantsToKnowFormField):
|
||||
def __init__(self):
|
||||
self.validation_task = None
|
||||
self.initial = None
|
||||
|
@ -63,6 +61,12 @@ class _AsyncValidatedMixin:
|
|||
self._validate_async_inner = None
|
||||
connect_signal(self, "change", self._reset_validation)
|
||||
|
||||
self.valid_char_pat = r"[-a-z0-9_]"
|
||||
self.error_invalid_char = _(
|
||||
"The only characters permitted in this field are a-z, 0-9, _ and -"
|
||||
)
|
||||
super().__init__()
|
||||
|
||||
def set_initial_state(self, initial):
|
||||
self.initial = initial
|
||||
self.validation_result = initial
|
||||
|
@ -86,15 +90,6 @@ class _AsyncValidatedMixin:
|
|||
self.validation_result = await self._validate_async_inner(value)
|
||||
self.bff.validate()
|
||||
|
||||
|
||||
class UsernameEditor(StringEditor, _AsyncValidatedMixin, WantsToKnowFormField):
|
||||
def __init__(self):
|
||||
self.valid_char_pat = r"[-a-z0-9_]"
|
||||
self.error_invalid_char = _(
|
||||
"The only characters permitted in this field are a-z, 0-9, _ and -"
|
||||
)
|
||||
super().__init__()
|
||||
|
||||
def valid_char(self, ch):
|
||||
if len(ch) == 1 and not re.match(self.valid_char_pat, ch):
|
||||
self.bff.in_error = True
|
||||
|
|
Loading…
Reference in New Issue