from Products.ATContentTypes.config import HAS_LINGUA_PLONE from Products.Meudon_Skin.config import PROJECTNAME, GLOBALS from Products.CutImageField import CutImageField if HAS_LINGUA_PLONE: from Products.LinguaPlone.public import * else: from Products.Archetypes.public import * from ComputedAttribute import ComputedAttribute from Acquisition import aq_base from AccessControl import ClassSecurityInfo from Products.CMFCore.permissions import ModifyPortalContent, View from Products.ATContentTypes.configuration import zconf from Products.ATContentTypes.content.base import updateActions, updateAliases from Products.RichDocument.content.richdocument import RichDocumentSchema from Products.RichDocument.content.richdocument import RichDocument from Products.ATContentTypes.content.image import ATImageSchema from Products.ATContentTypes.content.image import ATImage from Products.ATContentTypes.content.schemata import finalizeATCTSchema from Products.ATContentTypes.content.base import registerATCT from Products.ATContentTypes.interfaces import IATImage from Products.ATContentTypes.content.base import ATCTFileContent from Products.ATContentTypes.lib.imagetransform import ATCTImageTransform from Products.validation import V_REQUIRED ThumbnailedRichDocumentSchema = RichDocumentSchema.copy() ThumbnailedRichDocumentSchema = ThumbnailedRichDocumentSchema + Schema(( StringField( name='section', required=False, searchable=True, default='', accessor='Section', widget=StringWidget( label="Section", label_msgid='label_section', description = "", i18n_domain='plone', ), ), TextField('notes', required=False, searchable=True, primary=False, storage = AnnotationStorage(migrate=True), validators = ('isTidyHtmlWithCleanup',), #validators = ('isTidyHtml',), default_content_type = zconf.ATDocument.default_content_type, default_output_type = 'text/x-html-safe', allowable_content_types = zconf.ATDocument.allowed_content_types, widget = RichWidget( description = "", description_msgid = "help_body_notes", label = "Notes", label_msgid = "label_body_notes", rows = 25, i18n_domain = "plone", allow_file_upload = zconf.ATDocument.allow_document_upload,)), CutImageField('thumbnail', required=False, primary=False, languageIndependent=True, storage = AnnotationStorage(migrate=True), swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable, pil_quality = zconf.pil_config.quality, pil_resize_algo = zconf.pil_config.resize_algo, max_size = zconf.ATImage.max_image_dimension, sizes= { 'thumbnail' : (75, 100), 'smallthumb' : (55, 75), 'icon' : (45, 45), }, cut= { 'thumbnail':1, 'smallthumb':1, 'icon' : 1, }, validators = (('isNonEmptyFile', V_REQUIRED), ('checkImageMaxSize', V_REQUIRED)), widget = ImageWidget( #description = "Select the image to be added by clicking the 'Browse' button.", #description_msgid = "help_image", description = "Thumbnail shown in section root and in portlets", description_msgid = "help_richdocument_imagette", label= "Thumbnail", label_msgid = "label_richdocument_imagette", i18n_domain = "plone", show_content_type = False,)), ), marshall=PrimaryFieldMarshaller()) finalizeATCTSchema(ThumbnailedRichDocumentSchema) # now we have a schema with an icon field which can contain an image as primary field # creating a new type called ThumbnailedRichDocument class ThumbnailedRichDocument(RichDocument, ATImage): """A document which may contain directly uploaded images and attachments.""" schema = ThumbnailedRichDocumentSchema meta_type = 'ThumbnailedRichDocument' portal_type = 'RichDocument' archetype_name = 'Rich document' content_icon = 'RichDocument.gif' typeDescription = 'A document which can contain rich text, images and attachments' typeDescMsgId = 'RichDocument_description_edit' _atct_newTypeFor = {'portal_type' : 'RichDocument', 'meta_type' : 'RichDocument'} # Allow images and files to be uploaded into this containerish object allowed_content_types = ['ImageAttachment', 'FileAttachment'] # Set up our views - these are available from the 'display' menu default_view = 'richdocument_view' immediate_view = 'richdocument_view' suppl_views = ('richdocument_view_preview', 'richdocument_view_float') # Make sure we get title-to-id generation when an object is created _at_rename_after_creation = True __implements__ = RichDocument.__implements__, ATImage.__implements__ # Get the standard actions (tabs) actions = RichDocument.actions security = ClassSecurityInfo() security.declareProtected(ModifyPortalContent, 'setThumbnail') def setThumbnail(self, value, refresh_exif=True, **kwargs): """Set id to uploaded id """ # set exif first because rotation might screw up the exif data # the exif methods can handle str, Pdata, OFSImage and file # like objects if value: self.getEXIF(value, refresh=refresh_exif) field = self.getField('thumbnail') field.set(self, value, **kwargs) security.declareProtected(View, 'tag') def tag(self, **kwargs): """Generate image tag using the api of the ImageField """ return self.getField('thumbnail').tag(self, **kwargs) def __bobo_traverse__(self, REQUEST, name): """Transparent access to thumbnail scales """ if name.startswith('thumbnail'): field = self.getField('thumbnail') image = None if name == 'thumbnail': image = field.getScale(self) else: scalename = name[len('thumbnail_'):] if scalename in field.getAvailableSizes(self): image = field.getScale(self, scale=scalename) if image is not None and not isinstance(image, basestring): # image might be None or '' for empty images return image return RichDocument.__bobo_traverse__(self, REQUEST, name) registerATCT(ThumbnailedRichDocument, PROJECTNAME)