core: refactor MessageStage to not use dynamic class

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-10-26 20:01:42 +02:00
parent 9b6e07de17
commit f8fab14e1e

View file

@ -45,32 +45,24 @@ class Action(Enum):
DENY = "deny" DENY = "deny"
def message_stage(message: str, level: int) -> StageView: class MessageStage(StageView):
"""Show a pre-configured message after the flow is done""" """Show a pre-configured message after the flow is done"""
class MessageStage(StageView): # pylint: disable=unused-argument
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
"""Show a pre-configured message after the flow is done""" """Show a pre-configured message after the flow is done"""
message = getattr(self.executor.current_stage, "message", "")
level = getattr(self.executor.current_stage, "level", messages.SUCCESS)
messages.add_message(
self.request,
level,
message,
)
return self.executor.stage_ok()
message: str def post(self, request: HttpRequest) -> HttpResponse:
level: int """Wrapper for post requests"""
return self.get(request)
# pylint: disable=unused-argument
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
"""Show a pre-configured message after the flow is done"""
messages.add_message(
self.request,
self.level,
self.message,
)
return self.executor.stage_ok()
def post(self, request: HttpRequest) -> HttpResponse:
"""Wrapper for post requests"""
return self.get(request)
MessageStage.message = message
MessageStage.level = level
return MessageStage
class SourceFlowManager: class SourceFlowManager:
@ -284,13 +276,10 @@ class SourceFlowManager:
connection, connection,
stages=[ stages=[
in_memory_stage( in_memory_stage(
message_stage( MessageStage,
messages.SUCCESS, message=_(
_( "Successfully authenticated with %(source)s!" % {"source": self.source.name}
"Successfully authenticated with %(source)s!" ),
% {"source": self.source.name}
),
)
) )
], ],
**flow_kwargs, **flow_kwargs,
@ -339,13 +328,10 @@ class SourceFlowManager:
connection, connection,
stages=[ stages=[
in_memory_stage( in_memory_stage(
message_stage( MessageStage,
messages.SUCCESS, message=_(
_( "Successfully authenticated with %(source)s!" % {"source": self.source.name}
"Successfully authenticated with %(source)s!" ),
% {"source": self.source.name}
),
)
) )
], ],
**{ **{