From 88029a43355d73011b9fd078231fd932cfa1e2a6 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 20 Jul 2020 16:55:55 +0200 Subject: [PATCH] admin: update to work with new form --- passbook/admin/views/utils.py | 8 +++----- passbook/flows/models.py | 8 +++++++- passbook/root/settings.py | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/passbook/admin/views/utils.py b/passbook/admin/views/utils.py index 1c2f5e74b..22e984a64 100644 --- a/passbook/admin/views/utils.py +++ b/passbook/admin/views/utils.py @@ -6,7 +6,7 @@ from django.contrib.messages.views import SuccessMessageMixin from django.http import Http404 from django.views.generic import DeleteView, ListView, UpdateView -from passbook.lib.utils.reflection import all_subclasses, path_to_class +from passbook.lib.utils.reflection import all_subclasses from passbook.lib.views import CreateAssignPermView @@ -40,7 +40,7 @@ class InheritanceCreateView(CreateAssignPermView): ) except StopIteration as exc: raise Http404 from exc - return path_to_class(model.form) + return model.form(model) def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: kwargs = super().get_context_data(**kwargs) @@ -61,9 +61,7 @@ class InheritanceUpdateView(UpdateView): return kwargs def get_form_class(self): - form_class_path = self.get_object().form - form_class = path_to_class(form_class_path) - return form_class + return self.get_object().form() def get_object(self, queryset=None): return ( diff --git a/passbook/flows/models.py b/passbook/flows/models.py index 9eece7308..06338e596 100644 --- a/passbook/flows/models.py +++ b/passbook/flows/models.py @@ -50,6 +50,9 @@ class Stage(models.Model): def type(self) -> Type["StageView"]: """Return StageView class that implements logic for this stage""" + # This is a bit of a workaround, since we can't set class methods with setattr + if hasattr(self, "__in_memory_type"): + return getattr(self, "__in_memory_type") raise NotImplementedError def form(self) -> Type[ModelForm]: @@ -69,7 +72,10 @@ class Stage(models.Model): def in_memory_stage(view: Type["StageView"]) -> Stage: """Creates an in-memory stage instance, based on a `_type` as view.""" stage = Stage() - setattr(stage, "type", lambda self: view) + # Because we can't pickle a locally generated function, + # we set the view as a separate property and reference a generic function + # that returns that member + setattr(stage, "__in_memory_type", view) return stage diff --git a/passbook/root/settings.py b/passbook/root/settings.py index 77e3aa9e9..0149abdd9 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -325,6 +325,8 @@ LOG_PRE_CHAIN = [ structlog.stdlib.add_log_level, structlog.stdlib.add_logger_name, structlog.processors.TimeStamper(), + structlog.processors.StackInfoRenderer(), + structlog.processors.format_exc_info, ] LOGGING = {