Skip to content

Instantly share code, notes, and snippets.

@mpampols
Created February 4, 2014 11:24
Show Gist options
  • Save mpampols/8801982 to your computer and use it in GitHub Desktop.
Save mpampols/8801982 to your computer and use it in GitHub Desktop.
This is a sample extended content type for Plone that uses the Event Schema adding some new fields (Image, Categories and Location). Categories field is using a NamedVocabulariy and Location field uses a TTGoogleMapMarker
"""Definition of the imageevent content type
"""
from zope.interface import implements
from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
# -*- Message Factory Imported Here -*-
from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import *
from Products.ATReferenceBrowserWidget import ATReferenceBrowserWidget
from cambrils.contenttypes.interfaces import Iesdeveniment
from cambrils.contenttypes.config import PROJECTNAME
from cambrils.contenttypes import contenttypesMessageFactory as _
from Products.ATVocabularyManager import NamedVocabulary
from Products.ATContentTypes.content import event
from Products.ATContentTypes.content.event import ATEvent
from Products.ATContentTypes.content.event import ATEventSchema
from Products.ATContentTypes.interfaces import IATEvent
from Products.ATContentTypes.interface.interfaces import ICalendarSupport
from Products.ATContentTypes.lib import calendarsupport as cs
from Products.ATContentTypes.lib.calendarsupport import CalendarSupportMixin
from Products.ATContentTypes.lib.historyaware import HistoryAwareMixin
imageeventSchema = event.ATEventSchema.copy() + atapi.Schema((
# -*- Your Archetypes field definitions here ... -*-
atapi.ImageField(
'Image',
storage=atapi.AnnotationStorage(),
widget=atapi.ImageWidget(
label=_(u"Related image"),
description=_(u"Select the main news item image."),
),
required=False,
sizes={'mini': (86, 61), 'normal': (160, 120), 'medium': (290, 144), 'big': (640, 210)},
),
atapi.StringField(
'Categories',
widget=atapi.SelectionWidget(
label="Categories",
),
vocabulary=NamedVocabulary("""agenda""")
),
atapi.ReferenceField(
'Location',
widget=ReferenceBrowserWidget(
label="Location",
),
relationship='MapMarker',
allowed_types=("TTGoogleMapMarker"),
multiValued=True,
),
))
# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.
imageeventSchema['title'].storage = atapi.AnnotationStorage()
imageeventSchema['description'].storage = atapi.AnnotationStorage()
schemata.finalizeATCTSchema(imageeventSchema, moveDiscussion=False)
class imageevent(base.ATCTContent, CalendarSupportMixin, HistoryAwareMixin):
"""Extended event type with images"""
implements(Iimageevent)
meta_type = "imageevent"
schema = imageeventSchema
title = atapi.ATFieldProperty('title')
description = atapi.ATFieldProperty('description')
# -*- Your ATSchema to Python Property Bridges Here ... -*-
Imatge = atapi.ATFieldProperty('Imatge')
atapi.registerType(imageevent, PROJECTNAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment