[Zope] Now it's a "Folder" class question :-)

Max M maxmcorp@worldonline.dk
Sun, 9 Sep 2001 17:29:12 +0200


Well _somebody_ is working on another How-To, and is guessing that you will
like this the class below:

I don't remember if it runs in this version, but I believe so. Anyway it
should get you a step further

Regards Max M

------------

from OFS import SimpleItem, ObjectManager
from OFS.ObjectManager import ObjectManager
from Globals import DTMLFile
import Products

class minimalOM(ObjectManager, SimpleItem.SimpleItem):

    """
    A minimalOM product
    """

    meta_type = 'minimalOM'

    manage_options = ObjectManager.manage_options + (
    	{'label': 'Properties', 'action': 'manage_editForm',},
    	{'label': 'View', 'action': 'index_html',},
    )

    __ac_permissions__ = ObjectManager.__ac_permissions__ + (
        ('View', # label
            ('index_html',), # methods
            ('Anonymous', 'Manager'), # roles
        ),
        ('Change minimalOM',
            ('manage_editAction', 'manage_editForm'),
            ('Manager',)
        ),
        ('Add minimalOM',
            ('manage_addminimalOMAction', 'manage_addminimalOMForm'),
            ('Manager',)
        ),
    )

    def all_meta_types(self):
        """ What types can you add to this objectManager? """
        allowedMetaTypes = ('DTML Method', 'DTML Document', 'minimal')
        result = []
        for metaType in Products.meta_types:
            if metaType['name'] in allowedMetaTypes:
                result.append(metaType)
        return result

    def __init__(self, id, title):
        "Inits the product with default values"
        self.id = id
        self.title = title

    def manage_editAction(self, title, RESPONSE=None):
        "Changes the product values"
        self.title = title
        self._p_changed = 1
        RESPONSE.redirect('manage_editForm')

    def editAction(self, title, RESPONSE=None):
        "Changes the product values"
        self.title = title
        self._p_changed = 1
        RESPONSE.redirect('manage_editForm')

    ##########################
    # The web pages that shows content. Put your own in the www folder.

    # Used to view content of the object
    index_html = DTMLFile('www/index_html', globals())

    # Edit the content of the object
    manage_editForm = DTMLFile('www/manage_editForm', globals())

    # Edit the content of the object
    edit = DTMLFile('www/edit', globals())

##########################
# constructor pages. Only used when the product is added to a folder.

def manage_addminimalOMAction(self, id='minimalOM',
                              title='Title here', REQUEST=None):
    "Add a minimalOM to a folder."
    self._setObject(id, minimalOM(id, title))
    if REQUEST is not None:
        return self.manage_main(self, REQUEST)

# Get user input from this form
manage_addminimalOMForm = DTMLFile('manage_addminimalOMForm', globals())