from AccessControl import ClassSecurityInfo from Products.Archetypes.public import * import Products.generator.i18n as i18n from config import PROJECTNAME, VIDEO_METATYPE, CATEGORY_METATYPE class Category(BaseFolder): ''' A subject in the classification scheme ''' security = ClassSecurityInfo() portal_type = meta_type = CATEGORY_METATYPE archetype_name = 'Category' #this name appears in the 'add' box schema=BaseFolderSchema + Schema(( BooleanField('isSelectable', widget=BooleanWidget(description='Enter a value for isSelectable.', description_msgid='help_isSelectable', i18n_domain='videolibrary', label='Isselectable', label_msgid='label_isSelectable', ), ), LinesField('synonyms', widget=LinesWidget(description='Enter a value for synonyms.', description_msgid='help_synonyms', i18n_domain='videolibrary', label='Synonyms', label_msgid='label_synonyms', ), ), ), ) #Methods security.declareProtected('''View''','getLevel') def getLevel(self): ''' Returns the depth of this subject in the subject tree where the top level is level 1. ''' return len(list(self._getSubjectsToParent())) security.declareProtected('''View''','getFullSubject') def getFullSubject(self): ''' Returns a list of subject strings for related items portlet Simply returns the full path. XXX: Do something with synonyms. ''' mypath = self.getPath() keywords = [ mypath ] return keywords security.declareProtected('''View''','getPath') def getPath(self): ''' Returns the / separated path to the subject ''' subjects = [s.Title() for s in self._getSubjectsToParent()] subjects.reverse() return '/'.join(subjects) security.declareProtected('''View''','getPathElements') def getPathElements(self): ''' Returns path elements as a list. For use with translation. ''' subjects = [ s.Title() for s in self._getSubjectsToParent() ] subjects = [ i18n.translate('videolibrary', s, {}, context=self.aq_parent, default=s) for s in subjects ] subjects.reverse() return subjects security.declareProtected('''View''','getTranslatedPath') def getTranslatedPath(self): ''' Returns path in current language ''' return '/'.join(self.getPathElements()) #manually created methods def _getSubjectsToParent(self): ''' Generates a sequences of subjects from this one up to the top level ''' yield self p = self.aq_parent while p.meta_type == CATEGORY_METATYPE: yield p p = p.aq_parent def indexObject(self): '''Subjects should never be catalogued''' pass def reindexObject(self, idxs=[]): '''Subjects should never be catalogued''' pass def unindexObject(self): '''This shouldn't be indexed, so no need to unindex.''' pass def Subject(self): ''' Override the metadata method to prevent an Category being indexed under itself ''' return () factory_type_information={ 'allowed_content_types':( CATEGORY_METATYPE, VIDEO_METATYPE ), 'allow_discussion': 0, 'immediate_view':'base_view', 'global_allow':0, 'filter_content_types':1, } actions= ( {'action': '''string:$object_url/category_view''', 'category': '''object''', 'id': 'view', 'name': 'view', 'permissions': ('''View''',), 'condition' : 'python: True'}, {'action': '''string:$object_url/base_edit''', 'category': '''object''', 'id': 'edit', 'name': 'Edit', 'permissions': ('''Modify portal content''',), 'condition' : 'python: True'}, ) def containedCategories(self): return self.objectValues((CATEGORY_METATYPE,)) registerType(Category, PROJECTNAME)