Created
February 15, 2018 12:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################ | |
# | |
# 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