[Zope] Sessions & DTML Execution

Justin Dunsworth justin.dunsworth at gmail.com
Wed Apr 8 14:25:09 CEST 2015


Hello,

I am running into an issue that I can't quite figure out.

I'm trying to leverage storing data within sessions then setting a variable
in the header of my page to the session variable (for ease of calling)
where I can then use it throughout the rest of my document. Here's the way
it goes:

<dtml-if "REQUEST.SESSION.get('testVarDict')">
  <dtml-call "REQUEST.set('testVarDict',REQUEST.SESSION.get('vx9member'))">
<dtml-else>
  <dtml-call "RESPONSE.redirect(BASE1+'/login')">
</dtml-if>

<dtml-var testVarDict>

Here I am wanting to redirect to login should testVarDict not be set.
Instead it seems like Zope is still wanting to execute the rest of the page
prior to redirecting so this will throw a NameError for testVarDict should
the session data not be set.

I then found out that I can change the dtml-call to a dtml-return for the
redirect and it will stop executing the dtml and redirect. This is all fine
but if I have another page I'm going to call that uses the header like so:

<dtml-var headerDoc>
<dtml-var testVarDict>
<dtml-var footerDoc>

This then will throw the same NameError regardless of the dtml-return
redirect in the header. I can get around this by placing the same checks in
the top of every.single.page that I want to utilize testVarDict variable
but that's too cumbersome.

I then tried to make a script that would check the same thing and then
redirect but it doesn't seem to work at all - for fun here's the python
script:

if context.REQUEST.SESSION.get('testVarDict'):

context.REQUEST.set('vx9member',context.REQUEST.SESSION.get('testVarDict'))
else:
  return context.REQUEST.RESPONSE.redirect('/login')

I've also tried just the context.REQUEST.RESPONSE.redirect without the
return but it doesn't seem to work and I suspect it's because python return
is not the same as dtml-return.

If anyone could assist or show me a different way then I would greatly
appreciate it.

Thanks,
J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/zope/attachments/20150408/9ddf4c49/attachment.html>


More information about the Zope mailing list