[Zope3-Users] forbiddenAttribute on frozenset?!
I got the following error: ForbiddenAttribute: ('__rsub__', frozenset([20])) I hope I dont have to declare permissions built in classes?!? - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] doctest w/ formlib and ViewPageTemplateFile
Hello list, I was trying to run doctests on a formlib.EditForm-derived object, which uses ViewPageTemplateFile. The template then tries to access the object; and for testing I have override with a test template to exercise the object w/out too much html. To set up the doctest, I use zope.formlib.tests.formSetUp (which calls placelesssetup.setUp). However, I have problems in the zpt traversing from view to anything else. (I get a TraversalError because cannot adapt my object to ITraversable). (However, it works from a browser fine.) I notice that ().namespace/view is somewhere registered as an adapter for ITraversable. Is this what I need? Is there a convenience function somewhere to setup this and/or any other adapters I need to get ZPT running for doctests? Or how should I be doing my setup? Thanks, - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] zodb objects backup
It would be very nice if there were a faq or other doc addressing all of these scalability-related questions systematically for someone like me who understands what a relational database is doing for them (in return for squashing all their objects). It seems I'm not the only one with these concerns. :) Welcome to Open Source, we look forward to seeing your newly-written faq as it becomes available online ;-) Well, I've got enough info to write one by now... only, not having reviewed or tested the code, I couldn't actually vouch for it. But seriously, coming to Zope for an app server, I had no idea that ZODB was as robust as it seems to be. I think, from a marketing standpoint for the Zope corp (and other in the community deriving sustenance from providing zope-related products and services), it would make a lot of sense if they at least made the claim in a prominent place that ZODB was a serious candidate to replace a RDBMS if you didn't absolutely need SQL. Collecting the info together could be put on the todo list, but motivating people to seek it out would be a good first step. In the meantime, I had an idea about my current implementation: maybe instead of __getstate__ and __setstate__ I should put the external data in _v_data (marking as volatile). Then I could trap for its existence, and load if necessary; and also have an explicit refresh wired to a button in the GUI. Yup, this is exactly what _v_ was designed for... Great. - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] zodb objects backup
From: Tom Dossis [mailto:[EMAIL PROTECTED] Shaun Cutts wrote: But with replication, this issue is taken care of. (Too bad replication isn't part of the core functionality) Maybe soon.. http://hathawaymix.org/Software/PGStorage Great! Another potential issue on the scalability front I had forgotten about earlier: How do BTrees perform under lots of concurrent updates? (I know this is a tricky one, as implementations can get pretty complex to deal with this.) I note that http://www.zope.org/Wikis/ZODB/FrontPage/guide/node6.html#SECTION0006300 00 Says that As with a Python dictionary or list, you should not mutate a BTree-based data structure while iterating over it. Does this apply only to thread-local modifications or to any modification by anyone else? Ie, are BTrees versioned as the ZODB is... if I'm iterating over a BTree in my process (in ZEO, say), and another process modifies the BTree, does that sometimes show up in my copy, or only after commit? Also, wrt ConflictError -- is the BTree considered one object, or are the python objects (buckets, tree structure, ...) treated separately? In general, are the BTrees just written naively on top of ZODB, or do they interact in some special way with the storage? If they are just sitting on top of ZODB, it would seem that this dims the possibility that one could use the ZODB as a Postgres replacement. - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] zodb objects backup
On Sat, 2006-02-25 at 08:59 -0600, Andreas Jung wrote: --On 26. Februar 2006 01:52:29 +1100 Alen Stanisic [EMAIL PROTECTED] wrote: For some reason it doesn't feel completely safe just relying on Data.fs. That means what? Why shouln't it be safe...please come up with some reasonable arguments.. -aj I did mention that it could be because most rdb systems have a database and also keep transaction logs. In case of a failure you put the latest backup of the db and transaction logs together and you could rebuild your db to the point just before the failure. If you only had a daily back up of your db you could potentially lose a full day of transactions. One could also mention failover: if one computer with Data.fs goes down, you're down, period; whereas many RDBMSes support keeping slave copies of the database, which are then available. Also, there are ACID transactions (see http://en.wikipedia.org/wiki/ACID) in a good RDBMS. I don't know how zodb ensures consistency if there are multiple concurrent users, and can we rollback gracefully? ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] nextURL: add vs edit
Is there a reason why zope.app.form.browser.add.AddView defines: def nextURL(self): return self.context.nextURL() but zope.app.form.browser.editview.EditView doesnt? My redirection works for add but not edit, and this is the reason. Is this a feature or a bug? If a bug, all that needs to happen is that nextURL get moved to EditView from AddView, as EditView is base for Add. But perhaps there is a reason for this I dont understand? - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] nextURL: add vs edit
Ok, In AddView.update, self.request.response.redirect(self.nextURL()) is called, but this is not called in EditView... so change isn't as simple as moving nextURL. However, if you put this line into EditView.update as well as moving nextURL, then my redirect works fine. But does this break anything else? Is there some reason why the editview doesn't do redirect? I have gotten offlist feedback that I'm not the only one interested in this Thanks, - Shaun -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shaun Cutts Sent: Friday, February 17, 2006 1:17 PM To: Zope3-users@zope.org Subject: [Zope3-Users] nextURL: add vs edit Is there a reason why zope.app.form.browser.add.AddView defines: def nextURL(self): return self.context.nextURL() but zope.app.form.browser.editview.EditView doesn't? My redirection works for add but not edit, and this is the reason. Is this a feature or a bug? If a bug, all that needs to happen is that nextURL get moved to EditView from AddView, as EditView is base for Add. But perhaps there is a reason for this I don't understand? - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] nextURL: add vs edit
Ok -- Thanks Gary and Michael. I've defined changed in my mixin, and it works: def changed( self ): self.request.response.redirect(self.nextURL()) And I can still use the same mixin to do redirect for both edit and add forms, so I can't grumble about that. I'm curious how this works, however, since EditView.changed() doesn't call self.context.changed(). Who calls it? Thanks again, - Shaun PS I will indeed use formlib eventually, but I want to get just the workflow down for the prototype I'm writing at the moment. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] nextURL: add vs edit
On Behalf Of Garanin Michael What is mixin? Is it content-object or view? Well, I think in the wider python context mixin is something that you can use as a base class to extend the functionality of your class, assuming you provide some standard interface. (e.g. UserDict.DictMixin.) I'm not sure whether zope uses mixin exactly like this, or whether it extends mixin for something that you don't have to have in the class hierarchy, but acts as if it were because of traversal (so perhaps: An instance is give a special base class of its own that defines __getattr__ and uses it to search for missing methods in the wider context? I don't know but I'm a bit wary of the traversals without more study. They seem to be playing with normal python resolution in a way that isn't clear to me.) In this case, I got the term from the ++apidoc++ for the zcml editform.class attribute: A class to provide custom widget definitions or methods to be used by a custom template. This class is used as a mix-in class. As a result, it needn't subclass any special classes, such as BrowserView. And so, my mixin is indeed a view... or at least, it acts like a view. But I'm a bit hazy on how it is actually constructed and where it is wrt the EditView object. Is the factory (the class I pass in editform.class) passed in bases to SimpleViewClass(... ) in zope.app.forms.browser.editview.EditViewFactory? Then the EditView and my mixin are both bases of a specially constructed BrowserView derivative? That's my best guess without more study of the code. - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] question: can I make a view trusted?
Ah, Here's something to note: When I print out the schema objects just before attempting to access their titles, I get: --- zope.schema._bootstrapfields.Int object at 0x022E4490 zope.schema._bootstrapfields.TextLine object at 0x022E4470 zope.schema._bootstrapfields.TextLine object at 0x022E4430 zope.schema._bootstrapfields.TextLine object at 0x022E42D0 zope.schema._field.Date object at 0x022E44D0 2006-02-16T23:20:35 ERROR SiteError... --- In other words, I have no problem accessing the fields of the schema objects that are defined in _bootstrapfields, but I get an error when I access Date, which lives in _field! I defer to those who know more, but whether I'm supposed to be allowed to access the title or not, the current behavior seems like a bug, as it is inconsistent. - Shaun Cutts ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] question: can I make a view trusted: A BUG
Ok everyone: it is a zope bug. The following should be included in zope.app.schema.fields.zcml: content class=zope.schema.Date factory id=zope.schema.Date title=Date Field description=Date Field / require like_class=zope.schema.Orderable / require like_class=zope.schema.Field / /content PS -- Jim -- I sent in my contributor form almost two weeks ago? Have you received it yet? I'd be happy to put this in myself, if I could. - Shaun ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] What attributes are made persistent
Well, one could have a base class along the lines of class PersistSetItemOnAttributes: def __setattr__( self, attr, val ): oldSI = val.__class__.__dict__.get( '__setitem__', None ) if oldSI is not None: def newSI( vself, vattr, vval ): vself._p_changed = True # is this the right member? oldSI( vattr, vval )# oldSI is bound: no vself? val.__class__.__setitem__ = newSI super( PersistSetItemOnAttributes, self ).__setattr__( attr, val ) Of course, this is really just pseudocode. For one thing, need to trap whether 'val' is really a class. For another if you were serious about this, you would want to check if the obj wasn't persistent first, and you might want to do it recursively. And while your are at it, you might want to check on other mutators as well(for instance, check first what sequence interface if any 'val' supports...) ... sounds like too much work, and would be problem prone even so. After all, some things you don't want to be persistent! - Shaun -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stephan Richter Sent: Wednesday, February 15, 2006 8:43 AM To: zope3-users@zope.org Cc: Florian Lindner Subject: Re: [Zope3-Users] What attributes are made persistent On Wednesday 15 February 2006 08:21, Peter Bengtsson wrote: class PersistentAnything(PersistentMapping, PersistentList, PersistentDict): AA! This is so wrong! It merges two incompatible APIs: collections and mappings. The non-persistent equivalent to this is: class DoEverything(set, list, dict): ... pass Am I just trying to make it too simple? I think you try far too hard to not understand why the persistent mechanism works as it does. You make your life harder than it has to be. Regards, Stephan -- Stephan Richter CBU Physics Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] newbie design questions for UI to external data
Gary, Thanks for the reply. On Feb 13, 2006, at 10:33 PM, Shaun Cutts wrote: Um... I guess I must have asked too many questions at once :) :-) and this is still a bit much for me. I've implemented a first pass of a container for external data and got it working on some of my collections. I've included the (first pass of the) base DBContainer and DBContained objects for criticism, and would be very grateful if anyone would like to take a crack at it. It looks like an interesting approach--more low-level than I would have expected for a first cut, and *maybe* more low-level than necessary. I wish I had more time to look at it. If there were anything more higher-level, I would be happy I will eventually be needing paged collections to, though, so I can't give up too much control. Keep in mind, this is my first time working with the system, so I'm sure I'm going about some things the wrong way. In particular, I already think: 1) Instead of have the contained object update the container, I should rely on the event notification system. Events are a tool for disconnected notification. calling a method on an object is sending a message directly to the interested party. Not everything should be an event. If a communication between two components is a core aspect of your design, maybe direct method calls are more appropriate. The problem now is that the default edit view uses __setitem__ for the contained object, so I get one db update per column, whereas (I hope!) the event is fired after all the column updates are complete. Not a problem for the prototype, but maybe annoying in production system when Postgres is busier with other users as well. Of course, I may be overriding the default edit view anyway So the problem isn't the coupling between DBContained and DBContainer per se. Its sort of like I want the editView to enforce a transaction protocol, and want to use the Event as a proxy for commit. Note: I don't think I want dirty object in the system; otherwise I could use a lazy protocol where the container just checks -- say at demarshalling time (but probably on shutdown at least, if we are interrupted?) -- whether it has any updates to write. If I did want to go to a lazy protocol, is there a way to register things for getting triggered on shutdown. 2) Right now, the system works by translating objects at the border (in IExternalContainer). Some translation is necessary, for instance, to move from mx.DateTime to datetime.datetime, but still I think I should somehow be making use of the adaptor interface. If there's not an object to adapt then you have to start somewhere. My glance at the code seemed to show that you were making a reasonable choice. Another approach might be to have an abstract row object that could represent any columns (a dict or something), and named adapters registered for the row interface plus the name of the generating table. I dunno, do what your app needs and refine it as you discover what works. I actually do have a row object from my database code... but (as I learned) it is a bit of a pain to use directly, since: 1) datatypes are somewhat non-standard (dates, particularly), and 2) it is a bit messy to use with annotations because Row uses __getattribute__, though this is probably a design flaw in the Row class hierarchy. My thought was that I might want to be adapting my row objects (or their interfaces to be precise). Indeed, I am, but in a nonstandard way, as IExternalDatabase-derivatives do the translation. My plan now is: have the DBContained base class be a protoadapter that does all the column datatype translations and validation; its subclasses will adapt specific Row-derived classes, which have concrete sets of columns. I guess there is no particular machinery to use to present this pattern: one hierarchy adapts another hierarchy? 3) Along these same lines, IDBContainer._containedType should really be an interface (Object( schema = IDBContained )) Note: is there a tutorial on writing containers anywhere I should have read? I mainly figured this out by banging on it and fishing around in the code. I'd love to figure out, for instance, what is really happening with the traversals (with some interaction diagrams). I do think it was harder than it should have been. (But, then again, I think that about most things...:)) Don't know of a tutorial. Sounds like you are interested in traversal, though, which is different. Look at zope.app.traversing, or zope.app.container.traversal. The headline is that there are two kinds of traversal: URL path traversal and TALES path traversal. They have different adapters. When debugging, I had a lot of problems understanding what was happening because I didn't understand how traversal was trying to get data... It would just be nice to have more design doc -- especially interaction diagrams -- to refer
RE: [Zope3-Users] newbie design questions for UI to external data
Um... I guess I must have asked too many questions at once :) I've implemented a first pass of a container for external data and got it working on some of my collections. I've included the (first pass of the) base DBContainer and DBContained objects for criticism, and would be very grateful if anyone would like to take a crack at it. Keep in mind, this is my first time working with the system, so I'm sure I'm going about some things the wrong way. In particular, I already think: 1) Instead of have the contained object update the container, I should rely on the event notification system. 2) Right now, the system works by translating objects at the border (in IExternalContainer). Some translation is necessary, for instance, to move from mx.DateTime to datetime.datetime, but still I think I should somehow be making use of the adaptor interface. 3) Along these same lines, IDBContainer._containedType should really be an interface (Object( schema = IDBContained )) Note: is there a tutorial on writing containers anywhere I should have read? I mainly figured this out by banging on it and fishing around in the code. I'd love to figure out, for instance, what is really happening with the traversals (with some interaction diagrams). I do think it was harder than it should have been. (But, then again, I think that about most things...:)) BTW in my humble opinion, ILocation.__name__ is not well named. When I first got an error referring to __name__ I thought it was expecting a class object. And what happens when, for some strange reason, someone wants to put a class in a container, and doesn't like its default name? Thanks, - Shaun - class IExternalContainer( Interface ): an external container interface. def add( obj ): add 'obj' def update( obj ): update obj def delete( obj ): delete obj def connect( obj ): establish a connection to external database def __iter__( ): iterates through external objects class IDBContainer( IContainer, ILocation ): container that lives in zope, but contains objects made persistent by an external container. _database = Object( schema = IExternalContainer ) _containedType = Attribute( type of object contained ) def __setitem__( key, obj ): Add a IDBContained object. def _updateItem( key, newKey = None ): notify that object has been modified. If the key has been changed, 'key' should be the old key of the object, and 'newKey' should be set to the new key. def __delitem__( key ): delete item, removing it both from this view and from external storage. def getAttributeNames(): get names of attributes of contained object class IDBContained( IContained, ILocation ): Contained in IDBContainer. Must notify its parent if it is changed. Because of this, it must also know how to get its key. __parent__ = Field( constraint = ContainerTypesConstraint( IDBContainer ) ) def getZopeKey(): return ascii str or unicode key. IDBContainer[ '__setitem__' ].precondition = ItemTypePrecondition( IDBContained ) class DBContainer( IterableUserDict, Contained ): Implements L{IDBContainer} from zope.interface.verify import verifyClass verifyClass( IDBContainer, DBContainer ) True implements( IDBContainer ) # prevent browser from choosing name nameAllowed = False # defaults for IDBContainer _database = None _containedType = None # defaults for ILocation (base of IDBContainer) __parent__ = None __name__ = None def __init__( self ): super( DBContainer, self ).__init__( ) self.__setstate__() def _filterKey( self, newKey ): check that key is ascii string or unicode, and convert to unicode. if newKey is None: TypeError( key can't be None ) elif isinstance( newKey, str ): try: newKey = unicode( newKey ) except UnicodeError: raise TypeError(name not unicode or ascii string) elif not isinstance( newKey, unicode ): raise TypeError( key '%s' must be ascii or unicode string % repr( newKey ) ) return newKey def __setitem__( self, key, obj ): Implements L{cranedata.web.interfaces.IFundContainer.__setitem__}. key = self._filterKey( key ) if not isinstance( obj, self._containedType ): raise TypeError( object '%s' must be a %s % ( repr( obj ), self._containedType.__name__ ) ) self._database.add( obj ) setitem( self, self.data.__setitem__, key, obj ) def __getitem__( self, key ): return self.data[ self._filterKey( key ) ] def __delitem__( self, key ): obj = self.data.pop(
[Zope3-Users] newbie design questions for UI to external data
Hello, I'm trying to write a zope3 UI for data in an RDBMS with python business logic. (Hence updates shouldn't go directly to the database; queries are probably best off using the marshalling code in business logic as well, but could use direct query if its especially easy.) I was trying to adapt Stephan Ritcher's Zope3 book examples, but am getting a bit snarled with escaping from/interacting with the ZODB. For a collection of objects that live in the DDBMS, should I try to implement a collection object that itself lives in the ZODB (inherits from Persistent, implements IContainer), but really performs a query to get its data? Then I need to mark actual contents volatile (?) Is there a hook to set the volatile contents? Also, it would be good to have a simple admin object in the ZODB that has DB connection info. Putting one there and making it accessible via Zope3 seems easy enough -- just inherit from Persistent But how do I access this info from, say, my collection object(s). Does Persistent generate a standard key? Or should I have one big database object in ZODB that has attributes for the connection, and also attributes for each of the collections. This seems easy enough, but then I wonder if the zcml config will become tricky, as I would have to declare forms for attributes of instances (somehow)? When using the standard forms, I got errors for not setting __name__ and __parent__ on my contained objects. The first was easy enough, but who is supposed to set __parent__? I want to use standard forms if possible for the moment, as I am trying to get up a prototype fast. Eventually I will need a paged view. Is there one out there to use? In general, if there is a good example of something like I am trying to do, I would be grateful if someone could point me to it. - Shaun Cutts ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users