From 4a2ba3925d1ab2f33bbd7a67fcc4433993247683 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 5 Dec 2016 21:01:30 -0600 Subject: [PATCH] Use master view's session when creating form Needed when allowing create for models from non-rattail database --- tailbone/forms/alchemy.py | 5 +++-- tailbone/views/master.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tailbone/forms/alchemy.py b/tailbone/forms/alchemy.py index 0b9af0ff..143193b0 100644 --- a/tailbone/forms/alchemy.py +++ b/tailbone/forms/alchemy.py @@ -54,10 +54,11 @@ class AlchemyForm(Object): allow_successive_creates = False - def __init__(self, request, fieldset, **kwargs): + def __init__(self, request, fieldset, session=None, **kwargs): super(AlchemyForm, self).__init__(**kwargs) self.request = request self.fieldset = fieldset + self.session = session def _get_readonly(self): return self.fieldset.readonly @@ -82,7 +83,7 @@ class AlchemyForm(Object): def save(self): self.fieldset.sync() - Session.flush() + self.session.flush() def validate(self): self.fieldset.rebind(data=self.request.params) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 27d7a42d..685f989b 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -949,6 +949,7 @@ class MasterView(View): else: kwargs.setdefault('cancel_url', self.get_action_url('view', instance)) factory = kwargs.pop('factory', forms.AlchemyForm) + kwargs.setdefault('session', self.Session()) form = factory(self.request, fieldset, **kwargs) form.readonly = self.viewing return form