[Zope-dev] Python Based DataSkins and Propertysheets

Johan Carlsson johanc@torped.se
Mon, 12 Feb 2001 01:08:35 +0100


Hi,=20
I am trying to figure out ZPatterns and because I rather work with =
Python Products when with Zclasses I am trying to convert the EmployZ =
product to Python.
So far I got half the way there, the Rack recognizes the DataSkin
And on newItem in the Specialist it a new slot gets created and I can =
see them and their ID.

Now the problem is creating a Propertysheet in the DataSkin that gets =
stored in the Rack.

I packet my work so far and put it on Zope.org:=20
http://www.zope.org/Members/johanc/ZPatterns/EmployX/EmployX-0.0.1.tgz

I look at the ZPattern Products that I know are out there, but they =
don't seem=20
help me any futher.

Regards,
Johan



Here's my to classes:

< EmployX (DataSkin)>

__doc__ =3D """EmployX product module.

See README.txt for more details."""


__version__ =3D '0.0.1'

from Globals import HTMLFile
from Globals import MessageDialog
from Globals import Persistent

import OFS.SimpleItem
import Acquisition
import AccessControl.Role

from Products.ZPatterns.DataSkins import DataSkin
#from Products.ZPatterns.PropertySheets import VirtualSheets


manage_addEmployXForm =3D HTMLFile('dtml/EmployXAdd', globals())=20

def manage_addEmployX(self, id, title=3D'', REQUEST=3DNone):
    """Add a EmployX to a folder."""
    self._setObject(id, EmployX(id, title))
    if REQUEST is not None:
        return self.manage_main(self, REQUEST)


class EmployX(
        DataSkin,
        #VirtualSheets,
):=20
    """EmployX object.=20
    """
       =20
    meta_type =3D 'EmployX'

    # Necessary?
    _isRackMountable =3D 1

    #_properties=3D(
    #             {'id':'first', 'type': 'string'},
    #             {'id':'last', 'type': 'string'},
    #             {'id':'emp_id', 'type': 'string'},
    #             {'id':'salary', 'type': 'string'},                =20
    #            )
   =20
       =20
    manage_options =3D (=20
            {'label': 'Edit',       'action': 'manage_main' },
            {'label':'Debug','action':'debug'},       =20
            {'label': 'View',       'action': 'index_html'},=20
            {'label': 'Security',   'action': 'manage_access'},
        )=20


    _v_manage_options_label_index =3D =
ExtendedManagmentTabs.createManageIndex(manage_options=3Dmanage_options)

    __ac_permissions__=3D(=20
                ('View management screens', =
('debug','manage_tabs','manage_main')),
                ('Change permissions',      ('manage_access',)           =
),
                ('Change EmployX'     ,     ('manage_edit',)             =
),
                ('View EmployX',            ('',)                        =
),
                )

    def __init__(self,id):=20
        """initialise a new instance of BeingBoring"""
        DataSkin.__init__(self,id)
       =20
       =20
       =20
    def debug(self):
        """ Print object's __dict__ """
        result =3D ""
        for k, v in self.__dict__.items():
            result =3D "%s\n%s : %s" % (result, repr(k), repr(v))
        return result


    manage_main =3D HTMLFile('dtml/EmployXEdit', globals())=20
   =20
    def manage_edit(self, title, REQUEST=3DNone):=20
        """does this really need a doc string?"""
        self.title =3D title
        if REQUEST is not None:
            return =
self.manage_main(self,REQUEST,management_view=3D'Edit')


    editInstance =3D HTMLFile('editInstance', globals())=20
    editInstanceForm =3D HTMLFile('editInstanceForm', globals())=20
    index_html  =3D HTMLFile('index_html', globals())=20


def initialize(context):=20
    """Initialize the EmployX product.
    """


    context.registerClass(
            EmployX,        =20
            constructors =3D (                =20
                manage_addEmployXForm,=20
                manage_addEmployX),                                      =
          =20
            icon =3D 'www/item.gif'               =20
        )
    # We need this so that this class will show up in the list of =
classes
    # Customizers can customize. (Thanks Steve)
    context.registerBaseClass(EmployX)


< EmployXManager(Specialist)>

__doc__ =3D """EmployXManager product module.

See README.txt for more details."""


__version__ =3D '0.0.1'


from Globals import HTMLFile
#from Globals import MessageDialog
#from Globals import Persistent



from Products.ZPatterns.Specialists import Specialist


manage_addEmployXManagerForm =3D HTMLFile('EmployXManagerAdd', =
globals())=20

def manage_addEmployXManager(self, id, title=3D'', REQUEST=3DNone):
    """Add a EmployXManager to a folder."""
    self._setObject(id, EmployXManager(id, title))
    if REQUEST is not None:
        return self.manage_main(self, REQUEST)


class EmployXManager(Specialist):
    """Thing that manages EmployX"""
   =20
    meta_type =3D "EmployXManager"=20

    newItemForm =3D HTMLFile('newItemForm', globals())=20
    index_html  =3D HTMLFile('index_html_manager', globals())=20

    def addNewItem(self,emp_id,REQUEST=3DNone):
        """ttw"""
        ob =3D self.newItem(emp_id)
        #ob.addPropertySheet('Basic')
        =
#ob.propertysheets.Basic.manage_changeProperties(REQUEST=3DREQUEST)
       =20
        #if REQUEST.has_key('first'): ob.first =3D REQUEST['first']
        #else:  ob.first =3D ''
        #if REQUEST.has_key('last'): ob.last =3D REQUEST['last']
        #else:  ob.last =3D ''
        #if REQUEST.has_key('emp_id'): ob.emp_id =3D REQUEST['emp_id']
        #else:  ob.emp_id =3D ''
        #if REQUEST.has_key('salary'): ob.salary =3D REQUEST['salary']
        #else:  ob.salary =3D ''
       =20
        if REQUEST is not None:
            return self.manage_main(self, REQUEST)

   =20
          =20
           =20
def initialize(context):=20
    """Initialize the EmployXManager product.
    """

    context.registerClass(
            EmployXManager,        =20
            constructors =3D (                =20
                manage_addEmployXManagerForm,=20
                manage_addEmployXManager),                               =
                 =20
            icon =3D 'www/item.gif'               =20
        )