diff --git a/core/src/zeit/content/volume/browser/form.py b/core/src/zeit/content/volume/browser/form.py index 13eabe9d84..f418a5d7b9 100644 --- a/core/src/zeit/content/volume/browser/form.py +++ b/core/src/zeit/content/volume/browser/form.py @@ -70,10 +70,16 @@ def __init__(self, context, request): required=False, source=zeit.content.image.interfaces.imageGroupSource, ) - field.__name__ = 'cover_%s_%s' % (product.id, name) + field.__name__ = f'cover_{product.id}_{name}' field.interface = ICovers self.form_fields += zope.formlib.form.FormFields(field) fieldnames.append(field.__name__) + # In addition to covers, we give the possibility to override the title + field = zope.schema.Text(title=_('Title'), required=False) + field.__name__ = f'title_{product.id}' + field.interface = ICovers + self.form_fields += zope.formlib.form.FormFields(field) + fieldnames.append(field.__name__) self.field_groups += ( gocept.form.grouped.Fields(product.title, fieldnames, css_class='column-right'), ) @@ -156,17 +162,24 @@ class Covers(grok.Adapter): grok.context(zeit.content.volume.interfaces.IVolume) def __getattr__(self, name): - if not name.startswith('cover_'): - return super().__getattr__(name) - name = name.replace('cover_', '', 1) - product, cover = name.split('_') - # We dont want the fallback in the UI - return self.context.get_cover(cover, product, use_fallback=False) + if name.startswith('title_'): + product = name.split('_')[1] + return self.context.get_cover_title(product) + elif name.startswith('cover_'): + name = name.replace('cover_', '', 1) + product, cover = name.split('_') + # We dont want the fallback in the UI + return self.context.get_cover(cover, product, use_fallback=False) + return super().__getattr__(name) def __setattr__(self, name, value): - if not name.startswith('cover_'): - super().__setattr__(name, value) + if name.startswith('title_'): + product = name.split('_')[1] + self.context.set_cover_title(product, value) return - name = name.replace('cover_', '', 1) - product, cover = name.split('_') - self.context.set_cover(cover, product, value) + elif name.startswith('cover_'): + name = name.replace('cover_', '', 1) + product, cover = name.split('_') + self.context.set_cover(cover, product, value) + return + super().__setattr__(name, value) diff --git a/core/src/zeit/content/volume/interfaces.py b/core/src/zeit/content/volume/interfaces.py index 3f16b8ecc8..21c38d5733 100644 --- a/core/src/zeit/content/volume/interfaces.py +++ b/core/src/zeit/content/volume/interfaces.py @@ -84,6 +84,24 @@ def set_cover(cover_id, product_id, image): Set an image as a cover of product. """ + def get_cover_title(product_id): + """ + Get a title of a product. + For example volume.get_title('ZEI') returns the title of DIE ZEIT of + this specific volume. + :param product_id: str product ID set in products.xml + :return: str + """ + + def set_cover_title(product_id, title): + """ + Set cover specific title. + For example volume.set_title('ZEI', 'DIE ZEIT') sets the title of DIE + ZEIT of this specific volume. + :param product_id: str product ID set in products.xml + :param title: str - title of the product + """ + def all_content_via_search(additional_query_contstraints): """ Get all Content for this volume with a Elasticsearch-Lookup. diff --git a/core/src/zeit/content/volume/volume.py b/core/src/zeit/content/volume/volume.py index 9f10901e8e..02336f5577 100644 --- a/core/src/zeit/content/volume/volume.py +++ b/core/src/zeit/content/volume/volume.py @@ -38,6 +38,7 @@ class Volume(zeit.cms.content.xmlsupport.XMLContentBase): + """ @@ -204,6 +205,21 @@ def set_cover(self, cover_id, product_id, imagegroup): self.xml.find('covers').append(node) super().__setattr__('_p_changed', True) + def get_cover_title(self, product_id): + path = '//volume/title-overrides/title[@product_id="{}"]'.format(product_id) + node = self.xml.xpath(path) + return node[0].text if node else None + + def set_cover_title(self, product_id, title): + path = '//volume/title-overrides/title[@product_id="{}"]'.format(product_id) + node = self.xml.xpath(path) + if node: + self.xml.find('title-overrides').remove(node[0]) + if title is not None: + node = lxml.builder.E.title(title, product_id=product_id) + self.xml.find('title-overrides').append(node) + super().__setattr__('_p_changed', True) + def _is_valid_cover_id_and_product_id(self, cover_id, product_id): cover_ids = list(zeit.content.volume.interfaces.VOLUME_COVER_SOURCE(self)) product_ids = [prod.id for prod in self._all_products]