class ImageBlobAttachment(object): adapts(IImageAttachment) implements(ISchemaExtender) fields = [ ImageField( 'image', required=True, primary=True, accessor='getImage', mutator='setImage', sizes=None, languageIndependent=True, storage=AnnotationStorage(migrate=True), swallowResizeExceptions=zconf.swallowImageResizeExceptions.enable, pil_quality=zconf.pil_config.quality, pil_resize_algo=zconf.pil_config.resize_algo, original_size=None, max_size=zconf.ATImage.max_image_dimension, default_content_type='image/png', allowable_content_types=('image/gif', 'image/jpeg', 'image/png'), validators=(('isNonEmptyFile', V_REQUIRED), ('checkImageMaxSize', V_REQUIRED)), widget=ImageWidget( label=_('label_image', default='Image'), description=_(''), show_content_type=False, )), ] def __init__(self, context): self.context = context def getFields(self): return self.fields
class Red5StreamExtender(object): adapts(IRed5Stream) implements(ISchemaExtender) fields = [ ExtensionBlobField('file', required=True, primary=True, searchable=True, default='', read_permission=DownloadRed5Stream, index_method='getIndexValue', languageIndependent=True, storage=AnnotationStorage(migrate=True), validators=(('isNonEmptyFile', V_REQUIRED), ('checkFileMaxSize', V_REQUIRED)), widget=FileWidget( label=_(u'label_file', default=u'File'), description=_(u''), show_content_type=False, )) ] def __init__(self, context): self.context = context def getFields(self): return self.fields
class FileBlobAttachment(object): adapts(IFileAttachment) implements(ISchemaExtender) fields = [ FileField('file', required=True, primary=True, searchable=True, accessor='getFile', mutator='setFile', index_method='getIndexValue', languageIndependent=True, storage=AnnotationStorage(migrate=True), default_content_type='application/octet-stream', validators=(('isNonEmptyFile', V_REQUIRED), ('checkFileMaxSize', V_REQUIRED)), widget=FileWidget( label=_('label_file', default='File'), description=_(''), show_content_type=False, )), ] def __init__(self, context): self.context = context def getFields(self): return self.fields
def testModificationTimeDuringInlineImageMigration(self): foo = self.folder[self.folder.invokeFactory('Image', id='foo')] foo.schema['image'] = ImageField('image', storage=AnnotationStorage()) foo.schema['image'].set(foo, getImage()) # record the modification date before migration mod = foo.modified() # migrate using inline migrator migrate(self.portal, portal_type='Image', meta_type='ATBlob') # the modification date isn't changed by migration self.assertEqual(mod, foo.modified()) # cleanup del foo.schema['image']
def test_storageNonExisting(self): dummy = self.dummy storage = AnnotationStorage() self.assertRaises(AttributeError, storage.get, 'nonexisting', dummy) # del shouldn't raise anything storage.unset('nonexisting', dummy) # set should create an entry storage.set('nonexisting', dummy, value='bar') self.assertEqual(storage.get('nonexisting', dummy), 'bar')
def get_file_field(): return FileField('file', required=True, primary=True, searchable=True, languageIndependent=True, storage=AnnotationStorage(migrate=True), validators=(('isNonEmptyFile', V_REQUIRED), ('checkFileMaxSize', V_REQUIRED)), widget=FileWidget( description='', label='File', show_content_type=False, ))
def testOldScalesRemovedDuringInlineImageMigration(self): gif = getImage() foo = self.folder[self.folder.invokeFactory('Image', id='foo', title='an image', image=gif)] # fake an old ImageField in the class schema, # and store scales in AnnotationStorage foo.schema['image'] = ImageField('image', storage=AnnotationStorage()) foo.schema['image'].set(foo, gif) isimage = lambda i: isinstance(i, Image) self.assertTrue(filter(isimage, IAnnotations(foo).values())) # migrate using inline migrator migrate(self.portal, portal_type='Image', meta_type='ATBlob') # make sure all scale annotations were removed self.assertFalse(filter(isimage, IAnnotations(foo).values())) # cleanup del foo.schema['image']
def test_storageNonExisting(self): dummy = self.dummy storage = AnnotationStorage() self.assertRaises(AttributeError, storage.get, 'nonexisting', dummy) # del shouldn't raise anything storage.unset('nonexisting', dummy) # set should create an entry storage.set('nonexisting', dummy, value='bar') self.assertEqual(storage.get('nonexisting', dummy), 'bar')
def getFields(self): """ change the field to be languageIndependant = False""" return [ ExtensionBlobField('file', required=True, primary=True, searchable=True, default='', accessor='getFile', mutator='setFile', index_method='getIndexValue', languageIndependent=False, storage=AnnotationStorage(migrate=True), validators=(('isNonEmptyFile', V_REQUIRED), ('checkFileMaxSize', V_REQUIRED)), widget=FileWidget( label=_(u'File'), description=_(u''), show_content_type=False, )) ]
def get_image_field(): return ImageField( 'image', required=True, primary=True, languageIndependent=True, storage=AnnotationStorage(migrate=True), max_size=10.0, maxsize=10.0, # The validator is searching on field for maxsize sizes={ 'large': (768, 768), 'preview': (400, 400), 'mini': (200, 200), 'thumb': (128, 128), 'tile': (64, 64), 'icon': (32, 32), 'listing': (16, 16), }, validators=(('isNonEmptyFile', V_REQUIRED), ('checkImageMaxSize', V_REQUIRED)), widget=ImageWidget(description='', label=u'Image', show_content_type=False))
required_for_published=False, required=False, allowable_content_types=('text/html',), default_content_type="text/html", default_output_type="text/x-html-safe", widget=TextAreaWidget( label="Embed code", description=("Tableau embed code should be pasted here."), label_msgid='EEAContentTypes_label_embed', i18n_domain='eea',), ), ImageField('image', required=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=None, validators=(('isNonEmptyFile', V_REQUIRED), ('imageMinSize', V_REQUIRED)), widget=ImageWidget( description='High-res preview image ' \ '(at least FHD 1920x1080). ' \ 'If the image is removed, a new image will ' \ 'automatically be created after saving', label='Preview image', show_content_type=False, )
from ZODB.POSException import ConflictError from zope.event import notify from zope.interface import implementer from zope.lifecycleevent import ObjectCreatedEvent from zope.lifecycleevent import ObjectModifiedEvent try: from Products.LinguaPlone.public import registerType registerType # make pyflakes happy... except ImportError: from Products.Archetypes.atapi import registerType ATBlobSchema = ATContentTypeSchema.copy() ATBlobSchema['title'].storage = AnnotationStorage() # titles not required for blobs, because we'll use the filename if missing ATBlobSchema['title'].required = False finalizeATCTSchema(ATBlobSchema, folderish=False, moveDiscussion=False) ATBlobSchema.registerLayer('marshall', BlobMarshaller()) try: from Products.CMFCore.CMFCatalogAware import WorkflowAware WorkflowAware # make pyflakes happy... # CMF 2.2 takes care of raising object events for old-style factories hasCMF22 = True except ImportError: hasCMF22 = False
description="Url set by Kaltura after upload (read only)", visible = { 'edit' :'visible', 'view' : 'visible' }, i18n_domain="kaltura_video") ), ), marshall=RFC822Marshaller() ) KalturaVideoSchema += KalturaBase.KalturaMetadataSchema.copy() KalturaVideoSchema += ATContentTypeSchema.copy() # Set storage on fields copied from ATContentTypeSchema, making sure # they work well with the python bridge properties. KalturaVideoSchema.get('title').storage = AnnotationStorage() KalturaVideoSchema[ 'categories'].widget.description = "Select category(ies) this video will belong to" KalturaVideoSchema[ 'categories'].widget.description_msgid = "desc_kvideo_categories" KalturaVideoSchema[ 'tags'].widget.description = "keyword tags to place on this video (one per line)" KalturaVideoSchema['tags'].widget.description_msgid = "desc_kvideo_tags" finalizeATCTSchema(KalturaVideoSchema, moveDiscussion=False) class KalturaVideo(ATBlob, KalturaBase.KalturaContentMixin): """Kaltura Video Content Type - stores the video file on your Kaltura account""" implements(IKalturaVideo, IATBlobFile, IATFile, IFileContent)
getAnnotation, AT_ANN_STORAGE from Products.Archetypes.tests.test_classgen import Dummy from Products.Archetypes.tests.test_classgen import gen_class from Products.Archetypes.tests.test_classgen import gen_dummy from Acquisition import aq_base class AnnDummy(Dummy): pass annschema = BaseSchema + Schema(( StringField( 'string', default=u'stringdefault', storage=AnnotationStorage(), ), StringField( 'meta', default='metadefault', storage=MetadataAnnotationStorage(), ), )) def gen_anndummy(): gen_class(AnnDummy, annschema) class AnnotationTest(ATSiteTestCase): def afterSetUp(self):
class SlideshowExtender(object): adapts(IATDocument) implements(ISchemaExtender, IBrowserLayerAwareExtender) layer = IUOLImagesThemeLayer fields = [ ExReferenceField('slideshow_gallery', schemata='slideshow', relationship='relatesToGallery', multiValued=True, write_permission=ModifyPortalContent, allowed_types=("Gallery", ), keepReferencesOnCopy=True, storage=AnnotationStorage(), widget=ReferenceBrowserWidget( allow_search=True, allow_browse=True, show_indexes=False, force_close_on_insert=True, label=u'Slideshow gallery', ) ), ExIntegerField('image_count', schemata='slideshow', required=True, default=0, write_permission = ModifyPortalContent, languageIndependent=True, storage=AnnotationStorage(), widget=StringWidget( description='Enter 0 for all images', label=u'Number of images to show' ) ), ExBooleanField('show_captions', default=True, schemata='slideshow', widget = BooleanWidget( label="Show image captions" ) ), ExIntegerField('time_delay', schemata='slideshow', required=True, default=2, write_permission = ModifyPortalContent, languageIndependent=True, storage=AnnotationStorage(), widget=StringWidget( description='', label=u'Time delay in seconds' ) ), ExStringField('scale', schemata='slideshow', required=True, default='preview', write_permission = ModifyPortalContent, languageIndependent=True, vocabulary_factory="uniofleicester.jsimages.imagesscalevocabulary", enforceVocabulary=1, storage=AnnotationStorage(), widget=SelectionWidget( description='', label=u'Image scale to display' ) ), ] def __init__(self, context): self.context = context def getFields(self): return self.fields