Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tiberiuichim/c8ebae8c1de4d006b194d23b8ea08a71 to your computer and use it in GitHub Desktop.
Save tiberiuichim/c8ebae8c1de4d006b194d23b8ea08a71 to your computer and use it in GitHub Desktop.
diff --git a/eea/rdfmarshaller/dexterity/modifiers.py b/eea/rdfmarshaller/dexterity/modifiers.py
index 157c5a4..e19d26b 100644
--- a/eea/rdfmarshaller/dexterity/modifiers.py
+++ b/eea/rdfmarshaller/dexterity/modifiers.py
@@ -1,13 +1,16 @@
""" Modifiers """
import re
import sys
-import rdflib
-from Products.CMFCore.WorkflowCore import WorkflowException
-from Products.CMFCore.utils import getToolByName
-from Products.CMFPlone import log
+
from zope.component import adapts
from zope.interface import implements, providedBy
+
+import rdflib
+from eea.rdfmarshaller.interfaces import ISurfResourceModifier
from plone.dexterity.interfaces import IDexterityContent
+from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.WorkflowCore import WorkflowException
+from Products.CMFPlone import log
try:
from plone.app.multilingual.interfaces import ITranslationManager
@@ -15,7 +18,6 @@ try:
except ImportError:
has_plone_multilingual = False
-from eea.rdfmarshaller.interfaces import ISurfResourceModifier
ILLEGAL_XML_CHARS_PATTERN = re.compile(
u'[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]'
@@ -42,11 +44,13 @@ class WorkflowStateModifier(object):
workflowTool = getToolByName(self.context, "portal_workflow")
wfs = workflowTool.getWorkflowsFor(self.context)
wf = None
+
for wf in wfs:
if wf.isInfoSupported(self.context, "portal_workflow"):
break
status = workflowTool.getInfoFor(self.context, "review_state", None)
+
if status is not None:
status = ''.join([portal_url,
"/portal_workflow/",
@@ -62,6 +66,7 @@ class WorkflowStateModifier(object):
(self.context.absolute_url(),
sys.exc_info()[0], sys.exc_info()[1]),
severity=log.logging.WARN)
+
return resource
@@ -81,6 +86,7 @@ class IsPartOfModifier(object):
"""
parent = self.context.getParentNode()
wftool = getToolByName(self.context, 'portal_workflow')
+
if parent is not None:
try:
state = wftool.getInfoFor(parent, 'review_state')
@@ -109,12 +115,13 @@ class TranslationInfoModifier(object):
context = self.context
# ZZZ: should watch for availability of plone.app.multilingual
+
if has_plone_multilingual:
- translations = ITranslationManager(
- context).get_translated_languages()
+ tm = ITranslationManager(context)
+ translations = tm.get_translated_languages()
if translations:
- translations_objs = [ITranslationManager.get_translation(o)
+ translations_objs = [tm.get_translation(o)
for o in translations]
resource.eea_hasTranslation = \
[rdflib.URIRef(o.absolute_url()) for o in translations_objs
@@ -124,6 +131,7 @@ class TranslationInfoModifier(object):
rdflib.URIRef(context.absolute_url())
else:
resource.eea_hasTranslation = ['No Translation']
+
return
@@ -175,11 +183,13 @@ class RelatedItemsModifier(object):
def run(self, resource, *args, **kwds):
"""Change the rdf resource
"""
+
if not getattr(self.context, 'relatedItems', None):
return
resource.dcterms_references = [
rdflib.URIRef(o.to_object.absolute_url())
+
for o in self.context.relatedItems]
@@ -199,6 +209,7 @@ class BaseFileModifier(object):
"""change the rdf resource
"""
item = getattr(self.context, self.field)
+
if not item:
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment