Skip to content

Commit

Permalink
Remove logo field from cropping editor
Browse files Browse the repository at this point in the history
  • Loading branch information
laulaz committed Oct 26, 2023
1 parent 72c3bac commit 78b4088
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.1 (unreleased)
------------------

- Nothing changed yet.
- Remove logo field from cropping editor
[laulaz]


1.2 (2023-10-25)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
install_requires=[
"setuptools",
"z3c.jbot",
"z3c.unconfigure",
"plone.api>=1.8.4",
"plone.gallery",
"plone.restapi",
Expand Down
2 changes: 2 additions & 0 deletions src/imio/directory/core/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope">

<include package="z3c.unconfigure" file="meta.zcml" />

<include package="collective.geolocationbehavior" />
<include package="collective.monkeypatcher" />
<include package="collective.schedulefield" />
Expand Down
11 changes: 11 additions & 0 deletions src/imio/directory/core/contents/contact/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
<adapter factory=".serializer.SerializeContactToJson" />
<adapter factory=".serializer.ContactJSONSummarySerializer" />

<unconfigure>
<adapter factory="plone.app.imagecropping.dx.CroppingUtilsDexterity" />
<adapter
for="plone.dexterity.interfaces.IDexterityContent"
provides="imio.smartweb.common.interfaces.ICropping"
factory="imio.smartweb.common.adapters.BaseCroppingProvider"
/>
</unconfigure>

<adapter factory=".content.DirectoryCroppingUtilsDexterity" />

<adapter
for=".content.Contact"
provides="imio.smartweb.common.interfaces.ICropping"
Expand Down
24 changes: 21 additions & 3 deletions src/imio/directory/core/contents/contact/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
from imio.smartweb.locales import SmartwebMessageFactory as _
from plone import schema
from plone.app.content.namechooser import NormalizingNameChooser
from plone.app.imagecropping.dx import CroppingUtilsDexterity
from plone.app.imagecropping.interfaces import IImageCroppingUtils
from plone.app.z3cform.widget import SelectFieldWidget
from plone.autoform import directives
from plone.autoform.directives import read_permission
from plone.autoform.directives import widget
from plone.autoform.directives import write_permission
from plone.dexterity.content import Container
from plone.namedfile.field import NamedBlobImage
from plone.namedfile.interfaces import IImage
from plone.namedfile.interfaces import IImageScaleTraversable
from plone.supermodel import model
from z3c.form.browser.radio import RadioFieldWidget
from z3c.form.converter import FormatterValidationError
from zope.component import adapter
from zope.container.interfaces import INameChooser
from zope.interface import Interface
from zope.interface import implementer
Expand All @@ -26,9 +31,22 @@

import re

# from collective.geolocationbehavior.geolocation import IGeolocatable
# from plone.supermodel.interfaces import FIELDSETS_KEY
# from plone.supermodel.model import Fieldset
UNCROPPABLE_FIELDS = ["logo"]


@implementer(IImageCroppingUtils)
@adapter(IImageScaleTraversable)
class DirectoryCroppingUtilsDexterity(CroppingUtilsDexterity):
def _image_field_values(self):
"""Remove logo field from cropping editor"""
for fieldname, field in self._all_fields():
value = getattr(self.context, fieldname, None)
if (
value
and IImage.providedBy(value)
and fieldname not in UNCROPPABLE_FIELDS
):
yield (fieldname, value)


class ContactCroppingProvider(BaseCroppingProvider):
Expand Down
17 changes: 16 additions & 1 deletion src/imio/directory/core/tests/test_cropping.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-

from imio.directory.core.testing import IMIO_DIRECTORY_CORE_INTEGRATION_TESTING
from imio.directory.core.tests.utils import make_named_image
from imio.smartweb.common.interfaces import ICropping
from plone import api
from plone.app.imagecropping.interfaces import IImageCroppingUtils
from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles
from plone.namedfile.file import NamedBlobImage
from zope.component import getMultiAdapter

import unittest
Expand Down Expand Up @@ -38,9 +41,21 @@ def test_cropping_adapter(self):
)
self.assertEqual(adapter.get_scales("logo", self.request), [])

def test_uncroppable_fields(self):
self.contact.logo = NamedBlobImage(**make_named_image())
self.contact.image = NamedBlobImage(**make_named_image())
adapter = IImageCroppingUtils(self.contact, alternate=None)
self.assertIsNotNone(adapter)
self.assertEqual(len(list(adapter._image_field_values())), 1)
self.assertEqual(adapter.image_field_names(), ["image"])

def test_cropping_view(self):
self.contact.logo = NamedBlobImage(**make_named_image())
self.contact.image = NamedBlobImage(**make_named_image())
cropping_view = getMultiAdapter(
(self.contact, self.request), name="croppingeditor"
)
self.assertEqual(len(list(cropping_view._scales("image"))), 2)
self.assertEqual(len(list(cropping_view._scales("logo"))), 0)
self.assertEqual(len(list(cropping_view._scales("image"))), 2)
self.assertNotIn("Logo", cropping_view())
self.assertIn("Lead Image", cropping_view())

0 comments on commit 78b4088

Please sign in to comment.