
#                                                                               #
#                              AttachmentField sample                           #
#                                                                               #


# Python imports
from StringIO import StringIO
import os

# Zope imports
from AccessControl import ClassSecurityInfo
from OFS.PropertyManager import PropertyManager
from OFS.SimpleItem import SimpleItem, Item
from Products.CMFCore.utils import UniqueObject
from Globals import InitializeClass
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Acquisition import Implicit
from AccessControl import Role 

# CMF imports
from Products.CMFCore import CMFCorePermissions
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.ActionProviderBase import ActionProviderBase
from Products.Archetypes.public import *
from Products.Archetypes.BaseObject import BaseObject

# AttachmentField imports
from global_symbols import *
import AttachmentField
import AttachmentWidget

def getTypelessAttachmentField(object):
    """getTypelessAttachmentField(self, ) => temp AF

    This method will create a temporary AF-based type in memory
    It will return the object itself.

    It must be called with 'object', which can be Plone's root.
    """
    # Basic type init
    o = TypelessAttachmentField("", )
    o.initializeArchetype()

    # Special permission handling for anonymous user
    o.manage_role(
        "Anonymous",
        [
        CMFCorePermissions.AccessContentsInformation,
        CMFCorePermissions.View,
        CMFCorePermissions.ModifyPortalContent,
        ],
        )

    # Now, return the special object
    return o.__of__(object)     #.portal_url.getPortalObject()).__of__(object)



class TypelessAttachmentField(SimpleItem, BaseObject, Role.RoleManager):
    """
    This is a sample archetype object used to manage the user's join form.
    """
    archetype_name = "TypelessAttachmentField"
    meta_type = "TypelessAttachmentField"
    isPrincipiaFolderish = 0
 
    schema = Schema(
        (
        AttachmentField.AttachmentField(
            'file',
            widget = AttachmentWidget.AttachmentWidget(
            ),
            ),
        ),
    )
    
    
registerType(TypelessAttachmentField)
