Use master view's session when creating form
Needed when allowing create for models from non-rattail database
This commit is contained in:
parent
7705c765ee
commit
4a2ba3925d
|
@ -54,10 +54,11 @@ class AlchemyForm(Object):
|
||||||
|
|
||||||
allow_successive_creates = False
|
allow_successive_creates = False
|
||||||
|
|
||||||
def __init__(self, request, fieldset, **kwargs):
|
def __init__(self, request, fieldset, session=None, **kwargs):
|
||||||
super(AlchemyForm, self).__init__(**kwargs)
|
super(AlchemyForm, self).__init__(**kwargs)
|
||||||
self.request = request
|
self.request = request
|
||||||
self.fieldset = fieldset
|
self.fieldset = fieldset
|
||||||
|
self.session = session
|
||||||
|
|
||||||
def _get_readonly(self):
|
def _get_readonly(self):
|
||||||
return self.fieldset.readonly
|
return self.fieldset.readonly
|
||||||
|
@ -82,7 +83,7 @@ class AlchemyForm(Object):
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
self.fieldset.sync()
|
self.fieldset.sync()
|
||||||
Session.flush()
|
self.session.flush()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.fieldset.rebind(data=self.request.params)
|
self.fieldset.rebind(data=self.request.params)
|
||||||
|
|
|
@ -949,6 +949,7 @@ class MasterView(View):
|
||||||
else:
|
else:
|
||||||
kwargs.setdefault('cancel_url', self.get_action_url('view', instance))
|
kwargs.setdefault('cancel_url', self.get_action_url('view', instance))
|
||||||
factory = kwargs.pop('factory', forms.AlchemyForm)
|
factory = kwargs.pop('factory', forms.AlchemyForm)
|
||||||
|
kwargs.setdefault('session', self.Session())
|
||||||
form = factory(self.request, fieldset, **kwargs)
|
form = factory(self.request, fieldset, **kwargs)
|
||||||
form.readonly = self.viewing
|
form.readonly = self.viewing
|
||||||
return form
|
return form
|
||||||
|
|
Loading…
Reference in a new issue