def create_subobjects(self, context, total=0, types=None): request = self.request amount = int(request.get('amount', 3)) if types is None: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder or ' \ 'provide a type argument.') addStatusMessage(request, msg) return total else: msg = _("The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(request, msg) return total for portal_type in types: if portal_type in ['File', 'Image', 'Folder']: continue for n in range(0, amount): obj = self.create_object(context, portal_type) total += 1 if request.get('recurse'): total = self.create_subobjects(obj, total=total, types=None) return total
def test_implements(self): if self.dummy is not None: self.failIf(IReferenceable.providedBy(self.dummy)) self.failIf(IExtensibleMetadata.providedBy(self.dummy)) self.failIf(self.dummy.isReferenceable) self.failUnless(IBaseContent.providedBy(self.dummy)) self.failUnless(IATTopicCriterion.providedBy(self.dummy)) self.failUnless(verifyObject(IBaseContent, self.dummy)) self.failUnless(verifyObject(IATTopicCriterion, self.dummy))
def test_implements(self): if self.dummy is not None: self.assertFalse(IReferenceable.providedBy(self.dummy)) self.assertFalse(IExtensibleMetadata.providedBy(self.dummy)) self.assertFalse(self.dummy.isReferenceable) self.assertTrue(IBaseContent.providedBy(self.dummy)) self.assertTrue(IATTopicCriterion.providedBy(self.dummy)) self.assertTrue(verifyObject(IBaseContent, self.dummy)) self.assertTrue(verifyObject(IATTopicCriterion, self.dummy))
def create_subobjects(root, context, data, total=0): amount = int(data.get('amount', 3)) types = data.get('portal_type') if types is None: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = component.getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder or ' \ 'provide a type argument.') addStatusMessage(context.request, msg) return total else: msg = _("The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(context.request, msg) return total recurse = False if data.get('recurse', None) not in [None, '0', 'False', False]: depth = 0 node = context while IUUID(node) != IUUID(root): depth += 1 node = node.aq_parent if depth < data.get('recursion_depth'): recurse = True for portal_type in types: for n in range(0, amount): obj = create_object(context, portal_type, data) total += 1 if not IObjectManager.providedBy(obj): continue if recurse: if shasattr(obj, 'getLocallyAllowedTypes'): data['portal_type'] = \ list(obj.getLocallyAllowedTypes()) elif shasattr(obj, 'allowedContentTypes'): data['portal_type'] = \ [t.id for t in obj.allowedContentTypes()] total = create_subobjects(root, obj, data, total) return total
def test_seo_description(self): """Ticket #999: All content types should be extended with a new field called seoDescription. This field should appear directly underneath the normal description field. """ # import sys; sys.sdtout = file('/dev/stdout', 'w') ttool = getToolByName(self.portal, 'portal_types') not_extended = open("not_extended.txt", 'w') extended_properly = open("extended_properly", "w") wrong_order = open("wrong_order.txt", 'w') for type_name in ttool.listContentTypes(): info = ttool.getTypeInfo(type_name) try: obj = info.constructInstance(self.portal, type_name) except Unauthorized: continue except: continue if not IBaseContent.providedBy(obj): continue if IATTopicCriterion.providedBy(obj): continue field_obs = obj.Schema().getSchemataFields('default') fields = [f.__name__ for f in field_obs] # assert('seoDescription' in fields) # self.assertEquals( # fields.index('seoDescription'), # fields.index('description')+1 # ) if "seoDescription" not in fields: not_extended.write("Not extended: %s \n" % type_name) elif (fields.index('seoDescription') != fields.index('description') + 1): wrong_order.write("Wrong order: %s \n" % type_name) else: extended_properly.write("%s \n" % type_name) not_extended.close() wrong_order.close() extended_properly.close()
def _getCompetitionsWithImages(self, query): """ Get competitions (subfolders) with a default view object which has a related image """ result = list() competitions = self._getCompetitions(query) for competition in competitions: images = '' default_view = getattr(competition, competition.defaultView()) item = competition if IBaseContent.providedBy(default_view): images = self.getRelatedImages(default_view, 'mini') item = default_view result.append(dict(item=item, images=images)) return result
def patch_object(obj): logger.debug("Patching Object \"%s\" on path: %s" , \ (obj.title, obj.absolute_url() ) ) container = obj.getParentNode() if container and container.isPrincipiaFolderish: logger.debug("Object Type is %s", obj.portal_type) logger.debug("Object Parent is %s", container.absolute_url()) if HAS_ARCHETYPES and IBaseContent.providedBy(obj): # Archetype Object for field in obj.schema.fields(): if field.getType() == "Products.Archetypes.Field.TextField": name = field.getName() logger.debug( "Object \"%s\" is a Archetypes Type that has a field: \"%s\" that is a Archetype TextField that could hold HTML", (obj.title, field.getName())) field_content = field.getRaw(obj) if "base64" in field_content: new_content = patch(container, obj, name, field_content) field.getMutator(obj)(new_content) elif HAS_DEXTERITY and IDexterityContent.providedBy(obj): # Dexterity Object pt = obj.getTypeInfo() schema = pt.lookupSchema() for name in zope.schema.getFields(schema).keys(): logger.debug("Object Field Name is %s", name) logger.debug( "Object Field Type is %s" , \ str( type( getattr(obj, name) ).__name__ ) ) if type(getattr(obj, name)).__name__ == "RichTextValue": logger.debug("object %s is a Dexterity Type", obj.title) field_content = getattr(obj, name).raw if "base64" in field_content: new_content = patch(container, obj, name, field_content) getattr(obj, name).__init__(raw=new_content) else: logger.debug("Unknown Content-Type-Framework for %s", obj.absolute_url())
def patch_object(obj): logger.debug("Patching Object \"%s\" on path: %s" , \ (obj.title, obj.absolute_url() ) ) container = obj.getParentNode() if container and container.isPrincipiaFolderish: logger.debug( "Object Type is %s" , obj.portal_type) logger.debug( "Object Parent is %s" , container.absolute_url() ) if HAS_ARCHETYPES and IBaseContent.providedBy(obj): # Archetype Object for field in obj.schema.fields(): if field.getType() == "Products.Archetypes.Field.TextField": name = field.getName() logger.debug( "Object \"%s\" is a Archetypes Type that has a field: \"%s\" that is a Archetype TextField that could hold HTML" , (obj.title, field.getName()) ) field_content = field.getRaw(obj) if "base64" in field_content: new_content = patch(container, obj, name, field_content) field.getMutator(obj)(new_content) elif HAS_DEXTERITY and IDexterityContent.providedBy(obj): # Dexterity Object pt = obj.getTypeInfo() schema = pt.lookupSchema() for name in zope.schema.getFields(schema).keys(): logger.debug( "Object Field Name is %s" , name ) logger.debug( "Object Field Type is %s" , \ str( type( getattr(obj, name) ).__name__ ) ) if type(getattr(obj, name)).__name__ == "RichTextValue": logger.debug( "object %s is a Dexterity Type" , obj.title ) field_content = getattr(obj, name).raw if "base64" in field_content: new_content = patch(container, obj, name, field_content) getattr(obj, name).__init__(raw=new_content) else: logger.debug( "Unknown Content-Type-Framework for %s" , obj.absolute_url() )
def create_subobjects(self, context, total=0, types=None): request = self.request amount = int(request.get('amount', 3)) if types is None: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder or ' \ 'provide a type argument.') addStatusMessage(request, msg) return total else: msg = _( "The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(request, msg) return total for portal_type in types: if portal_type in ['File', 'Image', 'Folder']: continue for n in range(0, amount): obj = self.create_object(context, portal_type) total += 1 if request.get('recurse'): total = self.create_subobjects(obj, total=total, types=None) return total
def test_doesImplementAT(self): self.failUnless(IBaseContent.providedBy(self._ATCT)) self.failUnless(IReferenceable.providedBy(self._ATCT)) self.failUnless(verifyObject(IBaseContent, self._ATCT)) self.failUnless(verifyObject(IReferenceable, self._ATCT))
def test_doesImplementAT(self): self.assertTrue(IBaseContent.providedBy(self._ATCT)) self.assertTrue(IReferenceable.providedBy(self._ATCT)) self.assertTrue(verifyObject(IBaseContent, self._ATCT)) self.assertTrue(verifyObject(IReferenceable, self._ATCT))
def create_subobjects(root, context, data, total=0): amount = int(data.get('amount', 3)) types = data.get('portal_type') request = getRequest() depth = 0 node = context if not IPloneSiteRoot.providedBy(root): while IUUID(node) != IUUID(root): depth += 1 node = node.aq_parent else: while not IPloneSiteRoot.providedBy(node): depth += 1 node = node.aq_parent if types is None or depth > 0: base = aq_base(context) if IBaseContent.providedBy(base): types = [] if hasattr(base, 'constrainTypesMode') and base.constrainTypesMode: types = context.locallyAllowedTypes elif IDexterityContent.providedBy(base): fti = component.getUtility(IDexterityFTI, name=context.portal_type) types = fti.filter_content_types and fti.allowed_content_types if not types: msg = _('Either restrict the addable types in this folder ' 'or provide a type argument.') addStatusMessage(request, msg) return total else: msg = _("The context doesn't provide IBaseContent or " "IDexterityContent. It might be a Plone Site object, " "but either way, I haven't gotten around to dealing with " "it. Why don't you jump in and help?") addStatusMessage(request, msg) return total recurse = False if data.get('recurse', None) not in [None, '0', 'False', False] and \ depth < data.get('recursion_depth'): recurse = True for portal_type in types: for n in range(0, amount): obj = create_object(context, portal_type, data) total += 1 if not IObjectManager.providedBy(obj): continue if recurse: if not data.get('recurse_same_ptypes', False): if shasattr(obj, 'getLocallyAllowedTypes'): data['portal_type'] = \ list(obj.getLocallyAllowedTypes()) elif shasattr(obj, 'allowedContentTypes'): data['portal_type'] = \ [t.id for t in obj.allowedContentTypes()] total = create_subobjects(root, obj, data, total) return total