Re: [Zope] rendering the contents of ..

2005-08-03 Thread J Cameron Cooper

David Bear wrote:

On 8/1/05, J Cameron Cooper [EMAIL PROTECTED] wrote:


David Bear wrote:


I am looking at a couple way of producing a qotd solution.

one way is to put quotes in a folder. Then use objectvalues on the
folder  and randomly select one of the items. I get get the objectid.
but I don't know what I use to get the 'content' of the object.. what
is the method to get the 'rendered' and unrendered content of an
object.

In this case I'm using objects of type file (setting content type to
text/plain) (ofcourse the content is plain text)

I may find the using a zpt, html, or stx object will work better. I'm
hoping there is a method to get either a rendered view of the file,
(if zope knows how to render it) or unrendered, and I'll worry about
rendering it elsewhere.


The contents of a File object can be gotten at simply by calling it. You



sorry to be dense here. Its been a long time since I read the zope
book. I have the following code:
=
from Products.PythonScripts.standard import html_quote
import random
request = container.REQUEST
RESPONSE =  request.RESPONSE
# Return a string identifying this script.
q = container.quotes.objectIds()
print random.choice(q)()
return printed
=

But this returns an TypeError, str is not callable. How do I get this
code to return a random object from the quotes container?


Of course it does. What does 'objectIds' return? Answer: a list of ids 
(strings) and not objects. If you want objects, you must ask a different 
way, as another message provides.


Also, there's not particular reason to use the 'print' facility. You may 
simply say::


  return random.choice(q)()

and get the same effect.

--jcc


can also get at the underlying data with the 'data' attribute, which is
useful if the contents are large (since it provides a 'Pdata' object
rather than a string.) This is just as it says in
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx

Other object types, like those that have to do rendering, you can just
call for the rendered content. Methods 'document_src' or 'read' will
usually work for the source.

   --jcc
--
Building Websites with Plone
http://plonebook.packtpub.com








___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] rendering the contents of ..

2005-08-02 Thread David Bear
On 8/1/05, J Cameron Cooper [EMAIL PROTECTED] wrote:
 David Bear wrote:
  I am looking at a couple way of producing a qotd solution.
 
  one way is to put quotes in a folder. Then use objectvalues on the
  folder  and randomly select one of the items. I get get the objectid.
  but I don't know what I use to get the 'content' of the object.. what
  is the method to get the 'rendered' and unrendered content of an
  object.
 
  In this case I'm using objects of type file (setting content type to
  text/plain) (ofcourse the content is plain text)
 
  I may find the using a zpt, html, or stx object will work better. I'm
  hoping there is a method to get either a rendered view of the file,
  (if zope knows how to render it) or unrendered, and I'll worry about
  rendering it elsewhere.
 
 The contents of a File object can be gotten at simply by calling it. You

sorry to be dense here. Its been a long time since I read the zope
book. I have the following code:
=
from Products.PythonScripts.standard import html_quote
import random
request = container.REQUEST
RESPONSE =  request.RESPONSE
# Return a string identifying this script.
q = container.quotes.objectIds()
print random.choice(q)()
return printed
=

But this returns an TypeError, str is not callable. How do I get this
code to return a random object from the quotes container?

 can also get at the underlying data with the 'data' attribute, which is
 useful if the contents are large (since it provides a 'Pdata' object
 rather than a string.) This is just as it says in
 http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx
 
 Other object types, like those that have to do rendering, you can just
 call for the rendered content. Methods 'document_src' or 'read' will
 usually work for the source.
 
 --jcc
 --
 Building Websites with Plone
 http://plonebook.packtpub.com
 


-- 
David Bear
What's the difference between private knowledge and public knowledge?
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] rendering the contents of ..

2005-08-02 Thread David Siedband

I think something like this is what you're looking for:

===

from Products.PythonScripts.standard import html_quote
import random
request = container.REQUEST
RESPONSE =  request.RESPONSE
q = container.quotes.objectValues('File')
return random.choice(q)

===

cheers
--
David



On Aug 2, 2005, at 2:40 PM, David Bear wrote:



[ ... ]



sorry to be dense here. Its been a long time since I read the zope
book. I have the following code:
=
from Products.PythonScripts.standard import html_quote
import random
request = container.REQUEST
RESPONSE =  request.RESPONSE
# Return a string identifying this script.
q = container.quotes.objectIds()
print random.choice(q)()
return printed
=

But this returns an TypeError, str is not callable. How do I get this
code to return a random object from the quotes container?






___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] rendering the contents of ..

2005-08-01 Thread J Cameron Cooper

David Bear wrote:

I am looking at a couple way of producing a qotd solution.

one way is to put quotes in a folder. Then use objectvalues on the
folder  and randomly select one of the items. I get get the objectid.
but I don't know what I use to get the 'content' of the object.. what
is the method to get the 'rendered' and unrendered content of an
object.

In this case I'm using objects of type file (setting content type to
text/plain) (ofcourse the content is plain text)

I may find the using a zpt, html, or stx object will work better. I'm
hoping there is a method to get either a rendered view of the file,
(if zope knows how to render it) or unrendered, and I'll worry about
rendering it elsewhere.


The contents of a File object can be gotten at simply by calling it. You 
can also get at the underlying data with the 'data' attribute, which is 
useful if the contents are large (since it provides a 'Pdata' object 
rather than a string.) This is just as it says in 
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx


Other object types, like those that have to do rendering, you can just 
call for the rendered content. Methods 'document_src' or 'read' will 
usually work for the source.


--jcc
--
Building Websites with Plone
http://plonebook.packtpub.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )