Re: [Zope-dev] AttributeError validate using the Visitor pattern

2001-02-23 Thread R. David Murray

On Mon, 19 Feb 2001, Itai Tavor wrote:
 You posted your questions 3 days ago, so maybe you found a solution 
 by now... but this might still be useful to you.

I just unwrapped the visitor pattern into an psuedo-case statement grin.

 - I'm passing _ explicitly instead of relying on binding. I vaguely 
 recall reading something about a problem binding the namespace. It 
 might be fixed in the latest Python Scripts, I haven't tried the CVS 
 version yet.

This appeared to be the key.  I changed my 'accept(me)' call to
read 'accept(me,_=_)', and everything started working.  Thanks
very much!

 - visitLineItem is called in the context of an OrderLineItem, so no 
 dtml-with item is needed.

I had actually tried that and gotten an even less intelligable error
message.  So now I've reverted to that form and it works great.

 - If you wanted the visitor to implement looping over the items 
 (which is how the GoF do it) you could easily make something like:
 
  Order.displayItemsVisitor.displayItems (DTML Method):
  dtml-in line_items
tr
  dtml-var "_['sequence-item'].accept(container, _)"
/tr
  /dtml-in

Yeah, that's more or less what I do.  My display dtml-method gets passed the
list of objects, and it does the loop (implementing the batching logic
for dtml-in) calling accept on the items in the list.  I need to rename
my folder to make it's purpose clearer, though grin.

 BTW, I never thought of using a visitor for this until you brought it 
 up, so thanks! What I really like about it is that the same 'accept' 
 method can be used by multiple visitors, each one implementing a 
 different view of the object. So I can have displayItemsVisitor, 
 displayItemsCompactVisitor, and displayItemsEditableVisitor, all 

Yeah, exactly.  displayItemsEditableVisitor is why I chose to
implement the visitor pattern.  I've wound up doing it another
way (checking the auth of the logged in user and putting in a button),
but I suspect I'll have another Visitor before I'm through with the
project.

Thanks again for your help.

--RDM


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] AttributeError validate using the Visitor pattern

2001-02-18 Thread Itai Tavor

Hi David,

You posted your questions 3 days ago, so maybe you found a solution 
by now... but this might still be useful to you.

I just implemented a visitor similar to yours, with a few changes. It 
involves the following objects: Order and OrderLineItem. I created a 
Folder named 'displayItemVisitor' in Order containing:

Order.displayItemsVisitor.displayItem (Python Script):
 paramsitem/params
 return item.accept(container, _)

Order.displayItemsVisitor.visitLineItem (DTML Method):
 tddtml-qty;/td
 td class="price"dtml-var "getRetailAmount(qty, 
in_basket_date)" fmt=dollars-and-cents/td

The 'accept' method of OrderLineItem is:
 paramsvisitor, _/params
 return visitor.visitLineItem(container, _)

And the whole thing gets used in the DTML method that displays an order, using:
 dtml-in line_items
   dtml-var "displayItemsVisitor.displayItem(_['sequence-item'], _)"
 /dtml-in

Interesting points:

- I'm passing _ explicitly instead of relying on binding. I vaguely 
recall reading something about a problem binding the namespace. It 
might be fixed in the latest Python Scripts, I haven't tried the CVS 
version yet.

- visitLineItem is called in the context of an OrderLineItem, so no 
dtml-with item is needed.

- If you wanted the visitor to implement looping over the items 
(which is how the GoF do it) you could easily make something like:

 Order.displayItemsVisitor.displayItems (DTML Method):
 dtml-in line_items
   tr
 dtml-var "_['sequence-item'].accept(container, _)"
   /tr
 /dtml-in

BTW, I never thought of using a visitor for this until you brought it 
up, so thanks! What I really like about it is that the same 'accept' 
method can be used by multiple visitors, each one implementing a 
different view of the object. So I can have displayItemsVisitor, 
displayItemsCompactVisitor, and displayItemsEditableVisitor, all 
calling item.accept(), and I avoid polluting my OrderLineItem class 
with multiple view methods. OTOH, it requires adding public access 
methods to OrderLineItem, because a view method in OrderLineItem can 
do dtml-var price, while the visitor must do dtml-var 
"getPrice()". Oh well, there's always a price to pay ;-)

HTH, Itai

R. David Murray wrote:

OK, having helped me figure out how to work around the bug in accessing
ZPatterns objects from a catalog, I've got a new challenge for you all.

Now that I've got my list of objects, I want to generate a web page displaying
them.  The page has the structure of a series of table rows.  Inside each
row data about a single object is displayed, using a common format but
with certain differences depending on the type of object.  To implement this,
I am trying to use the Visitor pattern from the Gang of Four book.

So, I have a Folder displayItemList.  This folder contains (at the moment)
three methods: displayTable, visitAuthor, and visitBook.  displayTable
generates the html for the outer table, down to the tr/tr tags.
Between those tags, it calls dtml-var "accept(me)", where me is
this() for the displayTable method, and accept is a pythonscript method
defined on each of the object type's Specialist.  Each accept method
is of the form:

return visitor.visitBook(None,_,item=context)

with _ bound to namespace on the bindings tab and 'visitor' being listed
in the arguments line.

visitBook begins with the line:

dtml-with item

Trying to display my list, I get an AttributeError on 'validate', and
ZDebug flags the 'with' line as the error location.  validate
appears nowhere in my code, so from all I can figure from a certain
amount of inspection of the source, Zope is looking for this method
on the DTMLMethod and not finding it.

ZDebug says the namespace stack consists of a single entry, which looks like
the DTMLMethod itself (visitBook, presumably).  Seems to me the namespace
stack should be deeper than that.

I've been poking at this for a couple hours now without making any more
progress, so I'm going to quit for the day and come back to it tomorrow.
If anybody has any bright ideas, or sees something obvious I'm doing wrong,
please clue me in.  Thanks!

By the way, I also tried making accept be visitor.visitBook(context,_),
but that produced the same error and ZDebug could only point to the
call to accept as the error location.

--RDM
-- 
--
Itai Tavor  -- "Je sautille, donc je suis."--
[EMAIL PROTECTED]--   - Kermit the Frog --
-- --
-- "If you haven't got your health, you haven't got anything"  --


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] AttributeError

2001-02-16 Thread Andre Schubert

Hi Alex,

i have the following Products installed, and i don't use External Methods

ExternalMethod (Installed product ExternalMethod (External Method-1-0-0))
Hotfix_2000-12-08 (Installed product Hotfix_2000-12-08)
Hotfix_2000-12-15a (Installed product Hotfix_2000-12-15a)
Hotfix_2000-12-18 (Installed product Hotfix_2000-12-18)
MIMETools (Installed product MIMETools)
MailHost (Installed product MailHost (MailHost-1-2-0))
OFSP (Installed product OFSP (OFSP-1-0-0))
SiteAccess (Installed product SiteAccess (SiteAccess-2-0-0))
ZCatalog (Installed product ZCatalog (ZCatalog-2-2-0))
ZGadflyDA (Installed product ZGadflyDA)
ZMySQLDA (Installed product ZMySQLDA (ZMySQLDA-1-1-4))
ZPyGreSQLDA (Installed product ZPyGreSQLDA (ZPyGreSQLDA-0-0-3))
ZRTChat (Installed product ZRTChat)
ZSQLMethods (Installed product ZSQLMethods)
ZopeTutorial (Installed product ZopeTutorial (Zope Tutorial 1.0))
mysqlUserFolder (Installed product mysqlUserFolder
(mysqlUserFolder-0.5.2))

as

Steve Alexander schrieb:

 Andre Schubert wrote:

 
  Could anyone help me to solve the following Error that occurs sometimes.
 
  2001-02-16T09:11:42 ERROR(200) ZODB Couldn't load state for
  '\000\000\000\000\000\0008\004'
  Traceback (innermost last):
File /usr/share/Zope-2.2.4/lib/python/ZODB/Connection.py, line 443, in
  setstate
  AttributeError: 'None' object has no attribute 'load'
 
  Q: How can a find out wich object affected, by id or path or somewhat
  else ??
 Andre,

 What products do you have in your Zope installation?

 Are you using any External methods?

 This sounds like something has written something to the ZODB that
 shouldn't be written there.

 --
 Steve Alexander
 Software Engineer
 Cat-Box limited
 http://www.cat-box.net

 ___
 Zope-Dev maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  **
 (Related lists -
  http://lists.zope.org/mailman/listinfo/zope-announce
  http://lists.zope.org/mailman/listinfo/zope )


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] AttributeError: __call__

2000-10-05 Thread Chris Withers



knight wrote:
 
 I just installed a fresh copy of 2.2.1 also, and I'm getting the same
 issue. Any items starting with a subfolder has a __call__ AttributeError.

What do you mean by 'starting with a subfolder'?

Can you give some exampels and a full traceback?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] AttributeError: __call__

2000-10-05 Thread knight

Chris,

Ofcourse, the phenomina disappeared abruptly. However, I intend on using
2.2.2 again within minutes, so I will post a detailed message if the
phenomina occurs again.

Regards,

Knight
[EMAIL PROTECTED]

On Thu, 5 Oct 2000, Chris Withers wrote:

 
 
 knight wrote:
  
  I just installed a fresh copy of 2.2.1 also, and I'm getting the same
  issue. Any items starting with a subfolder has a __call__ AttributeError.
 
 What do you mean by 'starting with a subfolder'?
 
 Can you give some exampels and a full traceback?
 
 cheers,
 
 Chris
 
 ___
 Zope-Dev maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  **
 (Related lists - 
  http://lists.zope.org/mailman/listinfo/zope-announce
  http://lists.zope.org/mailman/listinfo/zope )
 
 


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )