adhocracy_core.graph package

Set/Get Resource References / versions graph (DAG) helpers.

class SheetReftype[source]

Bases: adhocracy_core.graph.ISheetReftype

Fields: isheet field reftype.

class Graph(context)[source]

Bases: persistent.Persistent

Utility to work with versions/references.

This implementation depends on the substanced.objectmap.Objectmap service.

Initialize self.

get_reftypes(base_isheet=<InterfaceClass adhocracy_core.interfaces.ISheet>, base_reftype=<SheetReferenceClass adhocracy_core.interfaces.SheetReference>) → collections.abc.Iterator[source]

Collect all used SheetReferenceTypes.

Return type:

Iterator

Parameters:
  • base_reftype – Skip types that are not subclasses of this.
  • base_isheet – Skip types with a source isheet that is not a subclass of this.
Returns:

Generator of adhocracy_core.graph.SheetReftype

set_references(source, targets: collections.abc.Iterable, reftype: <SheetReferenceClass adhocracy_core.interfaces.SheetReference>, registry: pyramid.registry.Registry=None, send_event=True)[source]

Set references of this source.

Parameters:
  • targets (Iterable) – the reference targets, for Sequences the order is preserved.
  • reftype – the reftype mapping to one isheet field.
  • registry (Registry) – pyramid registry to notify referenced resources. Default value is None to ease testing.
  • send_event (bool) – send events to notify referenced resources
get_references(source, base_isheet=<InterfaceClass adhocracy_core.interfaces.ISheet>, base_reftype=<SheetReferenceClass adhocracy_core.interfaces.SheetReference>) → collections.abc.Iterator[source]

Get generator of Reference with this source.

get_back_references(target, base_isheet=<InterfaceClass adhocracy_core.interfaces.ISheet>, base_reftype=<SheetReferenceClass adhocracy_core.interfaces.SheetReference>) → collections.abc.Iterator[source]

Get generator of Reference with this target.

get_back_reference_sources(resource, reftype=<SheetReferenceClass adhocracy_core.interfaces.SheetReference>) → collections.abc.Iterable[source]

Get generator of the sources of backreferences.

Return type:

Iterable

Parameters:
  • resource – the resource whose backreferences we want
  • reftype – the type of backreferences we want
Returns:

a generator of reference sources (sheets referring to the resource)

set_references_for_isheet(source, isheet: <InterfaceClass adhocracy_core.interfaces.ISheet>, references: dict, registry: pyramid.registry.Registry, send_event=True)[source]

Set references of this source for one isheet.

Parameters:
get_references_for_isheet(source, isheet: <InterfaceClass adhocracy_core.interfaces.ISheet>) → dict[source]

Get references of this source for one isheet only.

Returns:dictionary with the following content: key - isheet field name value - reference targets

References from subtypes of isheet are also listed. Fields without existing references are ignored.

get_back_references_for_isheet(target, isheet: <InterfaceClass adhocracy_core.interfaces.ISheet>) → dict[source]

Get references that point to this target for one isheet only.

: return: dictionary with the following content:

key - isheet field name value - references sources

References from subtypes of isheet are also listed. Fields without existing references are ignored.

is_in_subtree(descendant, ancestors: collections.abc.Iterable) → bool[source]

Check whether a resource is in a subtree below other resources.

Return type:

bool

Parameters:
  • descendant – the candidate descendant
  • ancestors (Iterable) – the candidate ancestors
Returns:

True if there exists a relation from one of the ancestors to descendant that does NOT include any ‘follows’ links. For example, descendant might be an element of an element (of an element...) of an ancestor. Also if descendant and one of the ancestors are the same node.

False otherwise.

get_refernces_for_removal_notificaton(context: <InterfaceClass adhocracy_core.interfaces.IResource>) → [<class 'adhocracy_core.interfaces.Reference'>][source]
send_back_reference_removal_notificatons(references: [<class 'adhocracy_core.interfaces.Reference'>], registry: pyramid.registry.Registry)[source]

Send SheetBackReferenceRemoved to reference targets.

includeme(config)[source]

Register Graph content type.