#Zope from OFS.ObjectManager import BeforeDeleteException # CMF from Products.CMFCore import CMFCorePermissions # AT from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import BaseContent, registerType from Products.Archetypes.Marshall import PrimaryFieldMarshaller # Fields from Products.Archetypes.public import StringField, TextField, ReferenceField from Products.Archetypes.public import ImageField, DateTimeField # Widgets from Products.Archetypes.public import SelectionWidget, RichWidget, ImageWidget from Products.Archetypes.public import StringWidget, CalendarWidget, VisualWidget # PloneRailroadVideoLibrary from config import PROJECTNAME, VIDEO_METATYPE, CATEGORY_METATYPE from config import VIDEO_LIBRARY_ID, AVAILABLE_MEDIUMS from utils import updateActions from Products.PloneRailroad import PloneRailroadProxyMixin from Products.PloneRailroadVideoLibrary.TreeWidget import CategoryTreeWidget try: from Products.ATRepresentations.public import * print "Representations support" except ImportError: from Products.Archetypes.public import * print "No representations support" """ * still image/thumbnail * file format * video resolution * creator of the video itself (the creator of the Video object in the VideoLibrary is of course in the metadata already) * time of creation * original medium (VHS, film, etc.) * original's reference/number. * categories * short summary of the video's content (but we could use the description metadata field for this) """ schema = Schema(( ImageField( 'stillimage', representationIndependent=1, widget=ImageWidget( description='''Representative still image or thumbnail''', description_msgid='help_stillimage', i18n_domain='videolibrary', label='Still image', label_msgid='label_stillimage',), ), StringField( 'fileformat', vocabulary='getFileformats', widget=SelectionWidget( description='''File format of this representation''', description_msgid='help_fileformat', i18n_domain='videolibrary', label='File format', label_msgid='label_fileformat',), ), StringField( 'resolution', widget=StringWidget( description='''Resolution of this representation''', description_msgid='help_resolution', i18n_domain='videolibrary', label='Resolution', label_msgid='label_resolution',), ), # StringField( # 'creator', # representationIndependent=1, # widget=StringWidget( # description='''Creator of the original video''', # description_msgid='help_creator', # i18n_domain='videolibrary', # label='Creator', # label_msgid='label_creator',), # ) DateTimeField( 'creationdatetime', representationIndependent=1, widget=CalendarWidget( description='''Creation date and time of the original video''', description_msgid='help_creationdatetime', i18n_domain='videolibrary', label='Creation date', label_msgid='label_creationdatetime',), ), StringField( 'medium', representationIndependent=1, vocabulary='getMediums', widget=SelectionWidget( description='''Type of medium of the original video''', description_msgid='help_medium', i18n_domain='videolibrary', label='Medium', label_msgid='label_medium',), ), StringField( 'referencenumber', representationIndependent=1, widget=StringWidget( description='''Reference of the original video''', description_msgid='help_referencenumber', i18n_domain='videolibrary', label='Reference', label_msgid='label_referencenumber',), ), ReferenceField( 'categories', representationIndependent=1, allowed_types=(CATEGORY_METATYPE,), multiValued=1, relationship='categories', vocabulary=(), index='KeywordIndex', default=(), widget=CategoryTreeWidget( description='''Select subjects categorizing this video''', description_msgid='help_categories', i18n_domain='videolibrary', label='Categories', label_msgid='label_categories', tree=VIDEO_LIBRARY_ID,), ), StringField( 'summary', searchable=1, representationIndependent=1, default_output_type='text/html', allowable_content_types=( 'text/plain', 'text/html', ), widget=RichWidget( description='''Summary of the video's content''', description_msgid='help_summary', i18n_domain='videolibrary', label='Summary', label_msgid='label_summary', ), ), )) class Video(BaseContent, PloneRailroadProxyMixin.Mixin): """ Basic video object """ portal_type = meta_type = VIDEO_METATYPE archetype_name = 'Video' schema = BaseSchema + schema + PloneRailroadProxyMixin.Mixin.schema factory_type_information = { 'allow_discussion': 0, 'immediate_view': 'base_view', 'global_allow': 0, } actions = updateActions( BaseContent, PloneRailroadProxyMixin.Mixin.actions + ( {'action': '''string:$object_url/video_view''', 'category': '''object''', 'id': 'view', 'name': 'View', 'permissions': ('''View''',), 'condition' : 'python:1'},) ) def getFileformats(self): return ('video/quicktime', 'video/mp4',) def getMediums(self): return AVAILABLE_MEDIUMS def manage_afterAdd(self, item, container): BaseContent.manage_afterAdd(self, item, container) # Adding the category of the container field = self.getField('categories') accessor = field.getAccessor(self) categories = [category.UID() for category in accessor()] container_category = container.UID() if not container_category in categories: categories.append(container_category) mutator = field.getMutator(self) mutator(categories) # Make sure the default RR service is selected default_service = self.get_default_service() self.set_railroad_service(default_service) def should_resource_be_deleted(self): # XXX consider a change in the proxy interface return True def manage_beforeDelete(self, item, container): storeRefs = getattr(item, '_v_cp_refs', None) if storeRefs is None: # The object is really going away, we want to remove # its resource if self.should_resource_be_deleted(): try: self.on_delete() except Exception, e: raise BeforeDeleteException, str(e) BaseContent.manage_beforeDelete(self, item, container) registerType(Video, PROJECTNAME)