[z3-five] zope.formlib with DB

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Fri Oct 20 15:20:48 CEST 2006


> I am looking for an example of using zope.formlib in connection with a 
> SQL database. (preferable SQLObject or SQLAlchemy as mapper)
> Means that I would have a container that doesn't look up in the ZODB but 
> in the external database by default.
>   
I did something like that but with standard DB adapters.
I've used setupDataWidgets function found somewhere
in formlibcode that gets 'data' parameter to inject data
from database. Function self.context._get_data()
in the example below returns data from db.


from Products.Five.formlib.formbase import Form

class TemplateFormlibForm(Form):
    """ testing formlib
    """
    prefix = 'tfl'
    form_fields = form.Fields(ITemplateFormlib)

    def setUpWidgets(self, ignore_request=True):
        self.adapters = {}
        self.widgets = setUpDataWidgets(
                                          form_fields=self.form_fields,
                                          form_prefix=self.prefix,
                                          context=self.context,
                                          request=self.request,
                                          data=self.context._get_data(),
                                          ignore_request=ignore_request)


-- 
Maciej Wisniowski


More information about the z3-five mailing list