[Zope] Re: meta_type in DTML returns incorrect type
Dario Alcocer
alcocer at helixdigital.com
Fri Jan 2 18:11:13 EST 2004
Dieter Maurer wrote:
> Dario Alcocer wrote at 2004-1-1 13:47 -0800:
>
>>I'm working with the AddressBook example from the book, "Zope Bible".
>>The example uses the following to conditionally display an edit link for
>> an AddressBook entry in the object's index_html (rendered via a
>>DTMLFile() object):
>>
>><dtml-if "meta_type=='AddressBook Entry'"> | <a
>>href="./editEntryForm">Edit Entry</a></dtml-if>
>>
>>However, this never renders an "Edit Entry" link because meta_type's
>>value is 'AddressBook' (i.e. the type of the containing object) and not
>>the expected value 'AddressBook Entry'. I've verified this by printing
>>out the type of self.meta_type.
>
>
> This means:
>
> either your "index_html" is "applied" to the "AddressBook"
> (and not an entry)
I'm not sure what you mean, but the object *should* be an Entry object.
The AddressBook class supports an addEntry method; the entries are
store in a dictionary kept by AddressBook:
class AddressBook(SimpleItem):
"An AddressBook object"
meta_type = "AddressBook"
def addEntry(self, FirstName = "", MiddleInitial = "",
LastName = "", REQUEST = ""):
"Method to add entry to an AddressBook"
id = self.LastEntryID = self.LastEntryID + 1
id = str(id)
entry = Entry(id, FirstName, MiddleInitial, LastName)
self.Entries[id] = entry
self.__changed__(1)
class Entry(Item, Persistent, Implicit):
"Address Book Entry"
meta_type = "AddressBook Entry"
def __init__(self, id, FirstName, MiddleInitial,
LastName):
self.id = id
self.editEntry(FirstName, MiddleInitial, LastName)
index_html = DTMLFile('dtml/entryDetails', globals())
Does it matter that Entry inherits from Item and not from SimpleItem?
Maybe the fact that Implicit is a base class means that meta_type is
acquired from AddressBook.
> or an "AddressBook Entry" does not have a "meta_type" attribute.
Nope, as you can see from above, the Entry class does in fact have a
meta_type member.
Any other hints you might have will be greatly appreciated.
More information about the Zope
mailing list