Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Users

- Next problem - looking for dtml file in the wrong place...

 

 

Zope users RSS feed   Index | Next | Previous | View Threaded


skip at calendar

Dec 8, 1998, 12:39 PM

Post #1 of 5 (472 views)
Permalink
- Next problem - looking for dtml file in the wrong place...

I'm inching along. Thanks to Michel Pelletier and Andy Kuchling, I now know
my calendar module is a Product and what most (all?) of the necessary
scaffolding is. My Calendar class supports a show method:

def show(self, year, month=0):
"""return plain ASCII calendar

month == 0 ==> display calendar for entire year
"""

if year < 1 or year > 9999:
raise ValueError, ("year out of range: %d" % year)
if month < 0 or month > 12:
raise ValueError, ("month out of range: %d" % month)

if month: cal = os.popen("cal %s %s" % (month, year)).read()
else: cal = os.popen("cal %s" % year).read()

return HTMLFile('cal', month=month, year=year, cal=cal)

When I access

http://localhost:8080/Calendar/show?month:int=0&year:int=1998

I get the following traceback:

Traceback (innermost last):
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 861, in publish_module
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 585, in publish
(Info: /Calendar/show)
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Response.py, line 284, in setBody
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_HTML.py, line 217, in __str__
(Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_HTML.py, line 209, in quotedHTML
(Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_String.py, line 532, in read_raw
(Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
IOError: (2, 'No such file or directory')

which suggests to me that my cal.dtml file is not where Zope expects to find
it. All files in my Products/Calendar directory are in that directory:

% ls -F lib/python/Products/Calendar/
__init__.py cal.dtml vcal.gif
__init__.pyc cal.py
addCalendar_form.dtml cal.pyc

Why is it looking up two levels in the directory hierarchy for the DTML
file? As far as I can tell, I'm using the same calling conventions for
HTMLFile objects as the MailHost and sample Products do.

Any suggestions this time?

Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/
skip [at] calendar | Musi-Cal: http://concerts.calendar.com/
518-372-5583


pavlos at gaaros

Dec 8, 1998, 1:17 PM

Post #2 of 5 (456 views)
Permalink
Re: - Next problem - looking for dtml file in the wrong place... [In reply to]

On Tue, 8 Dec 1998 skip [at] calendar wrote:

>
> def show(self, year, month=0):
> """return plain ASCII calendar
>
> month == 0 ==> display calendar for entire year
> """
>
> if year < 1 or year > 9999:
> raise ValueError, ("year out of range: %d" % year)
> if month < 0 or month > 12:
> raise ValueError, ("month out of range: %d" % month)
>
> if month: cal = os.popen("cal %s %s" % (month, year)).read()
> else: cal = os.popen("cal %s" % year).read()
>
> return HTMLFile('cal', month=month, year=year, cal=cal)

cal is a string not a file.
I am not a Zope user though so I might be talking nonsense

Pavlos


jim at Digicool

Dec 8, 1998, 1:29 PM

Post #3 of 5 (455 views)
Permalink
Re: - Next problem - looking for dtml file in the wrong place... [In reply to]

skip [at] calendar wrote:
>
> I'm inching along. Thanks to Michel Pelletier and Andy Kuchling, I now know
> my calendar module is a Product and what most (all?) of the necessary
> scaffolding is. My Calendar class supports a show method:
>
> def show(self, year, month=0):
> """return plain ASCII calendar
>
> month == 0 ==> display calendar for entire year
> """
>
> if year < 1 or year > 9999:
> raise ValueError, ("year out of range: %d" % year)
> if month < 0 or month > 12:
> raise ValueError, ("month out of range: %d" % month)
>
> if month: cal = os.popen("cal %s %s" % (month, year)).read()
> else: cal = os.popen("cal %s" % year).read()
>
> return HTMLFile('cal', month=month, year=year, cal=cal)

Is this Globals.HTMLFile or DocumentTemplate.HTMLFile?

> When I access
>
> http://localhost:8080/Calendar/show?month:int=0&year:int=1998
>
> I get the following traceback:
>
> Traceback (innermost last):
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 861, in publish_module
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 585, in publish
> (Info: /Calendar/show)
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/ZPublisher/Response.py, line 284, in setBody
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_HTML.py, line 217, in __str__
> (Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_HTML.py, line 209, in quotedHTML
> (Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
> File /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/DocumentTemplate/DT_String.py, line 532, in read_raw
> (Object: /home/dolphin/skip/src/Zope-1.9b1-src/lib/python/cal.dtml)
> IOError: (2, 'No such file or directory')
>
> which suggests to me that my cal.dtml file is not where Zope expects to find
> it. All files in my Products/Calendar directory are in that directory:
>
> % ls -F lib/python/Products/Calendar/
> __init__.py cal.dtml vcal.gif
> __init__.pyc cal.py
> addCalendar_form.dtml cal.pyc
>
> Why is it looking up two levels in the directory hierarchy for the DTML
> file?

I bet that you are running Globals.HTMLFile, which assumes that
DTML files are in SOFTWARE_HOME.

> As far as I can tell, I'm using the same calling conventions for
> HTMLFile objects as the MailHost and sample Products do.

Not quite. If you look closely, you'll see that HTMLFile is
used to create methods and that it's usually called with
globals() passed in. This allows it to figure out where
the calling package is located so that it can find the DTML
file. I think you want:

_show=HTMLFile('cal',globals())
def show(self, year, month=0):
"""return plain ASCII calendar

month == 0 ==> display calendar for entire year
"""

if year < 1 or year > 9999:
raise ValueError, ("year out of range: %d" % year)
if month < 0 or month > 12:
raise ValueError, ("month out of range: %d" % month)

if month: cal = os.popen("cal %s %s" % (month, year)).read()
else: cal = os.popen("cal %s" % year).read()

return self._show(self, month=month, year=year, cal=cal)

I assume that you want to return the rendered template, right?
In your version you were just calling the constructor. It's
better to call the constructor in the class definition so that
you don't pay construction and compilation costs on each hit.

Jim

--
Jim Fulton mailto:jim [at] digicool
Technical Director (540) 371-6909 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.


skip at calendar

Dec 8, 1998, 1:33 PM

Post #4 of 5 (456 views)
Permalink
Re: - Next problem - looking for dtml file in the wrong place... [In reply to]

Pavlos> cal is a string not a file.

True enough, but that's how HTMLFile objects are created in other examples I
looked at. All they seem to provide is the base name of the DTML file - no
extensions, no path.

Skip Montanaro | Mojam: "Uniting the World of Music" http://www.mojam.com/
skip [at] calendar | Musi-Cal: http://concerts.calendar.com/
518-372-5583


skip at calendar

Dec 8, 1998, 1:48 PM

Post #5 of 5 (455 views)
Permalink
Re: - Next problem - looking for dtml file in the wrong place... [In reply to]

Jim> Is this Globals.HTMLFile or DocumentTemplate.HTMLFile?

Globals.HTMLFile...

>> As far as I can tell, I'm using the same calling conventions for
>> HTMLFile objects as the MailHost and sample Products do.

Jim> Not quite. If you look closely, you'll see that HTMLFile is
Jim> used to create methods and that it's usually called with
Jim> globals() passed in.

Thanks for that tip. I assumed globals() was used simply to gather a bunch
of data into a dict.

Jim> I think you want:

Jim> _show=HTMLFile('cal',globals())
Jim> def show(self, year, month=0):
...
Jim> return self._show(self, month=month, year=year, cal=cal)

Right you are. Works like a charm.

Thanks,

Skip

Zope users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.