Re:[Zope] help with magic method "__of__"
Hi, I've been playing around with Confera for about 4 weeks now -- but I'm not the original developer nor am I an employee of Digital Creations (hint!hint!) so <YMMV>take the following with a grain of salt</YMMV>. On April 11, 1999 "Karl & Mel" <llwo@dbtech.net> wrote:
I know that Confera is not supported, but I am using it as a base for an = extended version that would allow messages to be moved, reordered, = copied, paseted, etc. In otherwords turn Messages into folderish? = containerish? objects. I don't want to give up the indexing and = searching though. Which leads me to believe that I need to override the = 'setItem' and '__getitem__' maybe?
I think you'd probably need to add methods in the Message/Topic classes to remove a child message (i.e. id in the intSet self.ids) (this would be to implement a <cut> function) and reattaching itself to another message or topic (to implement a paste function) You can *probably*(just a guess, I haven't fiddled around too much with this) use the setitem to paste messages to another message but it does'nt have to do the indexing because it would already have been indexed when it was added, but it also has to handle reorganizing the thread field of the message you are moving so that these reflect the new paths (note that if the message being moved has children (i.e. replies), their thread fields also have to be updated and so on recursively) I don't know why you'd have to modify __getitem__ though. In the cut function, you can probably base it on the delItem function (just take out the unindexing and delete object parts) As for the other functions (reodering,etc.), I don't have enough info to suggest anything...
Anyway
As I've been reading the code over and over and over (two weeks now) and = have thrown out three attempts. I keep seeing things like
self.data[id].__of__(self) msg=3Dmsg.__of__(self) r=3Dmap(lambda x, p=3Dself: x.__of__(p), r)
How does the magic method '__of__()' work?
Also how does intSet{} work?
ta for any info.
Grab the code in the Zope CVS area. If you're on Windows, theres a nice gui front end called WinCvs (http://www.wincvs.org) that allows you to mirror the entire Zope source distribution on your local drive. The reason for this is that the definitions of IntSet and the magic __of__ methods are defined in the c modules which are included in the source distribution (see Acquisition.c and intSet.c). AFAIK, obj.__of__(self) attaches your object (obj) to the Acquisition hierarchy (of which the self object is already a part of) so that it becomes accessible as a URL in Zope ...In Zopish, this is known as '*wrapping* the object into an acquisition wrapper'... If this is not as clear as it should be it's because I'm not that exactly sure of it myself :( Maybe somebody from DC or the original Confera developer can confirm this... HTH. Butch Landingin P.S. If you do get around to implement those things -- maybe you can send me some of the source code to see. I'm trying to finish up 0.1 version of a Zope Product that's based on Confera that implements a SlashDot-like website and I might be able to use some of the code you have <ain't Open Source great? ;)>. _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Thanks for the info. Kinda what I thought after staring at it some more. See below for what I came up with over the weekend. I think it is pretty sound and will test it today. class Topic ... ...<original stuff> ... def manage_copy(self, ids[], paste_id='', REQUEST=None): """A mangement interface for copying messages. Scenario: Topic Msg-1 *ids Msg-3 Msg-4 *ids Msg-5 Msg-2 *paste_id Msg-6 Result of Copy: Topic Msg-1 Msg-3 Msg-4 Msg-5 Msg-2 Copy-of-Msg-1 Copy-of-Msg-3 Copy-of-Msg-4 Copy-of-Msg-5 Msg-6 Notice that mesages selected in ids become branches. This is the intended result. There will also be a complimentary manage_move() that will copy then delete the mesages listed in ids. """ data=self.data ids=map(atoi, ids) for id in ids: # not sure about namespace of root_object so set this inside loop if paste_id != '': paste_id=atoi(paste_id) root_object=data[paste_id] else: root_object=self copyItems(id, root_object, ids) def copyItems(self, id, root_object, branches) data=self.data item=data[id] # Start copy title=item.title author=item.author body=item.body email=item.email notify=item.notify file=item.file submit=' Add ' # Make new message in root_object root_object.addMessage(title, author, body, email, notify, file, submit) for id in item.ids: if id not in branches: self.copyItems(id, item, branches) I also remembered about the CVS thing after I sent the message. That was a big help in deciding how to do the copy. I couldn't just move a message becaues of the line that says msg=msg.__of__(self). The original ID is bound in the namespace to it's parent so easy enough to just self.addMessage to create a new id and binding in the new spot, then delete the old messages. Not done yet, but the paste_id is selected by a modified Topic_manage_messages.dtml <INPUT TYPE="CHECKBOX" NAME="ids:list" VALUE="<!--#var id-->"> <INPUT TYPE="RADIO" NAME="paste_id" VALUE="<!--#var id-->"> at both places where it appears. Also still need to do some error checking so that a paste_id in the ids.sub_id (mangle) will raise an idiot error. I am psyched that I grok ;-) now. Zope rulz I don't quite know how to produce a patch but I will post all of the changes when I have them complete and working. Should be a couple of days. Karl ----- Original Message ----- From: Butch Landingin <butchland@yahoo.com>
Hi, I've been playing around with Confera for about 4 weeks now -- but I'm not the original developer nor am I an employee of Digital Creations (hint!hint!) so <YMMV>take the following with a grain of salt</YMMV>.
On April 11, 1999 "Karl & Mel" <llwo@dbtech.net> wrote:
I know that Confera is not supported, but I am using it as a base for an = extended version that would allow messages to be moved, reordered, = copied, paseted, etc. In otherwords turn Messages into folderish? = containerish? objects. I don't want to give up the indexing and = searching though. Which leads me to believe that I need to override the = 'setItem' and '__getitem__' maybe?
I think you'd probably need to add methods in the Message/Topic classes to remove a child message (i.e. id in the intSet self.ids) (this would be to implement a <cut> function) and reattaching itself to another message or topic (to implement a paste function)
You can *probably*(just a guess, I haven't fiddled around too much with this) use the setitem to paste messages to another message but it does'nt have to do the indexing because it would already have been indexed when it was added, but it also has to handle reorganizing the thread field of the message you are moving so that these reflect the new paths (note that if the message being moved has children (i.e. replies), their thread fields also have to be updated and so on recursively)
In the cut function, you can probably base it on the delItem function (just take out the unindexing and delete object parts)
As for the other functions (reodering,etc.), I don't have enough info to suggest anything...
participants (2)
-
Butch Landingin -
Karl & Mel