Use master view's session when creating form

Needed when allowing create for models from non-rattail database
This commit is contained in:
Lance Edgar 2016-12-05 21:01:30 -06:00
parent 7705c765ee
commit 4a2ba3925d
2 changed files with 4 additions and 2 deletions

View file

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

View file

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