当前位置: 首页>>代码示例>>Python>>正文


Python storage.AnnotationStorage类代码示例

本文整理汇总了Python中plone.scale.storage.AnnotationStorage的典型用法代码示例。如果您正苦于以下问题:Python AnnotationStorage类的具体用法?Python AnnotationStorage怎么用?Python AnnotationStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AnnotationStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: publishTraverse

 def publishTraverse(self, request, name):
     """ used for traversal via publisher, i.e. when using as a url """
     stack = request.get('TraversalRequestNameStack')
     image = None
     if stack and stack[-1] not in self._ignored_stacks:
         # field and scale name were given...
         scale = stack.pop()
         image = self.scale(name, scale)             # this is aq-wrapped
     elif '-' in name:
         # we got a uid...
         if '.' in name:
             name, ext = name.rsplit('.', 1)
         storage = AnnotationStorage(self.context)
         info = storage.get(name)
         if info is not None:
             scale_view = ImageScale(self.context, self.request, **info)
             alsoProvides(scale_view, IStableImageScale)
             return scale_view.__of__(self.context)
     else:
         # otherwise `name` must refer to a field...
         if '.' in name:
             name, ext = name.rsplit('.', 1)
         value = getattr(self.context, name)
         scale_view = ImageScale(
             self.context, self.request, data=value, fieldname=name)
         return scale_view.__of__(self.context)
     if image is not None:
         return image
     raise NotFound(self, name, self.request)
开发者ID:espenmn,项目名称:collective.lazysizes,代码行数:29,代码来源:scaling.py

示例2: storage

    def storage(self):
        from plone.scale.storage import AnnotationStorage

        storage = AnnotationStorage(None)
        storage.modified = lambda: 42
        storage.storage = {}
        return storage
开发者ID:ksuess,项目名称:plone.scale,代码行数:7,代码来源:test_storage.py

示例3: save_cropped

    def save_cropped(self, fieldname, scale, image_file):
        """ see interface
        """
        field = self.get_image_field(fieldname)
        handler = IImageScaleHandler(field)
        sizes = field.getAvailableSizes(self.context)
        w, h = sizes[scale]
        data = handler.createScale(self.context, scale, w, h, data=image_file.read())

        # store scale for classic <fieldname>_<scale> traversing
        handler.storeScale(self.context, scale, **data)

        # call plone.scale.storage.scale method in order to
        # provide saved scale for plone.app.imaging @@images view
        def crop_factory(fieldname, direction="keep", **parameters):
            blob = Blob()
            result = blob.open("w")
            _, image_format, dimensions = scaleImage(data["data"], result=result, **parameters)
            result.close()
            return blob, image_format, dimensions

        # Avoid browser cache
        # calling reindexObject updates the modified metadate too
        self.context.reindexObject()

        # call storage with actual time in milliseconds
        # this always invalidates old scales
        storage = AnnotationStorage(self.context, _millis)
        storage.scale(factory=crop_factory, fieldname=field.__name__, width=w, height=h)
开发者ID:nagyistoce,项目名称:plone.app.imagecropping,代码行数:29,代码来源:at.py

示例4: scale

    def scale(self,
              fieldname=None,
              scale=None,
              height=None,
              width=None,
              direction='thumbnail',
              **parameters):
        if fieldname is None:
            fieldname = IPrimaryFieldInfo(self.context).fieldname
        if scale is not None:
            available = self.getAvailableSizes(fieldname)
            if scale not in available:
                return None
            width, height = available[scale]

        if IDisableCSRFProtection and self.request is not None:
            alsoProvides(self.request, IDisableCSRFProtection)

        storage = AnnotationStorage(self.context, self.modified)
        info = storage.scale(factory=self.create,
                             fieldname=fieldname,
                             height=height,
                             width=width,
                             direction=direction,
                             **parameters)

        if info is not None:
            info['fieldname'] = fieldname
            scale_view = ImageScale(self.context, self.request, **info)
            return scale_view.__of__(self.context)
开发者ID:espenmn,项目名称:collective.lazysizes,代码行数:30,代码来源:scaling.py

示例5: save_cropped

    def save_cropped(
            self, fieldname, field, scale, image_file, interface=None):
        """ see interface
        """
        handler = IImageScaleHandler(field)
        sizes = field.getAvailableSizes(self.context)
        w, h = sizes[scale]
        data = handler.createScale(
            self.context, scale, w, h, data=image_file.read())

        # store scale for classic <fieldname>_<scale> traversing
        handler.storeScale(self.context, scale, **data)

        # call plone.scale.storage.scale method in order to
        # provide saved scale for plone.app.imaging @@images view
        def crop_factory(fieldname, direction='keep', **parameters):
            blob = Blob()
            result = blob.open('w')
            _, image_format, dimensions = scaleImage(
                data['data'], result=result, **parameters)
            result.close()
            return blob, image_format, dimensions

        # call storage with actual time in milliseconds
        # this always invalidates old scales
        storage = AnnotationStorage(self.context, self.now_millis)
        storage.scale(
            factory=crop_factory, fieldname=field.__name__, width=w, height=h)
开发者ID:hersonrodrigues,项目名称:plone.app.imagecropping,代码行数:28,代码来源:utils.py

示例6: _crop

    def _crop(self, fieldname, scale, box, interface=None):
        """interface just useful to locate field on dexterity types
        """
        # https://github.com/plone/plone.app.imaging/blob/ggozad-cropping/src/
        # plone/app/imaging/cropping.py

        field = self.context.getField(fieldname)
        if hasattr(field,'getHandler'):
            handler = field.getHandler()
        else:
            handler = IImageScaleHandler(field)

        # TODO this is archetype only
        value = field.get(self.context)
        data = getattr(aq_base(value), 'data', value)
        if isinstance(data, Pdata):
            data = str(data)

        original_file = StringIO(data)
        image = PIL.Image.open(original_file)
        image_format = image.format or self.DEFAULT_FORMAT

        cropped_image = image.crop(box)
        cropped_image_file = StringIO()
        cropped_image.save(cropped_image_file, image_format, quality=100)
        cropped_image_file.seek(0)

        sizes = field.getAvailableSizes(self.context)
        #regular scale
        if len(sizes[scale]) ==3:
            w, h, s = sizes[scale]
            data = handler.createScale(self.context, scale, w, h, data=cropped_image_file.read())
        else:
            w, h = sizes[scale]
            data = handler.createScale(self.context, scale, w, h,
                                    data=cropped_image_file.read())

        # store scale for classic <fieldname>_<scale> traversing
        handler.storeScale(self.context, scale, **data)

        # call plone.scale.storage.scale method in order to
        # provide saved scale for plone.app.imaging @@images view
        def crop_factory(fieldname, direction='keep', **parameters):
            blob = Blob()
            result = blob.open('w')
            _, image_format, dimensions = scaleImage(data['data'],
                result=result, **parameters)
            result.close()
            return blob, image_format, dimensions

        # call storage with actual time in milliseconds
        # this always invalidates old scales
        storage = AnnotationStorage(self.context,
            self.now_millis)
        storage.scale(factory=crop_factory, fieldname=fieldname,
            width=w, height=h)

        # store crop information in annotations
        self._store(fieldname, scale, box)
开发者ID:Goldmund-Wyldebeast-Wunderliebe,项目名称:plone.app.imagecropping,代码行数:59,代码来源:crop.py

示例7: getInfo

 def getInfo(self, fieldname=None, scale=None, height=None, width=None,
             **parameters):
     storage = AnnotationStorage(self.context, self.modified)
     return storage.scale(
         factory=self.create,
         fieldname=fieldname,
         height=height,
         width=width,
         **parameters)
开发者ID:plone,项目名称:plone.app.imaging,代码行数:9,代码来源:scaling.py

示例8: _invalidate_scale

 def _invalidate_scale(self, fieldname, scale):
     # Call storage with actual time in milliseconds.
     # This always invalidates old scales
     scale_storage = AnnotationStorage(
         self.context,
         int(time.time())
     )
     # holzhammermethode
     uids = list(scale_storage.keys())
     for uid in uids:
         del scale_storage[uid]
开发者ID:collective,项目名称:plone.app.imagecropping,代码行数:11,代码来源:storage.py

示例9: scale

 def scale(self, fieldname=None, scale=None, height=None, width=None, **parameters):
     if scale is not None:
         available = self.getAvailableSizes(fieldname)
         if not scale in available:
             return None
         width, height = available[scale]
     if width is None and height is None:
         field = self.field(fieldname)
         return field.get(self.context)
     storage = AnnotationStorage(self.context, self.modified)
     info = storage.scale(factory=self.create,
         fieldname=fieldname, height=height, width=width, **parameters)
     if info is not None:
         return self.make(info).__of__(self.context)
开发者ID:witsch,项目名称:plone.app.imaging,代码行数:14,代码来源:scaling.py

示例10: scale

 def scale(self, fieldname=None, scale=None, height=None, width=None, **parameters):
     if fieldname is None:
         fieldname = IPrimaryFieldInfo(self.context).fieldname
     if scale is not None:
         available = self.getAvailableSizes(fieldname)
         if not scale in available:
             return None
         width, height = available[scale]
     storage = AnnotationStorage(self.context, self.modified)
     info = storage.scale(factory=self.create,
         fieldname=fieldname, height=height, width=width, **parameters)
     if info is not None:
         info['fieldname'] = fieldname
         scale_view = ImageScale(self.context, self.request, **info)
         return scale_view.__of__(self.context)
开发者ID:naro,项目名称:plone.namedfile,代码行数:15,代码来源:scaling.py

示例11: populate_with_object

    def populate_with_object(self, obj):
        # check permissions
        super(ImageTile, self).populate_with_object(obj)

        data = {}
        obj = aq_inner(obj)
        try:
            scales = queryMultiAdapter((obj, self.request), name="images")
            data['image'] = NamedImageFile(str(scales.scale('image').data))
        except AttributeError:
            pass
        data_mgr = ITileDataManager(self)
        data_mgr.set(data)
        tile_storage = AnnotationStorage(self)
        obj_storage = BaseAnnotationStorage(obj)
        for k, v in obj_storage.items():
            tile_storage.storage[k] = v
            tile_storage.storage[k]['modified'] = '%f' % time.time()
            scale_data = obj_storage.storage[k]['data'].open().read()
            tile_storage.storage[k]['data'] = NamedImageFile(str(scale_data))
开发者ID:agnogueira,项目名称:collective.cover,代码行数:20,代码来源:image.py

示例12: publishTraverse

 def publishTraverse(self, request, name):
     """ used for traversal via publisher, i.e. when using as a url """
     stack = request.get('TraversalRequestNameStack')
     if stack:
         # field and scale name were given...
         scale = stack.pop()
         image = self.scale(name, scale)             # this is aq-wrapped
     elif '.' in name:
         # we got a uid...
         uid, ext = name.rsplit('.', 1)
         storage = AnnotationStorage(self.context)
         info = storage.get(uid)
         image = None
         if info is not None:
             image = self.make(info).__of__(self.context)
     else:
         # otherwise `name` must refer to a field...
         field = self.field(name)
         image = field.get(self.context)             # this is aq-wrapped
     if image is not None:
         return image
     raise NotFound(self, name, self.request)
开发者ID:witsch,项目名称:plone.app.imaging,代码行数:22,代码来源:scaling.py

示例13: __call__

    def __call__(self):
        form = self.request.form
        size = form.get('size', form.get('s', None))
        if size is None:
            # return original - no scaling required
            return self.context.index_html(self.request, self.request.RESPONSE)
        else:
            size = int(size)

        if not IAttributeAnnotatable.providedBy(self.context):
            alsoProvides(self.context, IAttributeAnnotatable)

        storage = AnnotationStorage(self.context)
        scale = storage.scale(self.scale_factory,
                              width=size,
                              height=size)

        response = self.request.RESPONSE
        response.setHeader('Last-Modified', rfc1123_date(scale['modified']))
        response.setHeader('Content-Type', scale['mimetype'])
        response.setHeader('Content-Length', len(scale['data']))
        response.setHeader('Accept-Ranges', 'bytes')
        return scale['data']
开发者ID:4teamwork,项目名称:ftw.avatar,代码行数:23,代码来源:portrait.py

示例14: _deploy_resources

    def _deploy_resources(self, urls, base_path):
        """
        Deploy resources linked in HTML or CSS.
        """
        portal_url = getToolByName(self.context, "portal_url")()
        for url in urls:
            url = url.strip()
            scheme, netloc, path, query, fragment = urlsplit(url)
            if not path:
                ## internal anchor
                continue

            if netloc and netloc != portal_url:
                ## external link
                continue
            elif path.startswith("image/svg+xml;base64") or path.startswith("image/png;base64"):
                ## images defined in css
                continue
            if path.startswith("/"):
                objpath = path[1:]
            else:
                objpath = os.path.join(base_path, path)

            if isinstance(objpath, unicode):
                objpath = objpath.encode("utf-8")

            # PloneSite with id 'plone' case problems during
            # restrictedTraverse() so we cut it
            objpath_spl = objpath.split("/", 1)
            if objpath_spl[0] == "plone" and len(objpath_spl) > 1:
                objpath = objpath_spl[1]
            # fix "../" in paths
            objpath = os.path.normpath(objpath).replace("%20", " ")

            if objpath in self.deployed_resources:
                continue
            obj = self.context.unrestrictedTraverse(objpath, None)
            if objpath.rsplit("/", 1)[-1].split(".")[0] == "image":
                obj = self.context.restrictedTraverse(objpath.rsplit(".", 1)[0], None)
            if not obj:
                obj = self.context.restrictedTraverse(unquote(objpath), None)
            if not obj:
                parent_obj = self.context.restrictedTraverse(unquote(objpath.rsplit("/", 1)[0]), None)
                if parent_obj:
                    image_name = objpath.rsplit("/", 1)[-1]
                    if hasattr(parent_obj, "schema"):
                        for field in parent_obj.schema.fields():
                            fieldname = field.getName()
                            if image_name.startswith(fieldname):
                                scalename = image_name[len(fieldname) + 1 :]
                                obj = field.getScale(parent_obj, scalename)
                                objpath = os.path.join(objpath, "image.jpg")
                                break
                        else:
                            # didn't find it, just go for field name now...
                            # could be added with archetypes.schemaextender
                            parts = image_name.split("_")
                            fieldname = parts[0]
                            field = parent_obj.getField(fieldname)
                            if field and len(parts) == 2:
                                scalename = parts[1]
                                obj = field.getScale(parent_obj, scalename)
                                objpath = os.path.join(objpath, "image.jpg")

            add_path = True
            if not obj:
                if "/@@images/" in objpath:
                    parent_path, image_name = objpath.split("/@@images/")
                    parent_obj = self.context.unrestrictedTraverse(unquote(parent_path), None)
                    if parent_obj:
                        spl_img_name = image_name.split("/")
                        if len(spl_img_name) == 1:
                            # no scalename in path
                            fieldname = spl_img_name[0]
                            scalename = None
                            objpath = "/".join((parent_path, "image.jpg"))
                        else:
                            fieldname, scalename = spl_img_name
                            objpath = os.path.join(parent_path, "_".join((fieldname, scalename)), "image.jpg")
                        try:
                            images_view = getMultiAdapter((parent_obj, self.request), name="images")
                            field = images_view.field(fieldname)
                            if field:
                                obj = field.getScale(parent_obj, scalename)
                            else:
                                # need to try and get it from the uid
                                uid, ext = fieldname.rsplit(".", 1)
                                from plone.scale.storage import AnnotationStorage

                                storage = AnnotationStorage(parent_obj)
                                info = storage.get(uid)
                                if info is not None:
                                    obj = images_view.make(info).__of__(parent_obj)
                                    # using the exported scale now instead
                                    objpath = "/".join((parent_path, fieldname))
                                    add_path = False
                        except ComponentLookupError:
                            pass

            if not obj:
#.........这里部分代码省略.........
开发者ID:vangheem,项目名称:stxnext.staticdeployment,代码行数:101,代码来源:util.py

示例15: print


for site in plones:
    print('')
    print('Handling Plone Site %s.' % site.id)
    setSite(site)
    catalog = getToolByName(site, 'portal_catalog')
    count = 0
    purged = 0
    for brain in catalog():
        try:
            obj = brain.getObject()
        except:
            continue
        savepoint = transaction.savepoint()
        ann = AnnotationStorage(obj)
        try:
            ann.storage
        except TypeError:
            # This happens when the context cannot be annotated, for
            # example for a plone.app.discussion comment.
            continue
        # We want to remove all scales that are X days older than the
        # last modification date of the object.
        final_date = obj.modified() - DAYS
        changed = False
        for key, value in ann.items():
            if value['modified'] < final_date.millis():
                # This may easily give an error, as it tries to remove
                # two keys: del ann[key]
                del ann.storage[key]
开发者ID:ida,项目名称:skriptz,代码行数:29,代码来源:purge_image_scales.py


注:本文中的plone.scale.storage.AnnotationStorage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。