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
andTraversalContext.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
-
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.
-
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
-
-
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.
-
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
-
-
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.
-
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 areInstanceContext
, 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.
-
get_collection_class
(typename=None)[source]¶ Returns the collection class, or subclass designated by typename
-
-
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 arePreferenceValueContext
-
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 fromassembl.lib.sqla.Base.extra_collections_dict()
.-
get_discussion_id
()[source]¶ Get the current discussion_id somehow
often from a
DiscussionBoundBase
instance
-
-
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
-
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
-
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’sAbstractCollectionDefinition.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 aCollectionContext
whose collection’sAbstractCollectionDefinition.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
-
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
-
class
assembl.views.traversal.
PreferenceValueContext
(preferences, parent, key)[source]¶ Bases:
assembl.views.traversal.TraversalContext
Represents a specific discussion preference
-
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.
-
-
class
assembl.views.traversal.
UserBoundNamespacedDictContext
(parent, collection)[source]¶ Bases:
assembl.views.traversal.TraversalContext
Represents the set of user-bound namespace-K-V items
-
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
-
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