Extending a type
================

With Archetypes and ATContentTypes it's very easy to extend a type. This small
example will show you how

Code Example
============

How to extend ATEvent by adding a new field and changing an existing field:

MyATEvent.py
------------

from Products.ATContentTypes.config import HAS_LINGUA_PLONE
from Products.MyATEvent.config import *

if HAS_LINGUA_PLONE:
    from Products.LinguaPlone.public import *
else:
    from Products.Archetypes.public import *

from Products.CMFCore import permissions
from Products.CMFCore.utils import getToolByName
from AccessControl import ClassSecurityInfo

from Products.ATContentTypes.content.base import updateActions
from Products.ATContentTypes.content.event import ATEventSchema
from Products.ATContentTypes.content.event import ATEvent
from Products.ATContentTypes.permission import ChangeEvents

from Products.validation.validators.SupplValidators import MaxSizeValidator
from Products.Archetypes.Marshall import PrimaryFieldMarshaller


# at first make a copy of the ATEvent schema so we can change everything without
# conflicting (and afflicting) ATEvent
MyATEventBaseSchema = ATEventSchema.copy()

# disable validation of the phone number
MyATEventBaseSchema['contactPhone'].validators = ()
# description shouldn't be primary field because we have an image
MyATEventBaseSchema['description'].primary = False

MyATEventSchema = MyATEventBaseSchema + Schema((
    ImageField('flyer',
               required=0,
               primary=1,
               languageIndependent=True,
               sizes= {'preview' : (400, 400),
                       'thumb'   : (128, 128),
                       'tile'    :  (64, 64),
                       'icon'    :  (32, 32),
                       'listing' :  (16, 16),
                      },
               validators = MaxSizeValidator('checkFlyerMaxSize',
                                             maxsize=0.5), # 500kb
               widget = ImageWidget(
                        description = "Select a flyer",
                        description_msgid = "help_image_flyer",
                        label= "Flyer",
                        label_msgid = "label_image_flyer",
                        i18n_domain = "plone"))
    ), marshall=PrimaryFieldMarshaller())

# now we have a schema without phone number validation for contactPhone and a
# flyer field which can contain an image as primary field

# creating a new type called MyATEvent
class MyATEvent(ATEvent):
    """My own event based on ATEvent"""

    schema         =  MyATEventSchema

    content_icon   = 'myevent_icon.gif'
    meta_type      = 'MyATEvent'
    archetype_name = 'My AT Event'
    immediate_view = 'my_event_view'
    default_view   = 'my_event_view'
    suppl_views    = ()
    typeDescription= 'My cool new event'
    typeDescMsgId  = 'description_edit_my_event'
    assocMimetypes = ()
    assocFileExt   = ('myevent', )

    __implements__ = ATEvent.__implements__

    security       = ClassSecurityInfo()

registerType(MyATEvent, PROJECTNAME)

# For the rest like config.py, __init__.py and skins you should use ArchExample
# as boiler plate
