Skip to content

Commit f9c5afd

Browse files
[ADD] checkbox to disable event image
1 parent c1b8a3b commit f9c5afd

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

src/genweb6/core/behaviors.zcml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,13 @@
5050
marker="genweb6.core.interfaces.ISeoMarker"
5151
/>
5252

53+
<plone:behavior
54+
name="genweb.event_image"
55+
title="Event Image Options"
56+
description="Add option to hide image on event page but show in portlets and views"
57+
provides=".behaviors.event_image.IEventImage"
58+
factory=".behaviors.event_image.EventImage"
59+
for="plone.app.contenttypes.interfaces.IEvent"
60+
/>
61+
5362
</configure>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
from plone.app.contenttypes.behaviors.leadimage import ILeadImage
3+
from plone.autoform.interfaces import IFormFieldProvider
4+
from plone.supermodel import model
5+
from zope import schema
6+
from zope.interface import alsoProvides
7+
from zope.interface import implementer
8+
9+
from genweb6.core import _
10+
11+
12+
class IEventImage(ILeadImage):
13+
"""Extend ILeadImage to add not_show_image field for events
14+
"""
15+
16+
not_show_image = schema.Bool(
17+
title=_(u"not_show_image"),
18+
description=_(u"No mostreu la imatge a la pàgina, però sí que ho feu als portlets i a les vistes."),
19+
required=False,
20+
default=False,
21+
)
22+
23+
alsoProvides(IEventImage, IFormFieldProvider)
24+
25+
26+
@implementer(IEventImage)
27+
class EventImage(object):
28+
"""Adapter for IEventImage behavior
29+
"""
30+
31+
def __init__(self, context):
32+
self.context = context
33+
34+
def _get_not_show_image(self):
35+
return getattr(self.context, 'not_show_image', False)
36+
37+
def _set_not_show_image(self, value):
38+
self.context.not_show_image = value
39+
40+
not_show_image = property(_get_not_show_image, _set_not_show_image)
41+

src/genweb6/core/browser/leadimage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from plone.app.contenttypes.behaviors.viewlets import LeadImageViewlet
33
from plone.event.interfaces import IOccurrence
44
from plone.app.contenttypes.behaviors.leadimage import ILeadImage
5+
from plone.app.contenttypes.interfaces import IEvent
6+
from genweb6.core.behaviors.event_image import IEventImage
57
from zope.interface import alsoProvides
68
from zope.component import queryAdapter
79

@@ -17,6 +19,23 @@ def update(self):
1719
if not ILeadImage.providedBy(self.context):
1820
self.available = False
1921
return
22+
23+
# Si es un Event, verificar si tiene not_show_image activado
24+
# Si está activado, ocultar la imagen en la página (pero mostrarla en portlets)
25+
if IEvent.providedBy(self.context):
26+
# Intentar obtener el valor del campo usando el adapter del behavior
27+
try:
28+
from zope.component import getAdapter
29+
event_image = getAdapter(self.context, IEventImage)
30+
not_show_image = event_image.not_show_image
31+
except:
32+
# Si no se puede obtener el adapter, leer directamente del contexto
33+
not_show_image = getattr(self.context, 'not_show_image', False)
34+
35+
if not_show_image:
36+
self.available = False
37+
return
38+
2039
self.available = True
2140

2241
super().update()

src/genweb6/core/portlets/multiviewcollectionevents/multiviewcollectionevents.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,29 @@ def result_dicts(self):
119119

120120
date = toLocalizedTime(self, result.end)
121121

122+
# Solo generar image_src si hay imagen y es válida
123+
# El campo not_show_image solo afecta a la vista del evento, no a los portlets
124+
image_src = None
125+
if result_image:
126+
try:
127+
# Verificar que la imagen existe y tiene contenido
128+
if hasattr(result_image, 'getSize'):
129+
size = result_image.getSize()
130+
if size and size > 0:
131+
image_src = "{0}/@@images/image/large".format(result.getURL())
132+
except (AttributeError, TypeError, Exception):
133+
# Si hay algún error al verificar la imagen, no generar la URL
134+
# Esto evita timeouts y errores si la imagen no está disponible
135+
image_src = None
136+
result_image = None
137+
122138
result_dicts.append(dict(
123139
date=date,
124140
description=self._summarize(result_description),
125141
col=col,
126-
image=result_image,
142+
image=result_image if image_src else None,
127143
image_caption=getattr(result_obj, 'image_caption', None),
128-
image_src=("{0}/@@images/image/large".format(result.getURL()) if result_image else None),
144+
image_src=image_src,
129145
portal_type=normalizeString(result.portal_type),
130146
title=result.title_or_id(),
131147
url=result.getURL(),

src/genweb6/core/profiles/default/types/Event.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<element value="plone.dublincore" />
1313
<element value="plone.richtext" />
1414
<element value="plone.leadimage" />
15+
<element value="genweb.event_image" />
1516
<element value="plone.allowdiscussion" />
1617
<element value="plone.excludefromnavigation" />
1718
<element value="plone.relateditems" />

0 commit comments

Comments
 (0)