Python Script HowTo (WAS: How do I get the value of an object with python?)
Hi First it's great to be back on the list..... Had some problems for a few days. As Dieter pointed out I was not very clear in what I was trying to accomplish. (All my posts to this point have been related - as well as the post by davis@mccalldesign.com - which seems very similar...) Heres what I have: 2 ZClasses StyleBook (Inherits from Folder) | | | |---StyleSheet (Inherits from DTML Document) Unique title Property specifying when to use styletype Property specifying where to use At this point I can successfully create the StyleBook instance and add StyleSheet instances with the correct properties and through the ZMI, reset and/or view the results of those properties at will..... Now, I am trying to: * Via Python, collect all instances of StyleSheet that exist in StyleBook (via unique object ID) * Via Python, look at the title and styletype properties of each StyleSheet instance and compare them against my query arguments * If I find a match, return all the Property values(potentially 47+) of the particular StyleSheet instance (that are not empty strings) in a CSS Format. I cannot find any good *simple* howto examples of doing this with python. (With DTML I can do it, but it is very messy... Though I'm just learning Python, I would like to do it with python) Hope this makes sense......and Thanks for listening WPH
Bill Hewitt wrote:
* Via Python, collect all instances of StyleSheet that exist in StyleBook (via unique object ID)
Since your StyleSheet is a Folder, you should be able to use 'objectIds' and company with a meta-type argument. I'm not sure what your parenthesized bit means.
* Via Python, look at the title and styletype properties of each StyleSheet instance and compare them against my query arguments
The 'title' should be accessible as a simple attribute. I presume that 'styletype' is defined on a ZClass propertsheet, so you may need to write something like "ss.propertysheets.get('mysheet').styletype"
* If I find a match, return all the Property values(potentially 47+) of the particular StyleSheet instance (that are not empty strings) in a CSS Format.
Hmm. Here an utterly untested code snippet that may help, intended to be the body of a Script in StyleBook ##parameters=a_title, a_type props = [] for ss in container.objectValues(['StyleSheet']): if (ss.title == a_title and ss.propertysheets['mysheet'].styletype == a_type): for p in ss.propertysheets.get('mysheet').propertyItems(): props.append('%s: %s' % p) return '; '.join(props) Cheers, Evan @ 4-am
participants (2)
-
Bill Hewitt -
Evan Simpson