Skip to content

Instantly share code, notes, and snippets.

@mpampols
Created February 4, 2014 11:35
Show Gist options
  • Save mpampols/8802132 to your computer and use it in GitHub Desktop.
Save mpampols/8802132 to your computer and use it in GitHub Desktop.
A Plone content type used for baners with a string URL and a Reference Field to any other content type
"""Definition of the banner 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.Archetypes.public import BaseContent
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.content.schemata import ATContentTypeSchema
from Products.ATContentTypes.content.schemata import finalizeATCTSchema
from Products.ATContentTypes.content import image
from Products.ATReferenceBrowserWidget.ATReferenceBrowserWidget import ReferenceBrowserWidget
bannerSchema = image.ATImageSchema.copy() + atapi.Schema((
# -*- Your Archetypes field definitions here ... -*-
atapi.StringField(
'LinkUrl',
storage=atapi.AnnotationStorage(),
widget=atapi.StringWidget(
label=_(u"Link (URL)")
),
),
atapi.ReferenceField(
'ContentLink',
widget=ReferenceBrowserWidget(
label=_(u"Link to content")
),
index_method="_at_edit_accessor",
relationship='IsReferencedTo',
multiValued=0,
),
))
# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.
bannerSchema['title'].storage = atapi.AnnotationStorage()
bannerSchema['description'].storage = atapi.AnnotationStorage()
schemata.finalizeATCTSchema(bannerSchema, moveDiscussion=False)
class banner(base.ATCTContent):
"""Banner"""
implements(Ibanner)
meta_type = "banner"
schema = bannerSchema
title = atapi.ATFieldProperty('title')
description = atapi.ATFieldProperty('description')
# -*- Your ATSchema to Python Property Bridges Here ... -*-
LinkUrl = atapi.ATFieldProperty('LinkUrl')
ContentLink = atapi.ATFieldProperty('ContentLink')
atapi.registerType(banner, PROJECTNAME)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment