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

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

Added 'view' for GSpreadsheet content type

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