Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the list of supported content types that the linkintegrity plugin will reference #26

Open
neilferreira opened this issue Sep 9, 2015 · 1 comment

Comments

@neilferreira
Copy link

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.

@jensens
Copy link
Member

jensens commented Sep 14, 2015

idea: use named adapters, register an adapter for each case, iterate over all adapters and let them do their work. so its easy to provide a custom adapter with an custom widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants