source: products/quintagroup.gdocs.spreadsheet/trunk/quintagroup/gdocs/spreadsheet/__init__.py @ 2682

Last change on this file since 2682 was 2667, checked in by liebster, 14 years ago

Added choose the titles of columns by contentype

File size: 2.4 KB
Line 
1"""Main product initializer
2"""
3import sys
4import logging
5
6from zope.i18nmessageid import MessageFactory
7from quintagroup.gdocs.spreadsheet import config
8
9from Products.Archetypes import atapi
10from Products.CMFCore import utils
11from Products.CMFCore.permissions import setDefaultRoles
12
13# Define a message factory for when this product is internationalised.
14# This will be imported with the special name "_" in most modules. Strings
15# like _(u"message") will then be extracted by i18n tools for translation.
16
17spreadsheetMessageFactory = MessageFactory('quintagroup.gdocs.spreadsheet')
18
19logger = logging.getLogger('quintagroup.gdocs.spreadsheet')
20
21def logException(msg, context=None):
22    logger.exception(msg)
23    if context is not None:
24        error_log = getattr(context, 'error_log', None)
25        if error_log is not None:
26            error_log.raising(sys.exc_info())
27
28def initialize(context):
29    """Initializer called when used as a Zope 2 product.
30
31    This is referenced from configure.zcml. Regstrations as a "Zope 2 product"
32    is necessary for GenericSetup profiles to work, for example.
33
34    Here, we call the Archetypes machinery to register our content types
35    with Zope and the CMF.
36    """
37
38    # Retrieve the content types that have been registered with Archetypes
39    # This happens when the content type is imported and the registerType()
40    # call in the content type's module is invoked. Actually, this happens
41    # during ZCML processing, but we do it here again to be explicit. Of
42    # course, even if we import the module several times, it is only run
43    # once.
44
45    content_types, constructors, ftis = atapi.process_types(
46        atapi.listTypes(config.PROJECTNAME),
47        config.PROJECTNAME)
48
49    # Now initialize all these content types. The initialization process takes
50    # care of registering low-level Zope 2 factories, including the relevant
51    # add-permission. These are listed in config.py. We use different
52    # permissions for each content type to allow maximum flexibility of who
53    # can add which content types, where. The roles are set up in rolemap.xml
54    # in the GenericSetup profile.
55
56    for atype, constructor in zip(content_types, constructors):
57        utils.ContentInit('%s: %s' % (config.PROJECTNAME, atype.portal_type),
58            content_types      = (atype,),
59            permission         = config.ADD_PERMISSIONS[atype.portal_type],
60            extra_constructors = (constructor,),
61            ).initialize(context)
Note: See TracBrowser for help on using the repository browser.