Skip to content

Commit

Permalink
ZO-6370: WIP/temp - try to add converter when image is dropped into I…
Browse files Browse the repository at this point in the history
…ImageGrid
  • Loading branch information
Sinnaj94 committed Nov 14, 2024
1 parent d5b3a6f commit 0d1f2cb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
16 changes: 16 additions & 0 deletions core/src/zeit/content/article/edit/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def factor_image_block_from_imagegroup(body, group, position):
return factor_image_block_from_image(body, group, position)


@grok.adapter(
zeit.content.article.edit.interfaces.IImageGrid, zeit.content.image.interfaces.IImage, int
)
@grok.implementer(zeit.edit.interfaces.IElement)
def factor_image_block_from_image_grid(body, image, position):
return factor_image_block_from_image(body, image, position)


@grok.adapter(
zeit.content.article.edit.interfaces.IImageGrid, zeit.content.image.interfaces.IImageGroup, int
)
@grok.implementer(zeit.edit.interfaces.IElement)
def factor_image_block_from_imagegroup_grid(body, image, position):
return factor_image_block_from_image(body, image, position)


@grok.subscribe(zeit.content.article.interfaces.IArticle, zope.lifecycleevent.IObjectModifiedEvent)
def copy_image_to_body(context, event):
for description in event.descriptions:
Expand Down
26 changes: 10 additions & 16 deletions core/src/zeit/content/article/edit/image_grid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import grokcore.component as grok
import lxml

from zeit.cms.content.property import ObjectPathAttributeProperty
from zeit.cms.i18n import MessageFactory as _
Expand All @@ -11,13 +10,6 @@

@grok.implementer(zeit.content.article.edit.interfaces.IImageGrid)
class ImageGrid(zeit.content.article.edit.block.Block):
def __init__(self, context, xml):
# call base constructor
super(ImageGrid, self).__init__(context, xml)
# set xml object to default template, if it has no body
if not self.xml.xpath('//body'):
self.xml.append(lxml.etree.Element('body'))

type = 'image_grid'

show_caption = ObjectPathAttributeProperty(
Expand All @@ -29,14 +21,16 @@ def __init__(self, context, xml):
aspect_ration = ObjectPathAttributeProperty(
'.', 'aspect_ration', zeit.content.article.edit.interfaces.IImageGrid['aspect_ration']
)
images = zeit.cms.content.reference.MultiResource('.body.image', 'image')

# first_image = zeit.cms.content.reference.SingleResource('.image[1]', 'image')
# second_image = zeit.cms.content.reference.SingleResource('.image[2]', 'image')
# third_image = zeit.cms.content.reference.SingleResource('.image[3]', 'image')
# first_image = zeit.cms.content.reference.SingleResource('.image-1', 'image')
# second_image = zeit.cms.content.reference.SingleResource('.image-2', 'image')
# third_image = zeit.cms.content.reference.SingleResource('.image-3', 'image')
_images = zeit.cms.content.reference.MultiResource('.image', 'image')

@property
def images(self):
return self._images

@images.setter
def images(self, value):
# TODO: Should I convert the Image here?
self._images = value


class Factory(zeit.content.article.edit.block.BlockFactory):
Expand Down

0 comments on commit 0d1f2cb

Please sign in to comment.