Skip to content

Commit

Permalink
WCM-498: add interface check in IgnoreMixin and add to generic DataSc…
Browse files Browse the repository at this point in the history
…ienceMixin
  • Loading branch information
Sinnaj94 committed Jan 7, 2025
1 parent 7fd4e62 commit ef50bcf
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions core/src/zeit/workflow/publish_3rdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ class IgnoreMixin:

#: map article attributes to settings
attr_setting_mapping = {
'genre': 'genres',
'template': 'templates',
'ressort': 'ressorts',
'uniqueId': 'uniqueids',
'genre': ('genres', zeit.content.article.interfaces.IArticleMetadata),
'template': ('templates', zeit.content.article.interfaces.IArticleMetadata),
'ressort': ('ressorts', zeit.content.article.interfaces.IArticleMetadata),
'uniqueId': ('uniqueids', zeit.cms.content.interfaces.ICommonMetadata),
}

@property
Expand All @@ -261,15 +261,21 @@ def name(self):
return self.__class__.__dict__['grokcore.component.directive.name']

def ignore(self, method):
if self.context.product and self.context.product.is_news:
if (
zeit.cms.content.interfaces.ICommonMetadata.providedBy(self.context)
and self.context.product
and self.context.product.is_news
):
return True
if method == 'publish':
for attribute, setting in self.attr_setting_mapping.items():
if self.is_on_ignorelist(attribute, setting):
if self.is_on_ignorelist(attribute, *setting):
return True
return False

def is_on_ignorelist(self, attribute, setting):
def is_on_ignorelist(self, attribute, setting, interface):
if not interface.providedBy(self.context):
return False
ignore_list = (
zeit.cms.config.get('zeit.workflow', f'{self.name}-ignore-{setting}', '')
.lower()
Expand Down Expand Up @@ -438,7 +444,7 @@ class CenterPageIndexNow(grok.Adapter, IndexNowMixin):
grok.name('indexnow')


class DataScienceMixin(PropertiesMixin):
class DataScienceMixin(PropertiesMixin, IgnoreMixin):
def _json(self):
if self.properties is None:
return None
Expand All @@ -447,15 +453,9 @@ def _json(self):
'body': lxml.etree.tostring(self.context.xml, encoding='unicode'),
}

def publish_json(self):
return self._json()

def retract_json(self):
return {}


@grok.implementer(zeit.workflow.interfaces.IPublisherData)
class ArticleDataScience(grok.Adapter, IgnoreMixin, DataScienceMixin):
class ArticleDataScience(grok.Adapter, DataScienceMixin):
grok.context(zeit.content.article.interfaces.IArticle)
grok.name('datascience')

Expand Down

0 comments on commit ef50bcf

Please sign in to comment.