Skip to content

Instantly share code, notes, and snippets.

@pigeonflight
Created February 15, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigeonflight/0afe91694051a25e00449e82538ed9fb to your computer and use it in GitHub Desktop.
Save pigeonflight/0afe91694051a25e00449e82538ed9fb to your computer and use it in GitHub Desktop.
Use this Plone commandline script to learn more about working with images in Plone
################################
#
# run this script using
# bin/instance -OPlone run {scriptname}
# assumptions:
# we assume that you have a working zope server with an instance
# of plone located at the root named "Plone"
# we also assume that you have an image named "
#
##################################################
from plone import api
import transaction
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy
from Testing.makerequest import makerequest
from Products.CMFCore.tests.base.security import PermissiveSecurityPolicy, OmnipotentUser
def spoofRequest(app):
"""
Make REQUEST variable to be available on the Zope application server.
This allows acquisition to work properly
"""
_policy=PermissiveSecurityPolicy()
_oldpolicy=setSecurityPolicy(_policy)
newSecurityManager(None, OmnipotentUser().__of__(app.acl_users))
return makerequest(app)
# Enable Faux HTTP request object so we can do "browsery" things on the cmd
app = spoofRequest(app)
request = app.REQUEST
site = app['Plone']
print site.Title()
api.portal.get()
portal = api.portal.get()
test_image = portal['new-alteroo-logo.png']
# this is an example of retrieving a browser view object
scale_util = api.content.get_view(
'images',
test_image,
request)
# details about an image are stored using
# annotation storage is an object oriented BTree style storage system
# see: https://docs.plone.org/develop/plone/persistency/storage.html#storing-as-attribute-vs-storing-in-btree
storage = AnnotationStorage(test_image,
test_image.modified)
# return a list of image properties
storage.items()
# have fun doing other debugging
# try doing a google search for the "tag" method
# this is provided by the scale_util and does some cool stuff
# tag = scale_util.tag('image', 'mini')
import ipdb;ipdb.set_trace()
transaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment