本文整理汇总了Python中plone.scale.storage.AnnotationStorage.get方法的典型用法代码示例。如果您正苦于以下问题:Python AnnotationStorage.get方法的具体用法?Python AnnotationStorage.get怎么用?Python AnnotationStorage.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.scale.storage.AnnotationStorage
的用法示例。
在下文中一共展示了AnnotationStorage.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publishTraverse
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import get [as 别名]
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)
示例2: publishTraverse
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import get [as 别名]
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)
示例3: _deploy_resources
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import get [as 别名]
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:
#.........这里部分代码省略.........
示例4: save_images
# 需要导入模块: from plone.scale.storage import AnnotationStorage [as 别名]
# 或者: from plone.scale.storage.AnnotationStorage import get [as 别名]
def save_images(self, context):
"""Save images from ZODB to temp directory
"""
portal = getSite()
portal_url = portal.absolute_url()
if not portal_url.endswith('/'):
portal_url += '/'
portal_path = '/'.join(portal.getPhysicalPath())
reference_tool = getToolByName(portal, 'reference_catalog')
mtool = getToolByName(portal, 'portal_membership')
for filename, image in self.images:
size = None
# Traverse methods mess with unicode
if type(image) is unicode:
image = str(image)
path = image.replace(portal_url, '')
item = None
# using uid
if 'resolveuid' in image:
# uid is the traversed value coming after "resolveuid/"
resolveuidpath = image.split('/')
resolveuid_idx = resolveuidpath.index('resolveuid')
try:
uuid = resolveuidpath[resolveuid_idx + 1]
except IndexError:
logger.error("Failed to get image uid from %s", image)
continue
item = reference_tool.lookupObject(uuid)
if len(resolveuidpath) >= resolveuid_idx + 2:
size = resolveuidpath[resolveuid_idx + 2]
logger.debug("Get image from uid %s", uuid)
if not item:
# relative url
try:
item = context.restrictedTraverse(image)
logger.debug("Get image from context")
except Unauthorized:
logger.warning("Unauthorized to get image from context path %s", item)
except:
logger.debug("Failed to get image from context path %s",
image)
if not item:
# plone.app.imaging
if '@@images' in path and AnnotationStorage:
context_path, images_str, uid_filename = path.rsplit('/', 2)
image_context = portal.restrictedTraverse(context_path)
uid, ext = uid_filename.rsplit('.', 1)
storage = AnnotationStorage(image_context)
info = storage.get(uid)
if info is not None:
request = TestRequest()
scale_view = ImageScale(image_context, request, **info)
item = scale_view.__of__(image_context)
if not item:
# absolute url
image_path = '/'.join((portal_path, path))
try:
item = portal.restrictedTraverse(image_path)
logger.debug("Get image from portal")
except Unauthorized:
logger.warning("Unauthorized to get from context path %s", image_path)
except:
logger.error("Failed to get image from portal path %s",
image_path)
continue
if not mtool.checkPermission('View', item):
logger.warning("Unauthorized to get image %s", item)
continue
if item and size:
try:
item = item.restrictedTraverse(size)
except Unauthorized:
logger.warning("Unauthorized to get size %s from image %s",
size, image)
except:
logger.error("Failed to get size %s from image %s",
size, image)
pass
# Eek, we should put an adapter for various image providers (overkill ?).
data = get_image_data(item)
if data:
_write_file(data, self.fsinfo, filename)
return