[2642] | 1 | """Main product initializer |
---|
| 2 | """ |
---|
[2667] | 3 | import sys |
---|
[2665] | 4 | import logging |
---|
[2642] | 5 | |
---|
| 6 | from zope.i18nmessageid import MessageFactory |
---|
| 7 | from quintagroup.gdocs.spreadsheet import config |
---|
| 8 | |
---|
| 9 | from Products.Archetypes import atapi |
---|
| 10 | from Products.CMFCore import utils |
---|
| 11 | from 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 | |
---|
| 17 | spreadsheetMessageFactory = MessageFactory('quintagroup.gdocs.spreadsheet') |
---|
| 18 | |
---|
[2665] | 19 | logger = logging.getLogger('quintagroup.gdocs.spreadsheet') |
---|
| 20 | |
---|
| 21 | def 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 | |
---|
[2642] | 28 | def 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) |
---|