Metadata-Version: 2.1
Name: collective.relationhelpers
Version: 1.0a2
Summary: Helpers to manage, create, export and rebuild relations in Plone
Home-page: https://github.com/collective/collective.relationhelpers
Author: Philip Bauer
Author-email: bauer@starzel.de
License: GPL version 2
Project-URL: PyPI, https://pypi.python.org/pypi/collective.relationhelpers
Project-URL: Source, https://github.com/collective/collective.relationhelpers
Project-URL: Tracker, https://github.com/collective/collective.relationhelpers/issues
Description: .. This README is meant for consumption by humans and pypi. Pypi can render rst files so please do not use Sphinx features.
           If you want to learn more about writing documentation, please check out: http://docs.plone.org/about/documentation_styleguide.html
           This text does not appear on pypi or github. It is a comment.
        
        ==========================
        collective.relationhelpers
        ==========================
        
        Helpers to manage, create, export and rebuild relations in Plone
        
        To learn more about relations read https://training.plone.org/5/mastering-plone/relations.html
        
        
        Features
        ========
        
        Rebuild all relations
        ---------------------
        
        There is a form ``http://localhost:8080/Plone/@@rebuild_relations`` that rebuilds all relations.
        
        It exports all valid reations from the relation-catalog, purges the relation-catalog (and the intid-catalog) and restores all valid relations.
        
        
        Use it in you own projects
        --------------------------
        
        The form uses some methods that you can use in your own projects or in your upgrade-steps.
        They are a great addition to the helpers in https://github.com/collective/collective.migrationhelpers
        
        
        
        Dealing with all relations at once
        ----------------------------------
        
        Especially during migrations (e.g. between Archetypes and Dexteriy or from Python 2 to 3) you need to deal with all relations at once.
        For example the relation-catalog and the intid-catalog could hold references to broken or removes objects.
        
        First import the api: ``from collective.relationhelpers import api as relapi``
        
        ``relapi.rebuild_relations()``
            Rebuild all relations using the same code as the form ``@@rebuild_relations``
        
        ``relapi.get_all_relations()``
            Get all relations as a list of dicts.
        
        ``relapi.export_relations()``
            Export all relations as a json file ``all_relations.json`` in you buildout directory.
        
        ``relapi.store_relations()``
            Export all relations and store them as a annotation on the portal ``IAnnotations(portal)['ALL_REFERENCES']``.
        
        ``relapi.cleanup_intids()``
            Purge all RelationValues and all references to broken objects from the IntId catalog.
        
        ``relapi.get_relations_stats()``
            Log information on all existing relations
        
        ``relapi.restore_relations(all_relations=None)``
            Recreate relations from a annotation on the portal or a list of dicts (e.g. restored from the json-file created by ``export_relations``).
            This works fine for all kinds of relations, RelationList- or RelationChoice-fields (including the default field "Related Items") as well as for linkintegrity-relations and relations between working-copies.
        
        
        Dealing with relations on individual objects
        --------------------------------------------
        
        **Convenience methods:**
        
        ``relations(obj, attribute=None, as_dict=False)``
            Get related objects.
        
        ``unrestricted_relations(obj, attribute=None, as_dict=False)``
            Get related objects without permission checks.
        
        ``backrelations(obj, attribute=None, as_dict=False)``
            Get objects with a relation to this object.
        
        ``unrestricted_backrelations(obj, attribute=None, as_dict=False)``
            Get objects with a relation to this object without permission checks.
        
        ``relation(obj, attribute)``
            Get related object. This is only valid if the attribute is the name of a relationChoice field on the object.
        
        ``unrestricted_relation(obj, attribute)``
            Get related object without permission checks. See relation
        
        ``backrelation(obj, attribute)``
            Get relating object. This only makes sense when one item has a relation of this type to the obj.
            One example is parent -> child where only one parent can exist.
        
        ``unrestricted_backrelation(obj, attribute)``
            Get relating object without permission checks. See backrelation
        
        ``relapi.link_objects(source, target, relationship)``
            Link objects: Create a relation between two objects using the specified relationship.
            From the parameter ``relationship`` the method will find out what kind of relationship you want to create (RelationChoice, RelationList) by inspecting the schema-field on the source-object.
            The method also works for linkintegrity-relations and relations between working-copies.
        
            Example: To use the default-behavior ``plone.relateditems`` use the field-name ``relatedItems`` as relationship: ``relapi.link_objects(obj, anotherobj, 'relatedItems')``.
        
        
        **Main method to get all kinds of relations:**
        
        ``relapi.get_relations(obj, attribute=None, backrels=False, restricted=True, as_dict=False)``
            Get a list of incoming or outgoing relation for a specific content object.
        
            If you pass a attribute you only get relations of that type. This is the same as the fieldname on the source-object and the ``from_attribute`` on a RelationValue. You can also pass a list if attributes to get relations of certain types.
        
            By default the result is a list of objects. If you set as_dict=True it will return a dict with the names of the relations as keys and lists of objects as values.
        
        
        Installation
        ============
        
        Install collective.relationhelpers by adding it to your buildout::
        
            [buildout]
        
            ...
        
            eggs =
                collective.relationhelpers
        
        
        and then running ``bin/buildout``.
        
        
        Contribute
        ==========
        
        - Issue Tracker: https://github.com/collective/collective.relationhelpers/issues
        - Source Code: https://github.com/collective/collective.relationhelpers
        
        
        Support
        =======
        
        If you are having issues, please create a ticket.
        
        
        License
        =======
        
        The project is licensed under the GPLv2.
        
        
        Contributors
        ============
        
        - Philip Bauer, bauer@starzel.de
        
        
        Changelog
        =========
        
        
        1.0a2 (2020-09-15)
        ------------------
        
        - Modify Api:
          * return objects by default, optionally return a dict by relationname
          * check view-permissions by default
          * add convenience-methods relations, backrelations, unrestricted_relations and unrestricted_backrelations
          * add convenience-method relation for relationChoice that only returns one object, not a list
          * rename parameter backref to backrel
          * allow to query for multiple reations
        
        
        1.0a1 (2020-05-29)
        ------------------
        
        - Initial release.
          [pbauer]
        
Keywords: Python Plone
Platform: UNKNOWN
Classifier: Environment :: Web Environment
Classifier: Framework :: Plone
Classifier: Framework :: Plone :: Addon
Classifier: Framework :: Plone :: 5.2
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Requires-Python: >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*
Provides-Extra: test
