-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 26 commits
f8241a8
15d680e
f7a0237
49ee305
24c8e3a
ab47688
362674f
ea7dc0b
300a3c6
1cbe543
f36fcaa
204339d
1588cd7
791f64a
f44cce0
c6f57c1
f4895fa
81bf404
64054d9
7b134d4
4fc6094
79b45a2
02f521c
6120df2
75ee18b
5d79d9b
4868874
a25b15d
bf34b7d
68500f8
d60b1e2
bc1001c
4bc52fc
e2b510d
172bfb4
729c0c5
9e0d4b0
110cead
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" /> | ||
|
@@ -43,4 +44,28 @@ | |
permission="cmf.ModifyPortalContent" | ||
/> | ||
|
||
<browser:page | ||
zcml:condition="installed Products.ATContentTypes" | ||
for="Products.ATContentTypes.interfaces.IATImage" | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here with this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
The variants are in the order of my preference (1 I like most). Any other variants or opinions? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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
andATNewsItem
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: