Skip to content

Commit 4c06fcc

Browse files
committed
fix for usage in monologingual sites
1 parent 321aa55 commit 4c06fcc

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

src/udala/zinema/views/pelikula_container_view.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
from zope.interface import Interface, alsoProvides, implementer
2020
from plone.event.interfaces import IEventAccessor
2121
from plone.namedfile.file import NamedBlobImage
22+
from plone.base.utils import get_installer
23+
24+
25+
def is_pam_enabled(context):
26+
installer = get_installer(context)
27+
return installer.is_product_installed("plone.app.multilingual")
2228

2329

2430
class IPelikulaContainerView(Interface):
@@ -159,8 +165,7 @@ def create_event_with_pelikulas(self, items):
159165
type="Event",
160166
title=title,
161167
text=RichTextValue(
162-
safe_text(self.get_initial_stuff(language).output)
163-
+ safe_text(html_content)
168+
safe_text(self.get_initial_stuff(language)) + safe_text(html_content)
164169
),
165170
# start=start_date,
166171
# end=end_date,
@@ -191,22 +196,22 @@ def create_event_with_pelikulas(self, items):
191196
source=context, target=item, relationship=REFERENCED_FILM
192197
)
193198

194-
translated, trans_items = self.create_translated_event(event, items)
195-
# translated_context = context.getTranslation(MEZUAK["translation"][language])
196-
translation_manager = pamapi.get_translation_manager(context)
197-
translated_context = translation_manager.get_translation(
198-
MEZUAK["translation"][language]
199-
)
200-
# Set the content and references to translated content
201-
translated_context.text = translated.text
202-
203-
# translated_context.deleteReferences(REFERENCED_FILM)
204-
api.relation.delete(source=translated_context, relationship=REFERENCED_FILM)
205-
for item in trans_items:
206-
# translated_context.addReference(item, REFERENCED_FILM)
207-
api.relation.create(
208-
source=translated_context, target=item, relationship=REFERENCED_FILM
199+
if is_pam_enabled(self.context):
200+
translated, trans_items = self.create_translated_event(event, items)
201+
translation_manager = pamapi.get_translation_manager(context)
202+
translated_context = translation_manager.get_translation(
203+
MEZUAK["translation"][language]
209204
)
205+
# Set the content and references to translated content
206+
translated_context.text = translated.text
207+
208+
# translated_context.deleteReferences(REFERENCED_FILM)
209+
api.relation.delete(source=translated_context, relationship=REFERENCED_FILM)
210+
for item in trans_items:
211+
# translated_context.addReference(item, REFERENCED_FILM)
212+
api.relation.create(
213+
source=translated_context, target=item, relationship=REFERENCED_FILM
214+
)
210215

211216
return event
212217

@@ -259,7 +264,7 @@ def create_translated_event(self, event, items):
259264
api.content.rename(obj=trans_event, new_id=id)
260265
trans_event.title = title
261266
trans_event.text = RichTextValue(
262-
self.get_initial_stuff(target_language).output + html_content
267+
self.get_initial_stuff(target_language) + html_content
263268
)
264269
trans_event.location = MEZUAK["location"][target_language]
265270
trans_event.subjects = MEZUAK["subject"][target_language]
@@ -318,7 +323,7 @@ def get_html_content(self, items):
318323
html += self.get_content_for_pelikula(item, num)
319324
num = num + 1
320325

321-
return images + "<br /> <br />" + html
326+
return f'<div class="d-flex justify-content-center">{images}</div><br /> <br />{html}'
322327

323328
def get_top_image(self, item, num=0):
324329
self.request.set("num", num)
@@ -339,6 +344,10 @@ def get_content_for_pelikula(self, item, num=0):
339344
return view()
340345

341346
def get_initial_stuff(self, language):
342-
manager = pamapi.get_translation_manager(self.context)
343-
item = manager.get_translation(language)
344-
return item.initial_stuff
347+
if is_pam_enabled(self.context):
348+
manager = pamapi.get_translation_manager(self.context)
349+
item = manager.get_translation(language)
350+
else:
351+
item = self.context
352+
353+
return item and item.initial_stuff and item.initial_stuff.output or ""

0 commit comments

Comments
 (0)