admin: update to work with new form

This commit is contained in:
Jens Langhammer 2020-07-20 16:55:55 +02:00
parent 4040eb9619
commit 88029a4335
3 changed files with 12 additions and 6 deletions

View File

@ -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 (

View File

@ -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

View File

@ -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 = {