From andreas at work.de Tue Nov 1 13:51:29 2005 From: andreas at work.de (Andreas Elvers) Date: Tue, 01 Nov 2005 13:51:29 +0100 Subject: [Z3-sqlos] sqlos and per site databases Message-ID: Hi, I am having problems with sqlos and local utilities. I have a folder which is a site. This site has a local utility which is a psycopg adapter named as 'psycopg'. I have registered this name with sqlos. When adding a SQLObjectContainer to this site folder my guess is, that this container should use the db adapter 'psycopg'. While adding I get a "'NoneType' object is not callable" in connection.py on line 96. This is because queryUtility really does not find my local Utility although context point to the newly created SQLObjectContainer and the utility name is currect either. I use sqlos trunk revision 19234. Maybe I forgot some magic configure stuff to make SQLObjectContainer more SiteManager aware ? thanks for any ideas, - Andreas From andreas at work.de Tue Nov 1 14:49:01 2005 From: andreas at work.de (Andreas Elvers) Date: Tue, 01 Nov 2005 14:49:01 +0100 Subject: [Z3-sqlos] Re: Error adapting connection In-Reply-To: <43c3c6a1de82355f87df1d88a7b720cc@cohack.com> References: <43c3c6a1de82355f87df1d88a7b720cc@cohack.com> Message-ID: Ben Godfrey wrote: [...] > In addition, I have a couple of questions: > > How can I use connections created through the site management folder > instead of hard-coded into ZCML? I'm just starting in zope3 so this may be wrong, but I don't think so :-) This should be possible through local utilities and SiteManager. On the management interface do: Create a Folder Enter Folder Click on "Make a site". A SiteManager with a default Folder (you can have diffrent site folder). Enter default folder. Add your database adapter. Register the Adapter ("register as" is the lookup name for sqlos) In your configure.zcml where you define the sqlos stuff you should change the line: change psycopg against the name you put in "register as". The manual work above can be put together in a special add view to make things work programmatically. > Secondly, I'm interested in the possibility of building on top of sqlos > to make using SQLObjects one step more generic, i.e. creating SQLObject > classes from databases which in turn create interfaces which is all > patched together somehow with ZCML. The goal being that if you provide > a connection to a database you magically get a whole new set of > containers and types to add based on the structure of that database. It is possible to create a container that (upon creation) will create other enclosed objects. You will need to write a special AddView or use the nice initialization tool (have not tested this yet,but looks great) available from svn://svn.tiks.org/repos/Tiks/trunk/src/tiks/initializer. That part with creating SQLObject classes from a database structure: don't know :-) - Andreas From andreas at work.de Mon Nov 7 11:57:13 2005 From: andreas at work.de (Andreas Elvers) Date: Mon, 07 Nov 2005 11:57:13 +0100 Subject: [Z3-sqlos] Re: Different database connections for different sqlobject containers In-Reply-To: <20041009133644.GG15880@cotia.awkly.org> References: <20041009133644.GG15880@cotia.awkly.org> Message-ID: Sidnei da Silva wrote: > | Sidnei suggested I look in ConnectionDescriptor for a way to do this, > | but I couldn't figure out how to access any contextual information from > | there. Without the context I don't think there's a way to decide > | between different connections. > > If you look again, there's this code: > > try: > ut = zapi.getUtility(IConnectionName, context=context) > except ComponentLookupError: > .... > > This is where you could hook looking up a different connection. Or > even changing the getConnection method below. Or even better: if you > add a local connection, and keep the same name, it will pick your > local connection in preference to the global one. > I did exactly this. I added a local connection, kept the name. But when zope tries to queryUtility(IZopeDatabaseAdapter,name,default=None,context=context) it does not find the local local utility and return None instead. If I setup a static global rdb connection in configure.zcml then queryUtility will find it. But it will not find local utilities. - Andreas From jinty at web.de Sun Nov 13 22:22:51 2005 From: jinty at web.de (Brian Sutherland) Date: Sun, 13 Nov 2005 22:22:51 +0100 Subject: [Z3-sqlos] Removing the adding view Message-ID: <20051113212251.GA17062@minipas.home> I wrote a testbrowser based functional test for adding SQLObject to see what I could do about simplifying adding view. Then I realized that an INameChooser adapter was already defined. Then I realized that my new test still would pass if I removed the Adding View, as the default one does everything we need. So, am I not seeing something, or should I apply the following patch? Index: src/sqlos/container/__init__.py =================================================================== --- src/sqlos/container/__init__.py (revision 19685) +++ src/sqlos/container/__init__.py (working copy) @@ -13,27 +13,20 @@ import random from sqlobject import * -from sqlobject.main import CreateNewSQLObject from persistent import Persistent from zope.interface import implements from zope.component import IFactory from zope.app import zapi -from zope.app.event import publish -from zope.app.event.objectevent import ObjectCreatedEvent -from zope.app.container.interfaces import IContainer from zope.app.container.interfaces import IContained from zope.app.container.contained import ContainedProxy from zope.app.container.contained import Contained -from zope.app.container.browser.adding import Adding from zope.app.container.constraints import checkFactory from zope.app.location.interfaces import ILocation -from zope.proxy import removeAllProxies from zope.proxy import sameProxiedObjects from sqlos.interfaces import ISQLObject, ISQLObjectIsolated from sqlos.interfaces.container import ISQLObjectContainer from sqlos.interfaces.container import IIsolatedSQLContainer -from sqlos.interfaces.container import ISQLObjectAdding from sqlos import getFactory def contained(obj, parent=None, name=None): @@ -224,46 +217,3 @@ if self.container_id in obj.domains: return obj raise KeyError, name - - -class SQLObjectAdding(Adding): - """Custom adding view for SQLObject objects.""" - - implements(ISQLObjectAdding) - - def __init__(self, context, request): - super(SQLObjectAdding, self).__init__(context, request) - - def add(self, content): - container = IContainer(self.context) - klass = content.__class__ - klass = removeAllProxies(klass) - package = klass.__module__.split('.')[0] - className = klass.__name__ - id = content.id - name = '%s.%s.%s' % (package, className, id) - container[name] = content - return container[name] - - def action(self, type_name=''): - if not type_name: - raise UserError(_(u"You must select the type of object to add.")) - - if type_name.startswith('@@'): - type_name = type_name[2:] - - if zapi.queryView(self, type_name, self.request) is not None: - url = "%s/%s" % ( - zapi.getView(self, "absolute_url", self.request), - type_name) - self.request.response.redirect(url) - return - - content = zapi.createObject(self, type_name, CreateNewSQLObject) - publish(self.context, ObjectCreatedEvent(content)) - - self.add(content) - self.request.response.redirect(self.nextURL()) - - def namesAccepted(self): - return not ISQLObjectContainer.providedBy(self.context) Index: src/sqlos/interfaces/container.py =================================================================== --- src/sqlos/interfaces/container.py (revision 19685) +++ src/sqlos/interfaces/container.py (working copy) @@ -9,17 +9,12 @@ """ $Id: adapter.py 5212 2004-06-21 18:09:05Z philikon $ """ -from zope.interface import Interface, Attribute -from zope.schema import Choice -from zope.app.i18n import ZopeMessageIDFactory as _ +from zope.interface import Attribute from zope.app.container.constraints import ItemTypePrecondition from zope.app.annotation.interfaces import IAttributeAnnotatable -from zope.app.container.interfaces import IAdding from zope.app.container.interfaces import IContainerNamesContainer from zope.app.container.interfaces import IReadContainer, IContainer -from sqlos.interfaces import ISQLObject - class ISQLObjectReadContainer(IReadContainer, IAttributeAnnotatable): """ An SQLObject Container """ @@ -36,6 +31,3 @@ # TODO Attribute -> zope.schema.* - jinty container_id = Attribute("The id of the containers, this is a filter on the" "database table.") - -class ISQLObjectAdding(IAdding): - """A marker interface""" Index: src/sqlos/configure.zcml =================================================================== --- src/sqlos/configure.zcml (revision 19793) +++ src/sqlos/configure.zcml (working copy) @@ -16,18 +16,6 @@ - - - - - Index: src/sqlos/add.pt =================================================================== --- src/sqlos/add.pt (revision 19682) +++ src/sqlos/add.pt (working copy) @@ -1,75 +0,0 @@ - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Add Content
- - - -
- Folders are generic containers for content, including other - folders. -
-
- - - - Folder - Document -

- Documents are simple textual content. -

- - -
-
-
- - - -- Brian Sutherland Metropolis - "it's the first movie with a robot. And she's a woman. And she's EVIL!!" From sidnei at awkly.org Mon Nov 14 02:07:41 2005 From: sidnei at awkly.org (Sidnei da Silva) Date: Sun, 13 Nov 2005 23:07:41 -0200 Subject: [Z3-sqlos] Removing the adding view In-Reply-To: <20051113212251.GA17062@minipas.home> References: <20051113212251.GA17062@minipas.home> Message-ID: <20051114010741.GB4224@cotia> On Sun, Nov 13, 2005 at 10:22:51PM +0100, Brian Sutherland wrote: | I wrote a testbrowser based functional test for adding SQLObject to see | what I could do about simplifying adding view. | | Then I realized that an INameChooser adapter was already defined. | | Then I realized that my new test still would pass if I removed the | Adding View, as the default one does everything we need. | | So, am I not seeing something, or should I apply the following patch? +1 The adding view is from the time SQLObject had a weird API for constructing objects which I don't even recall anymore what it looked like. -- Sidnei da Silva Enfold Systems, LLC. http://enfoldsystems.com From jinty at web.de Tue Nov 15 03:33:03 2005 From: jinty at web.de (Brian Sutherland) Date: Tue, 15 Nov 2005 03:33:03 +0100 Subject: [Z3-sqlos] Problems with the NameChooser Message-ID: <20051115023303.GA9825@minipas.home> Hi all, I just documented this bug in the sqlos TODO.txt. I would solve it, but am quite unsure of how. * There is a bug related to SQLObject names. Most of sqlos thinks that the name of an object is equal to ${factory_id}.${sqlobject_id} where the factory id is set in ZCML. This mostly works fine and is quite unique. The only problem is in the Adding view, where the NameChooser guesses the name to be ${package}.${class}.${sqlobject_id}. This means that in order to use the adding view all sqlos:factory declarations have to have an id of this form or the Adding view will error when it tries container[name]. Unfortunately I cannot see an easy and correct way to get the factory id inside the NameChooser. I only have 3 bad ideas: * Use a different scheme for object names. i.e. something attached to the object itself. (tablename.sqlrow for instance), that way we could implement __name__ as a property. tablename is probably more unique than factory id. * Set the name on the object as it is created in the factory, the name chooser would then pick it up. * Some really evil fuzzy search (this is not really an option) Any ideas? Without a good one, we should probably just leave things as they are. -- Brian Sutherland Metropolis - "it's the first movie with a robot. And she's a woman. And she's EVIL!!" From jinty at web.de Sat Nov 26 13:02:47 2005 From: jinty at web.de (Brian Sutherland) Date: Sat, 26 Nov 2005 13:02:47 +0100 Subject: [Z3-sqlos] Re-organizing SQLOS code. Message-ID: <20051126120247.GA8624@minipas.home> Hi, There are a few proposed re-orginzations I would like to do to the sqlos code. Comments appreciated... 1. get rid of getFactory. in sqlos.__init__.py we have this: def getFactory(name, context=None, default=None): return zapi.queryUtility(IISQLObject, name, default=default, context=context) I think this is misleading, getFactory doesn't return a factory (i.e. something implementing IFactory). It gets registered SQLOS sub-classes. I propose to depreciate this and replace the few calls. This makes it absolutely clear to the code reader that they are querying a utility and not getting a factory. Also I propose that getUtility is called as most of the time returning None will result in a failure later. An immediate ComponentLookupError will make it clearer where bugs are. 2. Replace this: def allowedFactories(self): items = zapi.getFactoriesFor(ISQLObject, context=self) names = [name for name, factory in items] f = lambda name: (name, zapi.getUtility(IFactory, name)) factories = map(f, names) a = lambda f, container=self: (checkFactory(container, None, f[1]) and f[0] or None) return filter(None, map(a, factories)) with this: def allowedFactories(self): for name, factory in zapi.getFactoriesFor(ISQLObject, context=self): if checkFactory(self, None, factory): yield name I am pretty sure they do the same thing, except the second is more efficient (one less utility lookup per factory) and clearer. 3. In quite a few package we have the form container/__init__.py where __init__.py is the only file and is quite small. I want to move these to the form container.py. It is not likely that these modules will grow too much in the near future. -- Brian Sutherland Metropolis - "it's the first movie with a robot. And she's a woman. And she's EVIL!!"