[Zope] Where do I find out about cookies?

Jean Jordaan Jean@mosaicsoftware.com
Fri, 25 Aug 2000 11:45:21 +0200


Hi Loren, J. Atwood, Maik

Thanks for all the info! I'll digest & give feedback 
where I can. In the meantime, this is what I've fixed up
for myself (with a LOT of help from Roche Compaan) ..

In DTML Document 'index_html'::

    <dtml-var docsSorted> 

In DTML Method 'docsSorted'::

    <dtml-if "REQUEST.form.has_key('sort_key')">
        <dtml-call "REQUEST.set('sort_key', REQUEST.form['sort_key'])">
        <dtml-call "RESPONSE.setCookie('sort_key',
REQUEST.form['sort_key'])">
    <dtml-else>
        <dtml-if "REQUEST.cookies.has_key('sort_key')">
            <dtml-call "REQUEST.set('sort_key',
REQUEST.cookies['sort_key'])">
        <dtml-else>
            <dtml-call "RESPONSE.setCookie('sort_key', 'title')">
            <dtml-call "REQUEST.set('sort_key', 'title')">
        </dtml-if "REQUEST.cookies.has_key['sort_key']">
    </dtml-if "REQUEST.form.has_key('sort_key')">

    <table border="1">
    <tr>  <th> <a href="<dtml-var id>?sort_key=title">Title</a>
	</th> <th> <a href="<dtml-var id>?sort_key=origin">Origin</a>
	</th> <th> <a href="<dtml-var id>?sort_key=series">Series</a>
	</th> 
	</tr>

    <dtml-if "sort_key=='title'">
        <dtml-in "PARENTS[0].objectItems(['ccDocClass'])" size=10 start=qs
            sort=title>
        <tr> <td> 
        <a href="<dtml-var id>"><dtml-var title></a> 
        <dtml-if "AUTHENTICATED_USER.has_role('ContentManager')">
            [<b><a href="<dtml-var id>/manage_workspace">Edit</a></b>]
        </dtml-if>
        </td> <td> <dtml-var origin> </td> <td> <dtml-var series> </td>
</tr>
        </dtml-in> 
    <dtml-elif "sort_key=='series'">
        <dtml-in "PARENTS[0].objectItems(['ccDocClass'])" size=10 start=qs
            sort=series>
        <tr> <td> 
    [... and so on for the other possibilities ...]

The rationale is:

'docsSorted' is called as method by 'index_html'. 
- Upon the first iteration, there is no cookie and no form
    variable. A cookie and a form variable is set to 'title' as
    default. The form variable governs.
- Upon subsequent iterations, if there is a form variable,
    then 'index_html' was called from 'docsSorted' and the
    sort-order has *just* changed. The cookie is changed (which
    will not be noticed during this iteration since it first has
    to be received again) and the form variable governs.
- If there is a only a cookie and no form variable, it
    governs.

Now I want to extend it so that choosing a sort-order for the
*second* time reverses the order -- does this really entail 
repeating the entire '<dtml-if "sort_key=='title'">' section
for '"order=='reverse'"'?

I think I'm probably better off using the catalog for this,
rather than dtml-in batching .. 

-- 
Jean Jordaan       --    technical writer    --
Mosaic Software    --    Zope 2.1.6 on WinNT and W2K