Currently only links within RichText fields are being added as references.
I've currently got an updated method used in a project which could be a good starting point:
def build_deps(referenced_content, value):
logger = logging.getLogger(__name__)
if not value:
return
if (isinstance(value, bool) or isinstance(value, int) or
isinstance(value, NamedBlobFile) or isinstance(value, date) or
isinstance(value, NamedFile)):
# We can't do anything with these
return
elif (isinstance(value, RichTextValue) or isinstance(value, str) or
isinstance(value, unicode)):
if isinstance(value, RichTextValue):
value = value.raw
links = extractLinks(value)
for content in getObjectsFromLinks(obj, links):
referenced_content.append(getattr(content, 'context', content))
elif isinstance(value, Structure):
if value.hasContentObject:
referenced_content.append(value.getContentObject())
elif isinstance(value, dict):
for key in value:
build_deps(referenced_content, value[key])
elif isinstance(value, list) or isinstance(value, set) or isinstance(value, tuple):
for row in value:
build_deps(referenced_content, row)
elif isinstance(value, RelationValue):
referenced_content.append(value.to_object)
else:
logger.error('Could not do anything with %s (type %s)' % (value, type(value)))
The "Structure" object is a custom widget type that we've created, ideally we could just check for a 'content object' on a specific attribute so support for this can be implemented by anyone wanting their custom schema types to include referenced content.
Currently only links within RichText fields are being added as references.
I've currently got an updated method used in a project which could be a good starting point:
The "Structure" object is a custom widget type that we've created, ideally we could just check for a 'content object' on a specific attribute so support for this can be implemented by anyone wanting their custom schema types to include referenced content.