Joachim Schmitz wrote:
> Hi,
> 
> for our current project we had to develop a lot of custom documenttypes
> and forms. I took the same approach as in CPSDocuments, that is putting
> the Schemas in getMyProjectSchemas.py and the layouts in
> getMyProjectLayouts.py and installing them in the install script.
> 
> However to find out what a single form is supposed to do, one has to
> look in various sourcefiles, and the connection between the various
> pieces is just by putting the right names at right places. That makes it
> very flexible but hard to understand and hard to maintain, especially if
> your working in a team.
> 
> I am interested to hear if other developers share this view,  and how
> they address this.
> 

Well... When there's a one 2 one mapping between FTI, schema and layout,
it's true that having them in the same place helps. Now there are cases
where this doesn't hold (look at the 'common' and 'metadata' schemas and
layouts...).

What I do actually is this: a python package 'mydocuments', which
contains one (python module) file per document type. Theses modules all
define some 'standard' symbol, ie:

### mydocuments/my_type.py
# import shared schemas, layouts and vocabularies definitions
import shared

TYPE_ID = 'my_type'
TYPE  = {
  # Flexible Type def here
}

my_type_schema = {
  # type specific schema here
}

# eventually import other shared schemas
SCHEMAS = {
  'my_type' : my_type_schema,
  # possibly references to other (imported) schemas, ie:
  # 'xxx' : shared.xxx_schema,
}

# idem for layouts, vocabularies, etc

And I have a (more or less) generic __init__.py that takes care of
presenting what's needed from theses modules to the installer.

### mydocuments/__init__.py
import os, os.path

__my_path = os.path.dirname(os.path.realpath(__file__))
__module_names = [os.path.splitext(f)[0] \
                  for f in os.listdir(__my_path)\
                  if f.endswith('.py')]

__modules = {}
for __name in __module_names:
    __modules[__name] = __import__(__name, globals(),  locals(), [])

def getTypes():
    return dict([(dt.TYPE_ID, dt.TYPE) \
                 for dt in __modules.values() \
                 if hasattr(dt, 'TYPE')])

def getSchemas():
    schemas = {}
    for dt in __modules.values():
        try:
            schemas.update(dt.SCHEMAS)
        except AttributeError:
            # no schema
            pass

    return schemas

def getLayouts():
    layouts = {}
    for dt in __modules.values():
        try:
            layouts.update(dt.LAYOUTS)
        except AttributeError:
            # no layouts
            pass
    return layouts

# etc...

And in the installer:


from Products.MyProduct import mydocuments

class MyInstaller(CPSInstaller):
   ( ... )
    def verifyMyDocuments(self):
        """Setup our documents types."""

        self.verifyFlexibleTypes(
           mydocuments.getTypes(),

           doc_roots=self.portal.getDocumentRoots()
                                )

        types = mydocuments.getTypes().keys()
        self.allowContentTypes(types, 'Workspace')
        self.allowContentTypes(types, 'Section')

        self.verifyWidgets(mydocuments.getWidgets())
        self.verifySchemas(mydocuments.getSchemas())
        self.verifyLayouts(mydocuments.getLayouts())
        # etc


Note that I wouldn't say it's a "best practice". And from Florent's
post, I guess this will soon become obsolete anyway...

-- 
bruno desthuilliers
développeur
[EMAIL PROTECTED]
http://www.modulix.com
_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel

Reply via email to