On Tue, 6 Feb 2007 18:53:38 -0800 (PST) Douglas Douglas <[EMAIL PROTECTED]> wrote:
> I guess you get this error because you're running the example as a > single script in isolation. The script should run inside a Zope 3 > environment (with utilities and adapters registries set up). > > If you want to try the example in IDLE you should create a Zope 3 > instance (using the mkzopeinstance script) and insert at the > beginning of your script: > > from zope.app.debug import Debugger > debugger = Debugger(db='/some/path/to/the/instances/Data.fs/file', > config_file='/some/path/to/the/instances/etcs/site.zcm/file') > > That would start a Zope 3 environment (with utilities and adapters > set up) and your example will run just fine. > Hi Douglas (and thank you Tom D.), You've hit the nail on the head. I did as you instructed above and was (mostly) able to correctly run the examples. It was very nice of you (both) to provide some help when I was fairly high up on the frustration level. I had a nice end to my evening of zope exploration. I managed to get zalchemy to work--to my astonishment. ;-) I have a SQLAlchemyContainer which has iso639 languages and I can actually click on one of them, edit it and have the changes reflected in the database. Below are the relevant files for those who are trying zalchemy. I created a SQLAlchemyContainer called Langs using the ZMI 'Add SQLalc...' feature while specifying the path to the ISO6392Language class after creating the iso639.py file below. At the end of this message is the SQL for the language table. The table lives in a non-default postgresql database schema named zope_schema (rather than public). I was unable to get autoload to work for sqlalchemy table reflection. This means I had to type all the Columns in by hand. I'll have to write a short script to build the interface, implementing class, and sqlalchemy.Table code, someday. It will get tedious having to cut and paste that for many tables. I hope this helps someone and that I haven't forgotten anything. Vinny ========= iso639.py ============== # from zope.interface import implements from zope.schema.fieldproperty import FieldProperty from interfaces import IISO6392Language from zope.publisher.browser import TestRequest import sqlalchemy import z3c.zalchemy from z3c.zalchemy.datamanager import AlchemyEngineUtility engineUtility = AlchemyEngineUtility( 'pg', 'postgres://user:[EMAIL PROTECTED]:5432/zopedb', echo=True ) from zope.component import provideUtility provideUtility(engineUtility) #pg = engineUtility.getEngine() #print pg.connect() #session = z3c.zalchemy.getSession #z3c.zalchemy.assignTable('iso639_2_language', 'pg') iso639_2_language = sqlalchemy.Table( 'iso639_2_language', z3c.zalchemy.metadata, sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True), sqlalchemy.Column('lookup', sqlalchemy.String(1024), nullable=False, default=u''), sqlalchemy.Column('enabled', sqlalchemy.Boolean, default=True), sqlalchemy.Column('reportable', sqlalchemy.Boolean, default=True), sqlalchemy.Column('searchable', sqlalchemy.Boolean, default=True), sqlalchemy.Column('bibliographic_code', sqlalchemy.String(3), nullable=False, default=u''), sqlalchemy.Column('terminologic_code', sqlalchemy.String(3), nullable=False, default=u''), sqlalchemy.Column('alpha2_code', sqlalchemy.String(2), nullable=False, default=u''), #autoload=True, schema='zope_schema') class ISO6392Language(object): """The implementation of IISO6392Language. Hopefully, the FieldProperty usage will help validate user data.""" implements(IISO6392Language) id = FieldProperty(IISO6392Language['id']) lookup = FieldProperty(IISO6392Language['lookup']) enabled = FieldProperty(IISO6392Language['enabled']) reportable = FieldProperty(IISO6392Language['reportable']) searchable = FieldProperty(IISO6392Language['searchable']) bibliographic_code = FieldProperty(IISO6392Language['bibliographic_code']) terminologic_code = FieldProperty(IISO6392Language['terminologic_code']) alpha2_code = FieldProperty(IISO6392Language['alpha2_code']) def __repr__(self): return "%s(%r,%r)" % ( self.__class__.__name__, self.lookup, self.id) ISO6392Language.mapper = sqlalchemy.mapper(ISO6392Language, iso639_2_language) #z3c.zalchemy.createTable('iso639_2_language') from zope.formlib import form from zope.app.pagetemplate import ViewPageTemplateFile class ISO6392LanguageForm(form.EditForm): form_fields = form.Fields(IISO6392Language, omit_readonly=True) # template = ViewPageTemplateFile('langedit.pt') ===============8<================== ========= configure.zcml =========== <configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" xmlns:alchemy='http://namespaces.zalchemy.org/alchemy' i18n_domain="hello" > <class class=".iso639.ISO6392Language"> <require permission="zope.Public" interface=".interfaces.IISO6392Language" /> <require permission="zope.ManageContent" set_schema=".interfaces.IISO6392Language" /> </class> <browser:page for=".interfaces.IISO6392Language" name="langedit.html" class=".iso639.ISO6392LanguageForm" permission="zope.View" template="langedit.pt" menu="zmi_views" title="Edit" /> <!-- alchemy:engine name="pg" url="postgres://user:[EMAIL PROTECTED]:5432/zopedb" /> <alchemy:connectTable table="iso639_2_language" engine="pg" /> <alchemy:connectClass class="hello.sql.iso639.ISO6392Language" engine="pg" / --> </configure> =================8<====================== ============ interfaces.py ============= # Some postgres table interfaces # from zope.interface import Interface from zope.schema import Int, TextLine, Bool from zope.i18n import MessageFactory _ = MessageFactory('hello') class IISO6392Language(Interface): """The interface definition of the iso639_2_language table. """ id = Int( title=_(u"serial id"), description=_(u"primary key is derived from this content"), readonly=True, required=True, ) bibliographic_code = TextLine( title=_(u"Bibliographic Code"), description=_(u"The three letter bibliographic code for the language. eng is for english."), required=True, max_length=3 ) lookup = TextLine( title=_(u"Lookup code. Message Id"), description=_(u"This may be used as a message id in i18n terms. Should be textually unique in a table."), required=True, max_length=1024 ) enabled = Bool( title=_(u"Language Enabled"), description=_(u"If True then this record be used as a vocabulary item when creating a new object that has this item as a property."), required=True, ) searchable = Bool( title=_(u"Language is Searchable"), description=_(u"If True then this record be used as a selection item when searching for objects that have this item as a property."), required=True, ) reportable = Bool( title=_(u"Language is Reportable"), description=_(u"If True then this record be used as a selection item when reporting on objects that have this item as a property."), required=True, ) terminologic_code = TextLine( title=_(u"Terminologic Code"), description=_(u"The three letter terminologic code for the language. Defaults to the bibliographic."), required=False, max_length=3 ) alpha2_code = TextLine( title=_(u"Two letter Language Code"), description=_(u"The two letter code for the language from ISO 639-1."), required=False, max_length=2 ) =============8<=============== ========= langedit.pt =============== <html metal:use-macro="context/@@standard_macros/view"> <body> <div metal:fill-slot="body" tal:content="view"> </div> </body> </html> =============8<============== ============= ISO639_2_language ========= -- Table: zope_schema.iso639_2_language -- DROP TABLE zope_schema.iso639_2_language; CREATE TABLE zope_schema.iso639_2_language ( id serial NOT NULL, bibliographic_code character varying(8) NOT NULL DEFAULT ''::character varying, lookup character varying(1024) NOT NULL DEFAULT ''::character varying, enabled boolean DEFAULT false, searchable boolean DEFAULT false, reportable boolean DEFAULT false, terminologic_code character varying(8) DEFAULT ''::character varying, alpha2_code character varying(8) DEFAULT ''::character varying, CONSTRAINT iso639_2_language_pk PRIMARY KEY (id) ) WITHOUT OIDS; ALTER TABLE zope_schema.iso639_2_language OWNER TO zope; ===============9<=================== _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users