Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling overrides #38

Merged
merged 38 commits into from
May 30, 2014
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f8241a8
Avoid browser cache (Return code 304 Not Modified)
rristow Feb 18, 2014
15d680e
simplified code a little bit
tomgross Feb 19, 2014
f7a0237
factored out cropping for better testability
tomgross Feb 19, 2014
49ee305
use Plone 4.3 for default buildout
tomgross Feb 20, 2014
24c8e3a
started test for crop-view
tomgross Feb 20, 2014
ab47688
override scaling view to keep crops on metadata change
tomgross Feb 26, 2014
362674f
implement scaling for plone.namedfile
tomgross Mar 5, 2014
ea7dc0b
Remove commented out version pins
tomgross Mar 10, 2014
300a3c6
fixed case where cropping annotation is none
tomgross Mar 11, 2014
1cbe543
we depend on plone.namedfile >= 2.0.1
tomgross Mar 11, 2014
f36fcaa
document changes
tomgross Mar 11, 2014
204339d
adjust schema of test content so tests pass on 4.2 and 4.3
tomgross Mar 12, 2014
1588cd7
use latest seleium
tomgross Mar 12, 2014
791f64a
specify version pinned egg plone.namedfile as test dependency
tomgross Mar 12, 2014
f44cce0
added test for plone 5.0
tomgross Mar 13, 2014
c6f57c1
buildout and egg hygiene
tomgross Mar 14, 2014
f4895fa
remove buildout config which is a duplicate of buildout.cfg
tomgross Mar 14, 2014
81bf404
don't depend on plone.namedfile >= 2.0.1
tomgross Mar 14, 2014
64054d9
fix test buildouts
tomgross Mar 14, 2014
7b134d4
reduce travis test variants
tomgross Mar 14, 2014
4fc6094
fixed typo
tomgross Mar 14, 2014
79b45a2
reverted over optimization
tomgross Mar 14, 2014
02f521c
added z3c.blobfile to eggs to activate plone.supermodel handler
tomgross Mar 14, 2014
6120df2
use bugfix version of plone.app.z3cform
tomgross Mar 14, 2014
75ee18b
remove plone.namedfile switch. we depend on plone.namedfile >= 2.0.1
tomgross Mar 15, 2014
5d79d9b
document changes
tomgross Mar 15, 2014
4868874
register customized scale view for all archetypes
frisi Apr 4, 2014
a25b15d
test scales stored in attributestorage too, and add test for invalida…
frisi Apr 4, 2014
bf34b7d
remove scales information, if image changes
tomgross May 15, 2014
68500f8
Merge remote-tracking branch 'collective/master'
tomgross May 15, 2014
d60b1e2
fix situation, where no crop information is available
tomgross May 16, 2014
bc1001c
remove todo
frisi May 19, 2014
4bc52fc
do not select first scale automatically - to prevent javascript modal…
frisi May 19, 2014
e2b510d
our test type needs this interface so NamedfileImageScaling is looked…
frisi May 19, 2014
172bfb4
removed unneeded interface
tomgross May 30, 2014
729c0c5
fix indentation
frisi May 30, 2014
9e0d4b0
add documenation and try to use meaningful names
frisi May 30, 2014
110cead
remove redundant changelog
frisi May 30, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ python: 2.7
env:
- PLONE_VERSION=4.2
- PLONE_VERSION=4.3
matrix:
include:
- python: 2.6
env: PLONE_VERSION=4.1
allow_failures:
- python: 2.6
env: PLONE_VERSION=4.1
before_install:
- sudo apt-get install -y libjpeg-dev libgif-dev libpng-dev libz-dev
install:
- sed -ie "s#travis-4.x.cfg#travis-$PLONE_VERSION.x.cfg#" travis.cfg
- mkdir -p buildout-cache/downloads
- python bootstrap.py -c travis.cfg
- bin/buildout -c travis.cfg annotate
- bin/buildout -c travis.cfg -N -q
- mkdir -p buildout-cache/eggs
install:
- python bootstrap.py -c test-$PLONE_VERSION.cfg
- bin/buildout -t 10 -Nc test-$PLONE_VERSION.cfg
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
Expand Down
10 changes: 8 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Changelog
0.1rc3 (unreleased)
-------------------

- Check for plone.namedfile not Dexterity. It can be used seperately
[tom_gross]
- Check for plone.namedfile not Dexterity. It can be used seperately.
*If plone.namedfile is used it needs to be at least version 2.0.1*
[tomgross]

- Rename ``imagecropping_keywords.txt`` to ``keywords.robot`` to allow simple
reusage in ``plone.app.robotframework``.
Expand All @@ -20,6 +21,11 @@ Changelog
- Prevent fieldname loosing for for current field
[bogdangi]

- Fixed #21 (cropping was reset on modifying image)
[tomgross]

- Only test Plone 4.2 and 4.3 with Python 2.7 on Travis-CI
[tomgross]

0.1rc2 (2013-05-03)
-------------------
Expand Down
11 changes: 6 additions & 5 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[buildout]
extends =
https://raw.github.com/collective/buildout.plonetest/master/test-4.2.x.cfg
https://raw.github.com/collective/buildout.plonetest/master/test-4.3.x.cfg

package-name = plone.app.imagecropping
package-extras = [test]

#index = http://c.pypi.python.org

parts +=
omelette
i18ndude
Expand All @@ -26,6 +24,11 @@ test-eggs +=

versions = versions

[versions]
Pillow = 2.3.0
selenium = 2.40.0
plone.app.contenttypes = 1.0

[omelette]
recipe = collective.recipe.omelette
eggs = ${instance:eggs} ${buildout:test-eggs}
Expand Down Expand Up @@ -53,5 +56,3 @@ input = inline:
cd -
mode = 755

[versions]
plone.app.collection = 2.0b5
60 changes: 0 additions & 60 deletions instance-4.3.cfg

This file was deleted.

7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from setuptools import setup, find_packages
import os
import pkg_resources
from distutils.version import LooseVersion

version = '0.1rc3.dev0'
version = '1.0.dev0'

long_description = (
open('README.rst').read()
Expand All @@ -23,15 +25,13 @@
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: 4.1",
"Framework :: Plone :: 4.2",
"Framework :: Plone :: 4.3",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: OS Independent",
"Programming Language :: JavaScript",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Software Development :: Libraries :: Python Modules",
],
Expand All @@ -56,6 +56,7 @@
'test': [
'plone.app.testing[robot]>=4.2.2',
'plone.app.dexterity',
'plone.namedfile>=2.0.1',
],
},
entry_points="""
Expand Down
3 changes: 0 additions & 3 deletions src/plone/app/imagecropping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@
imagecroppingMessageFactory = MessageFactory("plone.app.imagecropping")
PRODUCT_NAME = PAI_STORAGE_KEY = "plone.app.imagecropping"


def initialize(context):
"""Initializer called when used as a Zope 2 product."""
25 changes: 25 additions & 0 deletions src/plone/app/imagecropping/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone">

<include package="Products.CMFCore" file="permissions.zcml" />
Expand Down Expand Up @@ -43,4 +44,28 @@
permission="cmf.ModifyPortalContent"
/>

<browser:page
zcml:condition="installed Products.ATContentTypes"
for="Products.ATContentTypes.interfaces.IATImage"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limiting this override to ATImage and ATNewsItem requires people having custom archetypes based content types to add this page registration for their type, too.

from a usability point of view it should be sufficient to mark your type with plone.app.imagecropping.interfaces.IImageCropping to get cropping support for all image fields.

i'd suggest to register it for Archetypes BaseObject:

 <browser:page
      zcml:condition="installed Products.Archetypes"
      for="Products.Archetypes.BaseObject.BaseObject"
      name="images"
      class=".scaling.ImageScaling"
      allowed_interface="plone.app.imaging.interfaces.IImageScaling"
      permission="zope2.View" />

name="images"
class=".scaling.ImageScaling"
allowed_interface="plone.app.imaging.interfaces.IImageScaling"
permission="zope2.View" />

<browser:page
zcml:condition="installed Products.ATContentTypes"
for="Products.ATContentTypes.interfaces.IATNewsItem"
name="images"
class=".scaling.ImageScaling"
allowed_interface="plone.app.imaging.interfaces.IImageScaling"
permission="zope2.View" />

<browser:page
zcml:condition="installed plone.namedfile"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see the need of having this, as I mentioned before plone.namedfile is always installed on Plone.

for=".scaling.IImageCroppingScale"
name="images"
class=".scaling.NamedfileImageScaling"
allowed_interface="plone.app.imaging.interfaces.IImageScaling"
permission="zope2.View" />

</configure>
3 changes: 1 addition & 2 deletions src/plone/app/imagecropping/browser/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def _crop(self, fieldname, scale, box, interface=None):
"""switch between dexterity and Archetypes
"""
croputils = IImageCroppingUtils(self.context)
field = croputils.get_image_field(fieldname)
data = croputils.get_image_data(fieldname)

original_file = StringIO(data)
Expand All @@ -38,7 +37,7 @@ def _crop(self, fieldname, scale, box, interface=None):
cropped_image_file.seek(0)

croputils.save_cropped(
fieldname, field, scale, cropped_image_file, interface)
fieldname, scale, cropped_image_file, interface)

# store crop information in annotations
self._store(fieldname, scale, box)
Expand Down
30 changes: 16 additions & 14 deletions src/plone/app/imagecropping/browser/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from zope.component._api import getUtility
import json


JS_MESSAGES = """\
if(typeof(imagecropping) != "undefined") {
imagecropping.i18n_message_ids = {
Expand Down Expand Up @@ -143,24 +142,27 @@ def image_url(self, fieldname="image"):
height=int(self.default_editor_size[1]))
return scaled_img and scaled_img.url or ''

def __call__(self):
form = self.request.form
def _crop(self):
coordinate = lambda x: int(round(float(self.request.form.get(x))))
x1 = coordinate('x1')
y1 = coordinate('y1')
x2 = coordinate('x2')
y2 = coordinate('y2')
scale_name = self.request.form.get('scalename')
cropping_util = self.context.restrictedTraverse('@@crop-image')
cropping_util._crop(fieldname=self.fieldname,
scale=scale_name,
box=(x1, y1, x2, y2),
interface=self.interface)

def __call__(self):
form = self.request.form
if form.get('form.button.Delete', None) is not None:
cropping_util._remove(self.fieldname,
self.request.form.get('scalename'))
cropping_util = self.context.restrictedTraverse('@@crop-image')
cropping_util._remove(self.fieldname, form.get('scalename'))
IStatusMessage(self.request).add(_(u"Cropping area deleted"))
if form.get('form.button.Save', None) is not None:
x1 = int(round(float(self.request.form.get('x1'))))
y1 = int(round(float(self.request.form.get('y1'))))
x2 = int(round(float(self.request.form.get('x2'))))
y2 = int(round(float(self.request.form.get('y2'))))
scale_name = self.request.form.get('scalename')
cropping_util._crop(fieldname=self.fieldname,
scale=scale_name,
box=(x1, y1, x2, y2),
interface=self.interface)
self._crop()
IStatusMessage(self.request).add(
_(u"Successfully saved cropped area"))

Expand Down
72 changes: 72 additions & 0 deletions src/plone/app/imagecropping/browser/scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from zope.annotation.interfaces import IAnnotations

from plone.app.imagecropping import PAI_STORAGE_KEY
from plone.app.imaging.scaling import ImageScaling as BaseImageScaling


class ScalingOverrides(object):

_rescale = True

def need_rescale(self, fieldname, scale):
cropped = IAnnotations(self.context).get(PAI_STORAGE_KEY)
if cropped and '%s_%s' % (fieldname, scale) in cropped:
self._rescale = False
else:
self._rescale = True


class ImageScaling(ScalingOverrides, BaseImageScaling):

def modified(self):
if self._rescale:
return super(ImageScaling, self).modified()
else:
return 1

def scale(self,
fieldname=None,
scale=None,
height=None,
width=None,
**parameters):
self.need_rescale(fieldname, scale)
return super(ImageScaling, self).scale(fieldname, scale, height, width, **parameters)

try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this try block is not needed; as per #36 we need to drop support for Plone 4.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with this try/except, plone.namedfile is always installed on Plone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://dist.plone.org/release/4.2.7/versions.cfg Plone 4.2 uses TinyMCE 1.2.x which has no specified? dependency on plone.namedfile see https://github.com/plone/Products.TinyMCE/blob/1.2.x/setup.py

I'd happly remore the try/except clause if it is not needed. I see the following variants:

  1. Make plone.namedfile a hard dependency of plone.app.imagecropping (If it is always installed in Plone this should be no problem)
  2. Keep the conditional
  3. Drop even Plone 4.2 support

The variants are in the order of my preference (1 I like most). Any other variants or opinions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're totally right; that dependency was added on release 1.3b2.

I think we must keep the conditional then but we need to document the whole stuff.

from plone.namedfile.scaling import ImageScaling as NFImageScaling

from plone.namedfile.interfaces import IImageScaleTraversable
from plone.app.imagecropping.interfaces import IImageCropping


class IImageCroppingScale(IImageScaleTraversable, IImageCropping):
pass

class NamedfileImageScaling(ScalingOverrides, NFImageScaling):
""" Override plone.namedfile scaling view

This view checks, if image crops are available and
prevents rescaling in this case.
"""

def modified(self):
if self._rescale:
return super(NamedfileImageScaling, self).modified()
else:
return 1

def scale(self,
fieldname=None,
scale=None,
height=None,
width=None,
direction='thumbnail',
**parameters):
self.need_rescale(fieldname, scale)
return super(NamedfileImageScaling, self).scale(
fieldname, scale, height, width, direction, **parameters)


except ImportError:
pass
2 changes: 1 addition & 1 deletion src/plone/app/imagecropping/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.app.imagecropping">

<five:registerPackage package="." initialize=".initialize" />
<five:registerPackage package="." />

<genericsetup:registerProfile
name="default"
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/imagecropping/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_image_size(fieldname, interface):
(100, 200)
"""

def save_cropped(fieldname, field, scale, image_file, interface=None):
def save_cropped(fieldname, scale, image_file, interface=None):
""" Save the cropped iamge under the name of the selected scale in
plone.scale.storage.AnnotationStorage, so that it is available
in plone.app.imaging @@images view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
&lt;/schema&gt;
&lt;/model&gt;</property>
<property name="model_file"></property>
<property name="schema_policy">dexterity</property>
<alias from="(Default)" to="(dynamic view)"/>
<alias from="edit" to="@@edit"/>
<alias from="sharing" to="@@sharing"/>
Expand Down
Loading