[Zope] return value treated as dtml?

Dylan Reinhardt zope at dylanreinhardt.com
Fri Oct 24 15:28:56 EDT 2003


On Fri, 2003-10-24 at 10:33, Ted holden wrote:
> On Friday 24 October 2003 12:35, Dylan Reinhardt wrote:
> 
> 
> 
> > Sounds workable... what is it about passing the user a correctly-formed
> > link that doesn't meet your needs?
> 
> Not in all cases.  I could easily end up passing him a link to a half gigabyte 
> file, and I suspect he'd not be happy...

So don't do that. :-)

Pass a link to a *method* that takes the filename and offset as
arguments. Assuming you want a per-page limit of 1024 bytes, have your
method return the first 1024 bytes after the specified offset.  While
you're rendering that content, you should include a "continued" link
that points to the same method and file, but increments the offset value
1024. Ta-da! Instant buffering.

Alternately, you could easily indicate the size of the document next to
the link and leave it for the client to determine whether they want to
blow the bandwidth downloading it. 


> > > I'm guessing at this point that the best shot might be to write the list
> > > of hits to a file, and then return a handle to a dtml file which would
> > > pick up the list of hits from the file and do the right things with them,
> > > and include the user's name or id in the name of the hit file to keep
> > > users separate.
> >
> > I'm a bit confused at this. Is this a logging solution?  A caching
> > solution?  In terms of performance, it's tough to see how it could
> > possibly improve on knowing a file name and a byte offset.
> 
> No caching.  All I'm trying to do is get that filename and offset to another 
> external method while avoiding all the catch-22s and sticky-wickets and what 
> not.

My advice is to do as little in your external method as possible. Short
of accessing something on the file system, there's not much here that
*needs* to be done externally.  Rather than fuss with having it maintain
its own state, just make it fully parameterized.

> 
> > > The question at that point would be whether an external method could
> > > return the handle of a dtml method created within Zope
> 
> > Sure.  The easiest thing to do is return a string that corresponds with
> > a dtml method (or anything) available in the current namespace. Ex:
> 
> > <dtml-call "REQUEST.set('some_name', ext_method(arg1, arg2))">
> > <dtml-var "_[some_name]">
> 
> Sorry but I don't quite understand that.  I need to have the external method 
> return something which causes a dtml page to be acted upon and shown. 

Hopefully Paul's explanation clarifies this.

> I'm assuming also that the external method cannot return both a list of file 
> and offset pairs and the information to execute a dtml page, which is why I 
> assume I'd need to save the list to a file and have the dtml page pick it up.

It can only return one object, but that object *could* be a dictionary
containing an arbitrarily complex collection of values, if necessary.

Ex:

----
def my_method(args):
    do_stuff
    return {'path': '/path/to/file', 
            'offset': 10, 
            'dtml_method': 'some_name', 
            'sub_dict': {'value':'I think you get the point'}}
---

which could then be obtained thus:

---
info = my_external_method(args)
my_path = info.get('path')
my_offset = info.get('offset')
---

Etc, etc.

HTH,

Dylan




More information about the Zope mailing list