AUTHENTICATED_USER and external methods
Hi, I've got an external method that creates an HTML page from a large number of SQL queries. I call it like so; <a href="supercascade?tag_id=11>Overview of Module</a>. I want to have the benefits of standard_html_header and standard_html_footer in my documents too, so I've got this in the code... template_str = self.standard_html_header.read_raw() template = DocumentTemplate.HTML(template_str) html = template(self) ... lots of wondrous stuff with databases that add to 'html' template_str = self.standard_html_footer.read_raw() template = DocumentTemplate.HTML(template_str) return html + template(self) Now this works ok - standard_html_header can *get at* dtml variables in it, such as 'title' and 'id'. Problems arise if I want to get to AUTHENTICATED_USER, as adding this User:<dtml-var "AUTHENTICATED_USER.getUserName()"> Results in the header *being rendered* with the correct user, but the page gives <!-- Error type: NameError Error value: AUTHENTICATED_USER --> with the following traceback... <!-- Traceback (innermost last): File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/ZPublisher/Publish. py, line 214, in publish_module File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/ZPublisher/Publish. py, line 179, in publish File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/Zope/__init__.py, line 201, in zpublisher_exception_hook (Object: ElementWithAttributes) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/ZPublisher/Publish. py, line 165, in publish File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/ZPublisher/mapply.p y, line 160, in mapply (Object: sg_frontpage) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/ZPublisher/Publish. py, line 102, in call_object (Object: sg_frontpage) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/Products/ExternalMe thod/ExternalMethod.py, line 246, in __call__ (Object: sg_frontpage) (Info: ((<Folder instance at 74f830>, 's1ghs'), {}, None)) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/Extensions/get_all_children.py , line 201, in sg_preamble (Object: ElementWithAttributes) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/DocumentTemplate/DT _String.py, line 502, in __call__ (Object: <string>) File /home/nnle/Zope-2.0.0-solaris-2.6-sparc/lib/python/DocumentTemplate/DT _Util.py, line 321, in eval (Object: AUTHENTICATED_USER.getUserName()) File <string>, line 0, in ? NameError: (see above) --> line 201 is this line in the code html = template(self) baffled... Tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
Tony McDonald wrote:
Hi, I've got an external method that creates an HTML page from a large number of SQL queries. I call it like so; <a href="supercascade?tag_id=11>Overview of Module</a>.
I want to have the benefits of standard_html_header and standard_html_footer in my documents too, so I've got this in the code...
template_str = self.standard_html_header.read_raw() template = DocumentTemplate.HTML(template_str) html = template(self)
... lots of wondrous stuff with databases that add to 'html'
template_str = self.standard_html_footer.read_raw() template = DocumentTemplate.HTML(template_str) return html + template(self)
Now this works ok - standard_html_header can *get at* dtml variables in it, such as 'title' and 'id'. Problems arise if I want to get to AUTHENTICATED_USER, as adding this User:<dtml-var "AUTHENTICATED_USER.getUserName()">
Results in the header *being rendered* with the correct user, but the page gives <!-- Error type: NameError Error value: AUTHENTICATED_USER -->
I'm not definite about it, but I think I have a hint: This might be the case because AUTHENTICATED_USER is a property of the REQUEST object (according the the DTML-Guide). So, in your DTML you should put REQUEST['AUTHENTICATED_USER'] instead of just the name. This might then work within the external method, because it looks up the name correctly. Hope this helps, Heiko -- Heiko Stoermer MIG Augsburg
Heiko, I was thinking that I should do html = template(self, REQUEST) but that didn't work. Your code seems to do the trick - many thanks! Tone At 10:12 am +0200 13/9/99, Heiko Stoermer wrote:
Tony McDonald wrote:
Hi, I've got an external method that creates an HTML page from a large number of SQL queries. I call it like so; <a href="supercascade?tag_id=11>Overview of Module</a>.
I want to have the benefits of standard_html_header and standard_html_footer in my documents too, so I've got this in the code...
template_str = self.standard_html_header.read_raw() template = DocumentTemplate.HTML(template_str) html = template(self)
... lots of wondrous stuff with databases that add to 'html'
template_str = self.standard_html_footer.read_raw() template = DocumentTemplate.HTML(template_str) return html + template(self)
Now this works ok - standard_html_header can *get at* dtml variables in it, such as 'title' and 'id'. Problems arise if I want to get to AUTHENTICATED_USER, as adding this User:<dtml-var "AUTHENTICATED_USER.getUserName()">
Results in the header *being rendered* with the correct user, but the page gives <!-- Error type: NameError Error value: AUTHENTICATED_USER -->
I'm not definite about it, but I think I have a hint: This might be the case because AUTHENTICATED_USER is a property of the REQUEST object (according the the DTML-Guide). So, in your DTML you should put REQUEST['AUTHENTICATED_USER'] instead of just the name. This might then work within the external method, because it looks up the name correctly.
Hope this helps, Heiko
------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
participants (2)
-
Heiko Stoermer -
Tony McDonald