changing ZClass properties from a PythonScript
Hi everyone, I've built a simple ZClass for publishing news items on my site. The news articles have a "teazer" property for holding a short attention-getting paragraph and an optional "body" property for the full article. When displaying the news on the site, the teazer paragraph is displayed and if a body exists, a "Read more..." link is displayed. No problem there. I'm using a boolean property called "readmore" that determines whether the link is displayed or not. I use a PythonScript to add the instance and I'm trying to figure out how to set the "readmore" property depending on whether any text has been entered in the body field. Here's what I have so far: ## Script (Python) "NewsClass_add" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title=Add a NewsClass instance ## REQUEST = container.REQUEST newsitem = container.NewsClass.createInObjectManager(REQUEST['id'], REQUEST) newsitem.propertysheets.Basic.manage_editProperties(REQUEST) if REQUEST.has_key('body'): newsitem.propertysheets.Basic.manage_changeProperties(REQUEST, readmore=TRUE) else: newsitem.propertysheets.Basic.manage_changeProperties(REQUEST, readmore=FALSE) newsitem.reindex_object() RESPONSE = REQUEST.RESPONSE if REQUEST.has_key('DestinationURL'): return # following line wrapped in my email RESPONSE.redirect(REQUEST['DestinationURL']+'/manage_workspace') return RESPONSE.redirect(REQUEST['URL2']+'/manage_workspace') Should I be using manage_addProperty instead. I've tried a bunch of different approaches. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.com
Tim Wilson writes:
.... I'm using a boolean property called "readmore" that determines whether the link is displayed or not. I use a PythonScript to add the instance and I'm trying to figure out how to set the "readmore" property depending on whether any text has been entered in the body field. Here's what I have so far: ... if REQUEST.has_key('body'): newsitem.propertysheets.Basic.manage_changeProperties(REQUEST, readmore=TRUE) else: newsitem.propertysheets.Basic.manage_changeProperties(REQUEST, readmore=FALSE) What happens?
I would expect a "NameError" as "TRUE" and "FALSE" are not predefined names (use "1" for "TRUE" and "0" for "FALSE"). Then, I would expect that "REQUEST" always has the key "body". It just may be empty or not. Thus, you should probably use: if REQUEST.get('body'): .... More optimizations possible.... Dieter
participants (2)
-
Dieter Maurer -
Tim Wilson