from Globals import package_home
from Products.CMFCore import utils, CMFCorePermissions, DirectoryView
from Products.CMFPlone.PloneUtilities import ToolInit
from Products.Archetypes.public import *
from Products.Archetypes import listTypes
from Products.Archetypes.utils import capitalize

import os, os.path, sys, content, widget

# Module aliases - we don't always get it right on the first try, but and we
# can't move modules around because things are stored in the ZODB with the
# full module path. However, we can create aliases for backwards compatability.

sys.modules['Products.RichDocument.RichDocument'] = content.richdocument
sys.modules['Products.RichDocument.FileAttachment'] = content.attachments
sys.modules['Products.RichDocument.ImageAttachment'] = content.attachments
sys.modules['Products.RichDocument.widgets'] = widget
sys.modules['Products.RichDocument.ImagesManagerWidget'] = widget.images
sys.modules['Products.RichDocument.AttachmentsManagerWidget'] = widget.attachments


# Get configuration data, permissions
from Products.RichDocument.config import *

# Register skin directories so they can be added to portal_skins
DirectoryView.registerDirectory('skins', product_globals)
DirectoryView.registerDirectory('skins/RichDocument', product_globals)
DirectoryView.registerDirectory('skins/attachment_widgets', product_globals)

def initialize(context):

    # Import the type, which results in registerType() being called
    from content import RichDocument, ImageAttachment, FileAttachment

    # initialize the content, including types and add permissions
    content_types, constructors, ftis = process_types(
        listTypes(PROJECTNAME),
        PROJECTNAME)

    utils.ContentInit(
        PROJECTNAME + ' Content',
        content_types      = content_types,
        permission         = DEFAULT_ADD_CONTENT_PERMISSION,
        extra_constructors = constructors,
        fti                = ftis,
        ).initialize(context)
