def _deploy_content(self, obj, is_page=True):
        """
        Deploy object as page.
        """
        try:
            new_req, orig_req = fakeRequest(obj)
        except AttributeError:
            # not a valid obj to override request with
            new_req = None
        content = self._render_obj(obj)
        if content is None:
            return

        filename = obj.absolute_url_path().lstrip("/")
        # deploy additional views for content type
        if PLONE_APP_BLOB_INSTALLED and isinstance(obj, ATBlob):
            self._deploy_views([os.path.join(filename, "view")], is_page=True)

        if is_page:
            filename = filename.rstrip("/")
            if self.add_index or IFolder.providedBy(obj):
                filename = os.path.join(filename, "index.html")
            elif not filename.endswith(".htm") and not filename.endswith(".html"):
                filename = filename + ".html"
        elif (
            isinstance(obj, ATImage)
            or hasattr(obj, "getBlobWrapper")
            and "image" in obj.getBlobWrapper().getContentType()
        ):
            # create path to dump ATImage in original size
            if filename.rsplit(".", 1)[-1] in ("png", "jpg", "gif", "jpeg"):
                filename = os.path.join(filename, "image.%s" % (filename.rsplit(".", 1)[-1]))
            else:
                filename = os.path.join(filename, "image.jpg")
            filename, content = self._apply_image_transforms(filename, content)
        elif hasattr(obj, "getBlobWrapper") and "image" not in obj.getBlobWrapper().getContentType():
            # create path like for ATImage
            if len(filename.rsplit(".", 1)) > 1:
                filename = os.path.join(filename, "file.%s" % (filename.rsplit(".", 1)[-1]))
            else:
                filename = os.path.join(filename, "file")

        self._write(filename, content)

        # deploy all sizes of images uploaded for the object
        if not getattr(obj, "schema", None):
            return

        for field in obj.Schema().fields():
            if (PLONE_APP_BLOB_INSTALLED and IBlobImageField.providedBy(field)) or field.type == "image":
                self._deploy_blob_image_field(obj, field)
            elif PLONE_APP_BLOB_INSTALLED and IBlobField.providedBy(field):
                self._deploy_blob_file_field(obj, field)
            elif field.type == "file" and obj.meta_type not in self.file_types:
                self._deploy_file_field(obj, field)
            else:
                continue
        if new_req is not None:
            restoreRequest(orig_req, new_req)
    def image_fields(self):
        """ read interface
        """
        fields = []

        for field in self.context.Schema().fields():
            if IBlobImageField.providedBy(field) or IImageField.providedBy(field) and field.get_size(self.context) > 0:
                fields.append(field)

        return fields
Beispiel #3
0
    def image_fields(self):
        """ read interface
        """
        fields = []

        for field in self.context.Schema().fields():
            if (IBlobImageField.providedBy(field)
                    or IImageField.providedBy(field)
                    and field.get_size(self.context) > 0):
                fields.append(field)

        return fields
    def publishTraverse(self, request, name):
        # remove scales information, if image has changed
        # We have no way of knowing if a non-blob image has changed, since we
        # don't have a time marker for when crops were generated.
        has_blobs = False
        for field in self.context.Schema().fields():
            if IBlobImageField.providedBy(field):
                has_blobs = True
                break

        if has_blobs and not hasattr(aq_base(self.context), blobScalesAttr) \
           and PAI_STORAGE_KEY in IAnnotations(self.context):
            del IAnnotations(self.context)[PAI_STORAGE_KEY]
        return super(ImageTraverser, self).publishTraverse(request, name)
Beispiel #5
0
    def publishTraverse(self, request, name):
        # remove scales information, if image has changed
        # We have no way of knowing if a non-blob image has changed, since we
        # don't have a time marker for when crops were generated.
        has_blobs = False
        for field in self.context.Schema().fields():
            if IBlobImageField.providedBy(field):
                has_blobs = True
                break

        if has_blobs and not hasattr(aq_base(self.context), blobScalesAttr) \
           and PAI_STORAGE_KEY in IAnnotations(self.context):
            del IAnnotations(self.context)[PAI_STORAGE_KEY]
        return super(ImageTraverser, self).publishTraverse(request, name)
    def _deploy_content(self, obj, is_page=True):
        """
        Deploy object as page.
        """
        content = self._render_obj(obj)
        if content is None:
            return

        filename = obj.absolute_url_path().lstrip('/')
        # deploy additional views for content type
        if PLONE_APP_BLOB_INSTALLED and isinstance(obj, ATBlob):
            self._deploy_views([os.path.join(filename, 'view'), ],
                    is_page=True)

        if is_page:
            filename = os.path.join(filename, 'index.html')
        elif isinstance(obj, ATImage) or hasattr(obj, 'getBlobWrapper') and 'image' in obj.getBlobWrapper().getContentType():
            # create path to dump ATImage in original size
            if filename.rsplit('.', 1)[-1] in ('png', 'jpg', 'gif', 'jpeg'):
                filename = os.path.join(filename, 'image.%s' % filename.rsplit('.', 1)[-1])
            else:
                filename = os.path.join(filename, 'image.jpg')
            filename, content = self._apply_image_transforms(filename, content)
        elif (hasattr(obj, 'getBlobWrapper') and 'image' not in
                obj.getBlobWrapper().getContentType()):
            # create path like for ATImage
            if len(filename.rsplit('.', 1)) > 1:
                filename  = os.path.join(filename, 'file.%s' % filename.rsplit('.', 1)[-1])
            else:
                filename = os.path.join(filename, 'file')

        self._write(filename, content)

        # deploy all sizes of images uploaded for the object
        if not getattr(obj, 'schema', None):
            return

        for field in obj.Schema().fields():
            if PLONE_APP_BLOB_INSTALLED and IBlobImageField.providedBy(field):
                self._deploy_blob_image_field(obj, field)
            elif PLONE_APP_BLOB_INSTALLED and IBlobField.providedBy(field):
                self._deploy_blob_file_field(obj, field)
            elif field.type == 'image':
                self._deploy_image_field(obj, field)
            elif field.type == 'file' and obj.meta_type not in self.file_types:
                self._deploy_file_field(obj, field)
            else:
                continue
    def _deploy_content(self, obj, is_page=True):
        """
        Deploy object as page.
        """
        try:
            new_req, orig_req = fakeRequest(obj)
        except AttributeError:
            # not a valid obj to override request with
            new_req = None
        content = self._render_obj(obj)
        if content is None:
            return

        filename = obj.absolute_url_path().lstrip('/')
        # deploy additional views for content type
        if PLONE_APP_BLOB_INSTALLED and isinstance(obj, ATBlob):
            self._deploy_views([os.path.join(filename, 'view'), ],
                    is_page=True)

        if is_page:
            filename = filename.rstrip('/')
            if self.add_index or IFolder.providedBy(obj):
                filename = os.path.join(filename, 'index.html')
            elif not filename.endswith('.htm') and not filename.endswith('.html'):
                filename = filename + '.html'
        elif isinstance(obj, ATImage) or \
                hasattr(obj, 'getBlobWrapper') and \
                'image' in obj.getBlobWrapper().getContentType():
            # create path to dump ATImage in original size
            if filename.rsplit('.', 1)[-1] in ('png', 'jpg', 'gif', 'jpeg'):
                filename = os.path.join(filename, 'image.%s' % (
                    filename.rsplit('.', 1)[-1]))
            else:
                filename = os.path.join(filename, 'image.jpg')
            filename, content = self._apply_image_transforms(filename, content)
        elif (hasattr(obj, 'getBlobWrapper') and 'image' not in
                obj.getBlobWrapper().getContentType()):
            # create path like for ATImage
            if len(filename.rsplit('.', 1)) > 1:
                filename = os.path.join(filename, 'file.%s' % (
                    filename.rsplit('.', 1)[-1]))
            else:
                filename = os.path.join(filename, 'file')

        self._write(filename, content)

        # deploy all sizes of images uploaded for the object
        if not getattr(obj, 'schema', None):
            return

        # For Dexterity objects
        if IDexterityContent.providedBy(obj):
            from plone.dexterity.interfaces import IDexterityFTI
            from zope.component import getUtility
            from zope.schema import getFieldsInOrder
            from plone.behavior.interfaces import IBehaviorAssignable

            fti = getUtility(IDexterityFTI, name=obj.portal_type)
            schema = fti.lookupSchema()
            fields = getFieldsInOrder(schema)
            for _, field in fields:
                if INamedImageField.providedBy(field):
                    self._deploy_blob_dexterity_image_field(obj, field)
                elif INamedFileField.providedBy(field):
                    self._deploy_blob_dexterity_file_field(obj, field)

            behavior_assignable = IBehaviorAssignable(obj)
            if behavior_assignable:
                behaviors = behavior_assignable.enumerateBehaviors()
                for behavior in behaviors:
                    for k, v in getFieldsInOrder(behavior.interface):
                        pass

        else:
            for field in obj.Schema().fields():
                if (PLONE_APP_BLOB_INSTALLED and IBlobImageField.providedBy(field)) or \
                        field.type == 'image':
                    self._deploy_blob_image_field(obj, field)
                elif PLONE_APP_BLOB_INSTALLED and IBlobField.providedBy(field):
                    self._deploy_blob_file_field(obj, field)
                elif field.type == 'file' and obj.portal_type not in self.file_types:
                    self._deploy_file_field(obj, field)
                else:
                    continue
        if new_req is not None:
            restoreRequest(orig_req, new_req)