[Zope] - How do I publish this object?

Michel Pelletier mike@icebox.dlogue.net
Tue, 8 Dec 1998 08:29:17 -0600 (CST)


> 
> 
> I believe this was asked yesterday, but I don't recall seeing an answer
> posted yet, so I'll ask again, in case it wasn't noticed by those with
> enough Zope Zen.
> 
> While I was in the shower last night (what is it about the shower with this
> group?) it dawned on me that what I don't get about Zope is how to publish
> an object in much the same way I would have done using Bobo.
> 
> As an example, appended is a small module, cal.py, which uses the Unix cal
> command to generate an ASCII calendar.  How would I make that available
> through Zope?  Seeing how that is done would be a big step forward for me.
> 
> Thx,
> 
> Skip Montanaro	   | Mojam: "Uniting the World of Music" http://www.mojam.com/
> skip@calendar.com  | Musi-Cal: http://concerts.calendar.com/
> 518-372-5583
> 

	It's quite easy.  There are some things missing from my example here that
you will need to create, alot of dtml and an __init__.py file which sets up some
stuff and contains the ImageFile references to any icons you plan to use.  Notice
I just droped this stuff like iceing onto your Calendar cake.  It looks daunting
now but after you see it a few times lots of the fluf because invisible to you.

Michel

> 
> """
> dumb Calendar module
> """

from Globals import HTMLFile
import OFS.SimpleItem, Persistence, Acquisition, AccessControl.Role

> import os
> 
> class Calendar(
	OFS.SimpleItem.Item,
	Persistence.Persistent,
	Acquisition.Implicit,
	AccessControl.Role.RoleManager,
	):
>     """calendar class"""

	meta_type='MyCalendar'
	icon='misc_/MyCalendar/folder

# These are added to your manage screens by lib/python/App/manage_tabs.dtml
        manage_options=(
                {'label':'Contents',   'action':'manage_main'},
                {'label':'Properties', 'action':'manage_propertiesForm'},
                {'label':'View',       'action':''},
                {'label':'Security',   'action':'manage_access'},
                )

# These define the atomic operations that can be done with this module
# These end up in your security screen 'manage_access'
        __ac_permissions__=(
                ('View management screens', ('manage_tabs','manage_main')),
                ('Change permissions', ('manage_access',)),
                ('Change Calendar Settings', ('manage_edit',)),
                ('View Calendar',   ('',)),
                )

	def __init__(self, id, title='', REQUEST):
		self.id = id
		self.title=title

	# need an index view
	index_html=HTMLFile('index_html', globals())

	# this is your management screen
	manage_main=HTMLFile('main', globals())

	# returned when the manage clicks on 'Properties' (see permissions above)
	manage_propertiesForm=HTMLFile('editprops', globabls())

	def manage_edit(self, id, name, REQUEST:
		""" this is the action for the form in manage_propertiesForm
		"""
		self.title=title
		if REQUEST is not None:
			return self.manage_main(self, REQUEST)

>     def show(self, year, month=0):
>         """return plain ASCII calendar
	You probably want to convert this to a function that returns
	a DTML file that lays out the calendar and fills in some
	<!--#var--> tags.
> 
>         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 cal
> 
>