Exemplo n.º 1
0
 def isArticle(self, obj):
     """
     Return True if obj is an Article
     Used by portal_javascript/portal_css ...
     """
     if IPloneArticle.providedBy(obj) :
         return True
Exemplo n.º 2
0
 def isArticle(self, obj):
     """
     Return True if obj is an Article
     Used by portal_javascript/portal_css ...
     """
     if IPloneArticle.providedBy(obj):
         return True
Exemplo n.º 3
0
    def __init__(self, context, request):
        self.context = context
        self.request = request

        self.path = {'query': '/'.join(context.getPhysicalPath()) }
        self.article = request.get('current_article', None)
        if self.article is None:
            raise ValueError, ("%s called without 'current_article' in REQUEST",
                               self.__class__.__name__)
        
        self.field_name = request.get('field_name', None)
        self.scope = request.get('scope', '')
        self.searchTerm = request.get('searchTerm', None)
        if self.field_name is None:
            raise ValueError, (
                "Invalid: %s called without 'field_name' in request"
                % self.__class__.__name__)

        # a proper call is self.queryMethod.aq_inner: if you don't do that,
        # getFolderContents will issue an AttributeError for
        # 'portal_membership', for instance        
        if context.portal_type == 'Topic' or self.searchTerm :
            self.queryMethod = [context.queryCatalog]
            if self.scope=='portal':
               self.path={}
        else:
            self.queryMethod = [context.getFolderContents] 
            self.path['depth']=1
        self.isArticle = IPloneArticle.providedBy(context)
Exemplo n.º 4
0
 def useJquery(self, obj):
     """
     Return True if we're in an article
     and version of plone < 3.1
     """
     pmig = getToolByName(self, 'portal_migration')
     if IPloneArticle.providedBy(obj) and \
        pmig.getFSVersionTuple() < (3, 1) :    
         return True          
Exemplo n.º 5
0
 def useJquery(self, obj):
     """
     Return True if we're in an article
     and version of plone < 3.1
     """
     pmig = getToolByName(self, 'portal_migration')
     if IPloneArticle.providedBy(obj) and \
        pmig.getFSVersionTuple() < (3, 1) :
         return True
    def testInterfaces(self):
        """
        Test presence of interfaces (+z3 interfaces obtained by ZCML)
        """
        from Products.PloneArticle.interfaces import INonStructuralFolder
        from Products.PloneArticle.interfaces import IPloneArticle
        from Products.ATContentTypes.interface import IATDocument

        article = self.article

        self.failUnless(INonStructuralFolder.providedBy(article))
        self.failUnless(IPloneArticle.providedBy(article))
        self.failUnless(IATDocument.providedBy(article))
    def testInterfaces(self):
        """
        Test presence of interfaces (+z3 interfaces obtained by ZCML)
        """
        from Products.PloneArticle.interfaces import INonStructuralFolder
        from Products.PloneArticle.interfaces import IPloneArticle
        from Products.ATContentTypes.interface import IATDocument

        article = self.article

        self.failUnless(INonStructuralFolder.providedBy(article))
        self.failUnless(IPloneArticle.providedBy(article))
        self.failUnless(IATDocument.providedBy(article))
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            if not pathkey:                     # not enough info
                yield item; continue
            obj = self.context.unrestrictedTraverse(item[pathkey].lstrip('/'), None)
            if obj is None:                     # path doesn't exist
                yield item; continue

            def getUnit(x, field_name):
                name = x['id'][0]
                f_path = x[field_name][0]['data']
                x = x[field_name][0]
                if self.datafield_separator:
                    f_path = f_path.replace(self.datafield_separator,
                                            os.path.sep)
                f_name = os.path.basename(f_path)
                f_path = os.path.join(os.path.dirname(\
                    item['_json_file_path']),
                                      f_name)
                
                ###
                ## type2png = image/x-ms-bmp
                value = ''
                if x.get('content_type','') in self.options.get('type2png',''):
                    path = tempfile.mkdtemp()
                    img = Image.open(f_path)
                    new_path = os.path.join(path,'image.png')
                    img.save(new_path)
                    f = open(new_path, mode = 'rb')
                    value = f.read()
                    x['content_type'] =  'image/png'
                    ext = os.path.splitext(x.get('filename', ''))[-1]
                    x['filename'] = x.get('filename','').replace(ext, '.png')
                    try:
                        os.unlink(path)
                    except:
                        pass
                else:
                    f = open(f_path, mode = 'rb')
                    value = f.read()
   

                
                unit = BaseUnit(name = name,
                                file = value,
                                mimetype = x.get('content_type', ''),
                                filename = x.get('filename', ''),
                                instance = obj)
                f.close()
                return unit

            def getReferencedContent(x):
                path = x['referencedContent'][0]
                ## we try to get content
                try:
                    refobj = self.context.restrictedTraverse(path)
                    return (refobj.UID(),{})
                except:
                    item['_error'] = item['_json_file_path']
                    logger.exception('we cant set referencedContent for %s' % path)
                
                
            if IPloneArticle.providedBy(obj):
                
                if '_plonearticle_images' in item and \
                       len(item['_plonearticle_images']):
                    for (i, x) in enumerate(item['_plonearticle_images']) :
                        if 'attachedImage' in x:
                            
                            unit = getUnit(x,'attachedImage')
                            item['_plonearticle_images'][i]['attachedImage']=\
                                                                      (unit,{})
                        elif 'referencedContent' in x:
                            
                            item['_plonearticle_images'][i]['referencedContent']=getReferencedContent(x)
                    try:
                        obj.getField('images').set(obj,item['_plonearticle_images'])
                    except:
                        item['_error'] = item['_json_file_path']
                        #import pdb;pdb.set_trace();
                        logger.exception('cannot set images for %s %s' % \
                                         (item['_path'],
                                          item['_json_file_path'])
                                         )
                if '_plonearticle_attachments' in item and\
                       len(item['_plonearticle_attachments']):

                    for (i, x) in enumerate(item['_plonearticle_attachments']):
                        if 'attachedFile' in x:
                            unit = getUnit(x,'attachedFile')
                            item['_plonearticle_attachments'][i]['attachedFile'] =\
                                                                      (unit,{})
                        elif 'referencedContent' in x:
                            item['_plonearticle_attachments'][i]['referencedContent']=getReferencedContent(x)
                    try:
                        obj.getField('files').set(obj,
                                                  item['_plonearticle_attachments'])
                    except:
                        item['_error'] = item['_json_file_path']
                        #import pdb;pdb.set_trace();
                        logger.exception('cannot set files for %s %s' % \
                                         (item['_path'],
                                          item['_json_file_path'])
                                         )
                if '_plonearticle_refs' in item and \
                       len(item['_plonearticle_refs']):
                    for (i, x) in enumerate(item['_plonearticle_refs']):
                        if 'referencedContent' in x:
                            item['_plonearticle_refs'][i]['referencedContent']=getReferencedContent(x)
                    try:
                        obj.getField('links').set(obj,
                                                  item['_plonearticle_refs'])
                    except:
                        
                        item['_error'] = item['_json_file_path']
                        logger.exception('cannot set links for %s %s' % \
                                         (item['_path'],
                                          item['_json_file_path'])
                                         )
            yield item