assembl.views.traversal module

This defines Context objects for traversal of the magic api.

Pyramid allows to use model objects as Context objects, but in our cases they’re surrogates for model objects.

class assembl.views.traversal.AbstractCollectionDefinition(owner_class, name, collection_class)[source]

Bases: object

Represents a collection of objects related to an instance.

extra_permissions(permissions)[source]

Return a list of extra permissions that could be added along the way.

See e.g. in assembl.models.widgets.IdeaCreatingWidget.BaseIdeaHidingCollection

qual_name()[source]

The fully qualified name of the collection, including owning class name.

Used in NamedCollectionContextPredicate and TraversalContext.find_collection().

class assembl.views.traversal.Api2Context(parent, acl=None)[source]

Bases: assembl.views.traversal.TraversalContext

The root class for the magic API (/data)

Sub-contexts are ClassContext

creation_side_effects_rec(inst_ctx, top_ctx)[source]

Apply simple side-effects from the instance

decorate_query(query, ctx, tombstones=False)[source]

Given a SQLAlchemy query, add joins and filters that correspond to this step in the traversal path.

on_new_instance(instance)[source]

If a model instance was created in this context, let the context learn about it. Exists mostly for RelationCollectionDefinition.on_new_instance()

class assembl.views.traversal.AppRoot(request=None, user_id=None)[source]

Bases: assembl.views.traversal.DictContext

The root context. Anything not defined by a root comes here.

find_collection(collection_class_name)[source]

Find a collection by name

get_discussion_id()[source]

Get the current discussion_id somehow

often from a DiscussionBoundBase instance

get_instance_ctx_of_class(cls)[source]

Look in the context chain for a model instance of a given class, and return that context

get_instance_of_class(cls)[source]

Look in the context chain for a model instance of a given class

get_permissions(discussion_id=None)[source]

Get the permissions from the request, maybe altering on the way.

See e.g. in assembl.models.widgets.IdeaCreatingWidget.BaseIdeaHidingCollection

get_request()[source]

Get the request from the context, if known

class assembl.views.traversal.BaseContext(parent=None, acl=None)[source]

Bases: object

The base class for all traversal contexts. Delegate everything to parent by default.

find_collection(collection_class_name)[source]

Find a collection by name

get_discussion_id()[source]

Get the current discussion_id somehow

often from a DiscussionBoundBase instance

get_instance_ctx_of_class(cls)[source]

Look in the context chain for a model instance of a given class, and return that context

get_instance_of_class(cls)[source]

Look in the context chain for a model instance of a given class

get_permissions(discussion_id=None)[source]

Get the permissions from the request, maybe altering on the way.

See e.g. in assembl.models.widgets.IdeaCreatingWidget.BaseIdeaHidingCollection

get_request()[source]

Get the request from the context, if known

class assembl.views.traversal.ClassContext(parent, cls)[source]

Bases: assembl.views.traversal.TraversalContext

A context that represents a given model class (e.g. /data/Idea)

Sub-contexts are InstanceContext, given by numeric ID.

get_class(typename=None)[source]

Returns the collection class, or subclass designated by typename

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.ClassContextPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is a ClassContext and represents the given class.

class assembl.views.traversal.CollectionContext(parent, collection, instance)[source]

Bases: assembl.views.traversal.TraversalContext

A context that represents a collection of model objects related to the model object of the parent InstanceContext.

The collection itself is embodied by a AbstractCollectionDefinition object, often backed by a SQLA relationship. Sub-contexts are InstanceContext, indexed by Id.

creation_side_effects_rec(inst_ctx, top_ctx)[source]

Apply side-effects through multiple dispatch on the collection

decorate_query(query, ctx, tombstones=False)[source]

Given a SQLAlchemy query, add joins and filters that correspond to this step in the traversal path.

find_collection(collection_class_name)[source]

Find a collection by name

get_collection_class(typename=None)[source]

Returns the collection class, or subclass designated by typename

get_instance_of_class(cls)[source]

Look in the context chain for a model instance of a given class

get_permissions(discussion_id=None)[source]

Get the permissions from the request, maybe altering on the way.

See e.g. in assembl.models.widgets.IdeaCreatingWidget.BaseIdeaHidingCollection

get_target_class()[source]

What is the model class we can expect to find at this context?

on_new_instance(instance)[source]

If a model instance was created in this context, let the context learn about it. Exists mostly for RelationCollectionDefinition.on_new_instance()

class assembl.views.traversal.CollectionContextClassPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is a CollectionContext, where the class of the targets of the relationship is as given.

class assembl.views.traversal.DictContext(name, acl, subobjects=None)[source]

Bases: assembl.views.traversal.BaseContext

A Context defined using a simple dictionary

class assembl.views.traversal.DiscussionPreferenceCollection(cls)[source]

Bases: assembl.views.traversal.AbstractCollectionDefinition

Represents the collection of preferences for a given discussion’s DiscussionPreferenceContext.

class assembl.views.traversal.DiscussionPreferenceContext(parent_context, collection)[source]

Bases: assembl.views.traversal.PreferenceContext

Represents a set of preference values for a discussion

Backed by a DiscussionPreferenceCollection, sub-contexts are PreferenceValueContext

class assembl.views.traversal.DiscussionsContext(parent=None, acl=None)[source]

Bases: assembl.views.traversal.BaseContext

A context where discussions, named by id, are sub-contexts

class assembl.views.traversal.InstanceContext(parent, instance)[source]

Bases: assembl.views.traversal.TraversalContext

A context that represents a given model instance (e.g. /data/Idea/12)

Sub-contexts are CollectionContext, given by relationship name or taken from assembl.lib.sqla.Base.extra_collections_dict().

find_collection(collection_class_name)[source]

Find a collection by name

get_discussion_id()[source]

Get the current discussion_id somehow

often from a DiscussionBoundBase instance

get_instance_ctx_of_class(cls)[source]

Look in the context chain for a model instance of a given class, and return that context

get_instance_of_class(cls)[source]

Look in the context chain for a model instance of a given class

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.InstanceContextPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is a InstanceContext, and that the instance is of the given class.

class assembl.views.traversal.InstanceContextPredicateWithExceptions(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is a InstanceContext, and that the instance is of the given class, but not of one of a given set of subclass exceptions.

class assembl.views.traversal.JsonLdPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a request really asks for jsonld

class assembl.views.traversal.LocalPermissionPredicate(permission, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is an InstanceContext and the user has a certain local permission on it

class assembl.views.traversal.NSBoundDictContext(ns_kvdict, parent)[source]

Bases: assembl.views.traversal.TraversalContext

Represents the set of namespace-bound K-V items

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.NSKeyBoundDictItemContext(ns_kvdict, parent, key)[source]

Bases: assembl.views.traversal.TraversalContext

Represents a value which is bound to a namespace and key

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.NamedCollectionContextPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is a CollectionContext, whose collection’s AbstractCollectionDefinition.name() is as given.

class assembl.views.traversal.NamedCollectionInstancePredicate(val, config)[source]

Bases: object

A view predicate factory that checks that a given traversal context is an InstanceContext under a CollectionContext whose collection’s AbstractCollectionDefinition.name() is as given.

class assembl.views.traversal.NamespacedDictContext(parent, collection)[source]

Bases: assembl.views.traversal.TraversalContext

Represents the set of namespace-K-V items

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.NsDictCollection(cls)[source]

Bases: assembl.views.traversal.AbstractCollectionDefinition

class assembl.views.traversal.PreferenceContext(parent_context, preferences)[source]

Bases: assembl.views.traversal.TraversalContext

Represents a set of preference values (eg for a discussion)

Sub-contexts are PreferenceValueContext

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.PreferenceValueContext(preferences, parent, key)[source]

Bases: assembl.views.traversal.TraversalContext

Represents a specific discussion preference

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.RelationCollectionDefinition(owner_class, relationship, name=None)[source]

Bases: assembl.views.traversal.AbstractCollectionDefinition

A collection of objects related to an instance through a relationship.

class assembl.views.traversal.SecureConnectionPredicate(val, config)[source]

Bases: object

A view predicate factory that checks that the connection is secure (https).

class assembl.views.traversal.TraversalContext(parent, acl=None)[source]

Bases: assembl.views.traversal.BaseContext

The base class for the magic API

creation_side_effects(inst_ctx=None)[source]

Generator for objects that are created as side-effect of another object’s creation. They can have their own side-effect.

creation_side_effects_rec(inst_ctx, top_ctx)[source]

Recursion

decorate_query(query, ctx, tombstones=False)[source]

Given a SQLAlchemy query, add joins and filters that correspond to this step in the traversal path.

get_target_class()[source]

What is the model class we can expect to find at this context?

on_new_instance(instance)[source]

If a model instance was created in this context, let the context learn about it. Exists mostly for RelationCollectionDefinition.on_new_instance()

class assembl.views.traversal.UserBoundNamespacedDictContext(parent, collection)[source]

Bases: assembl.views.traversal.TraversalContext

Represents the set of user-bound namespace-K-V items

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.UserNSBoundDictContext(user_ns_b_kvdict, parent)[source]

Bases: assembl.views.traversal.TraversalContext

Represents the set of user-bound, namespace-bound K-V items

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.UserNSKeyBoundDictItemContext(user_ns_b_kvdict, parent, key)[source]

Bases: assembl.views.traversal.TraversalContext

Represents a value which is bound to a user, namespace and key

get_target_class()[source]

What is the model class we can expect to find at this context?

class assembl.views.traversal.UserNsDictCollection(cls)[source]

Bases: assembl.views.traversal.AbstractCollectionDefinition

assembl.views.traversal.collection_creation_side_effects(inst_ctx, ctx)[source]

Multiple dispatch adapter for collection-related side effects

assembl.views.traversal.root_factory(request, user_id=None)[source]

The factory function for the root context