Open source cms for mobile and desktop websites

nive.container

This file provides container functionality for objects and roots. The different components are separated into classes by functionality.

See nive.components.objects.base for subclassing containers.

class nive.container.Container

Container implementation with read access for subobjects used for objects and roots.

Requires: ContainerFactory

obj(id, **kw)

shortcut for GetObj

GetObj(id, **kw)

Get the subobject by id.

id = object id as number
permission = check current users permissions for the page. requires securityContext.
securityContext = required to check the permission. the request object by default.
**kw = load information
returns the object or None

Events: - loadObj(obj)

GetObjs(parameter=None, operators=None, pool_type=None, **kw)

Search for subobjects based on parameter and operators.

parameter = dict. see nive.Search
operators = dict. see nive.Search
kw.sort = sort objects. if None container default sort is used
kw.batch = load subobjects as batch
**kw = see Container.GetObj()
returns all matching subobjects as list

see nive.Search for parameter/operators description

Events - loadObj(obj)

GetObjsList(fields=None, parameter=None, operators=None, pool_type=None, **kw)

Search for subobjects based on parameter and operators. This function performs a sql query based on parameters and does not load any object.

fields = list. see nive.Search
parameter = dict. see nive.Search
operators = dict. see nive.Search
kw.sort = sort objects. if None container default sort is used
kw.batch = load subobjects as batch
returns dictionary list

see nive.Search for parameter/operators description

GetObjsBatch(ids, **kw)

Tries to load the objects with as few sql queries as possible.

ids = list of object ids as number
**kw = see Container.GetObj()
returns all matching sub objects as list

Events - loadObj(objs)

GetContainers(parameter=None, operators=None, **kw)

Loads all subobjects with container functionality. Uses select tag range nive.definitions.StagContainer to nive.definitions.StagRessource - 1.

kw.batch = load subobjects as batch and not as single object
parameter = see pool Search
operators = see pool Search
**kw = see Container.GetObj()
returns all matching sub objects as list

see nive.Search for parameter/operators description

Events - loadObj(objs)

GetContainerList(fields=None, parameter=None, operators=None, **kw)

Lists all subobjects with container functionality. Uses select tag range nive.definitions.StagContainer to nive.definitions.StagRessource - 1. This function performs a sql query based on parameters and does not load any object.

fields = list. see nive.Search
parameter = see pool Search
operators = see pool Search
kw.batch = load subobjects as batch
**kw = see Container.GetObj()
returns dictionary list

see nive.Search for parameter/operators description

GetContainedIDs(sort=None)

Returns the ids of all contained objects including subfolders sorted by sort. Default is GetSort().

returns list

GetSort()

The default sort order field name.

returns the field id as string

IsContainer()
class nive.container.ContainerEdit

Container with add and delete functionality for subobjects.

Requires: Container

Create(type, data, user, **kw)

Creates a new sub object.

type = object type id as string or object configuration
data = dictionary containing data for the new object
user = the currently active user
**kw = version information
returns the new object or None

Keyword options:

  • nocommit: pass nocommit=True to skip a database commit after creation.

Events

  • beforeAdd(data=data, type=type, user=user, kw) called for the container
  • create(user=user, kw) called for the new object
  • afterAdd(obj=obj, user=user, kw) called for the container after object has been committed

Workflow actions

  • add (called in context of the container)
  • create (called in context of the new object)
CreateWithoutEventsAndSecurity(typedef, data, user, **kw)

Creates a new sub object. Unlike Create this function does not trigger any events or workflow actions. Subtype configuration is not validated. Also commit is not called. Can be used to speed up batch creation.

typedef = object type configuration
data = dictionary containing data for the new object
user = the currently active user
**kw = version information
returns the new object or None
Duplicate(obj, user, updateValues=None, **kw)

Duplicate the object including all data and files and store as new subobject.

obj = the object to be duplicated
user = the currently active user
updateValues = dictionary containing meta, data, files
**kw = version information
returns new object or None

Events

  • beforeAdd(data=data, type=type, user=user, kw) called for the container
  • duplicate(kw) called for the new object
  • afterAdd(obj=obj, user=user, kw) called for the container after obj has been committed

Workflow action

  • add (called in context of the container)
  • create (called in context of the new object)
Delete(id, user, obj=None, **kw)

Delete the subobject referenced by id.

id = id of object to be deleted
user = the currently active user
obj = the object to be deleted. Will be loaded automatically if None
**kw = version information
returns True or False

Events

  • delete(user=user) called on object to be deleted
  • afterDelete(id=id, user=user) called on container after object has been deleted

Workflow action

  • remove (called in context of the container)
  • delete (called in context of the new object)
DeleteInternal(id, user, obj=None, **kw)

Like Delete() but does not call any workflow action.

id = id of object to be deleted
user = the currently active user
obj = the object to be deleted. Will be loaded automatically if None
**kw = version information
returns True or False

Events

  • delete() called on object to be deleted
  • afterDelete(id=id) called on container after object has been deleted
class nive.container.ContainerSecurity

Provides functionality to allow or disallow the creation of objects based on object configuration.subtypes.

GetAllowedTypes(user=None, visible=1)

List types allowed to be created in this container based on configuration.subtypes.

user = the currently active user
visible = will skip all hidden object types 
returns list of configurations
IsTypeAllowed(type, user=None)

Check if type is allowed to be created in this container based on configuration.subtypes.:

type = the type to be checked
user = the currently active user
returns True/False

type can be passed as

  • type id string
  • configuration object
  • type object instance
class nive.container.ContainerFactory

Container object factory. Creates objects based on type configuration.

class nive.container.Root(path, app, rootDef)

The root is a container for objects but does not store any data in the database itself. It is the entry point for object access. Roots are only handled by the application.

Requires (Container, ContainerFactory, Event)

dataroot

this will return itself. Used for object compatibility.

app

returns the cms application the root is used for

db

returns the datapool object

parent

this will return None. Used for object compatibility.

LookupObj(id, **kw)

Lookup the object referenced by id anywhere in the tree structure. Use obj() to restrain lookup to the first sublevel only.

id = number
**kw = version information

returns the object or None

ObjQueryRestraints(containerObj=None, parameter=None, operators=None)

The functions returns two dictionaries (parameter, operators) used to restraint object lookup in subtree. For example a restraint can be set to ignore all objects with meta.pool_state=0. All container get (GetObj, GetObjs, ...) functions use query restraints internally.

See nive.search for parameter and operator usage.

Please note: Setting the wrong values for query restraints can easily crash the application.

Event: - loadRestraints(parameter, operators)

returns parameter dict, operators dict

GetID()

returns 0. the root id is always zero.

GetTypeID()

returns the root type id from configuration

GetTypeName()

returns the root type name from configuration

GetFieldConf(fldId)

Get the FieldConf for the field with id = fldId. Looks up data, file and meta fields.

returns FieldConf or None

GetTitle()

returns the root title from configuration.

GetPath()

returns the url path name as string.

IsRoot()

returns always True.

GetParents()

returns empty list. Used for object compatibility.

GetParentIDs()

returns empty list. Used for object compatibility.

GetParentTitles()

returns empty list. Used for object compatibility.

GetParentPaths()

returns empty list. Used for object compatibility.

GetTool(name)

Load a tool in the roots’ context. Only works for tools registered for roots or this root type.

returns the tool object or None

Event - loadToool(tool=toolObj)

Close()

Close the root and all contained objects. Currently only used in combination with caches.

Event - close()

root()

bw 0.9.12: use dataroot property instead! this will return itself. Used for object compatibility.

GetRoot()

bw 0.9.12: to be removed. returns self.

GetApp()

bw 0.9.12: to be removed. returns the cms application.

GetParent()

bw 0.9.12: to be removed. returns None.

class nive.container.RootWorkflow

Provides workflow functionality for roots. Workflow process objects are handled and loaded by the application. Meta layer fields pool_wfp stores the process id and pool_wfa the current state.

WfAllow(action, user, transition=None)

Check if action is allowed in current state in workflow. This functions returns True or False and unlike WFAction() will not raise a WorkflowNotAllowed Exception.

Event: - wfAllow(name)

returns bool

WfAction(action, user, transition=None)

Trigger workflow action. If several transitions are possible for the action in the current state the first is used. In this case the transition id can be passed as parameter.

Event: - wfAction(name)

raises WorkflowNotAllowed

GetWf()

Returns the workflow process for the object.

Event: - wfLoad(workflow)

returns object

GetNewWf()

Returns the workflow process id for the object based on configuration settings.

returns string

GetWfInfo(user)

returns the current workflow state as dictionary

GetWfState()
SetWfState(stateID)

Sets the workflow state for the object. The new is state is set regardless of transitions or calling any workflow actions.

© 2013 Nive GmbH