A List object of. A list can be filterd, and sorted.
Clazz: | Class of items which will be loaded. |
---|---|
Db: | DB connection used to load the items. |
Cache: | Name of the cache region. If empty then no caching is done. |
Items: | Set items of the Baselist. If provided no items will be |
loaded.
Will return a sorted item list. Sorting is done based on the string version of the value in the sort field.
Field: | Name of the field on which the sort will be done |
---|---|
Order: | If “desc” then the order will be reverted. |
Expand: | If True, then the sorting will be done on the expanded values. |
Returns: | Sorted item list |
This function will set some internal values for the pagination function based on the given params.
Page: | Integer of the current page |
---|---|
Size: | Items per page |
Returns: |
This function will filter the list of items by only leaving those items in the list which match all search criterias in the filter stack. The list will get reduced with every iteration on the filter stack.
For each filter in the stack the function will first look for an optional operator which must be the first word of the search expression. If a operator can be found the search will be done with the given operator. Otherwise the search word will be compiled to the regular expression.
Then all items are iterated. For each item the function will try to match the value of either all, or from the configued search field with the regular expression or configured operator. If the value matches, then the item is kept in the list.
Factory to create of load instances of the clazz.
Clazz: | The clazz of which new items will be created |
---|
Will create a new instance of clazz. The instance is it is not saved persistent at this moment. The method will also take care of setting the correct ownership.
User: | User instance will own the new created item |
---|---|
Returns: | Instance of clazz |
Loads the item with id from the database and returns it.
Id: | ID of the item to be loaded |
---|---|
Db: | DB session to load the item |
Cache: | Name of the cache region. If empty then no caching is done. |
Uuid: | If true the given id is a uuid. Default to false |
Returns: | Instance of clazz |
This function can be used to render a different representation of the item. On default it also returns the simple string representation. Usefull to build some HTML used in links e.g overviews and lists
Return the value of the given attribe of the item. Unlike accessing the raw value through the attribite directly this function will apply all configured transformations to the value before returing it.
Will return a dictionary with the values of the item. If include_relations is true, than the realtion values are included. Else only scalar values are included
Will set the values of the items attributes to the given values in the dictionary. Attributes beginning with “_” are considred private and are ignored.
This function will not handle saving the changed data. This can be by either calling the save method of the item, or automatically at the transactions end if autocommit is enabled.
Please note that setting the values for foreign key attributes might not work as expected. This is especially true for foreign keys to already existing items. You are not able to change a existing relation in the items by changing the foreign key value (You must do this by setting the related item). In this case the value for the foreign key seems to be ignored and replaced by the one of the actual related item. In contrast you can set a new relation by setting the foreign key if this is a new relation.
Values: | Dictionary with values to be set |
---|
Will save the given data into the item. If the current item has no value for the id attribute it is assumed that this item must be added to the database as a new item. In this case you need to provide a dbsession as the new item is not linked to any dbsession yet.
Please note, that you must ensure that the submitted values are validated. This function does no validation on the submitted data.
Data: | Dictionary with key value pairs. |
---|---|
Request: | Current request session. Used when saving new items. |
Returns: | item with new data. |
Returns the clazz defined in the clazzpath attribute
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Will return True if the modul has a ActionItem configured with given url. Else false.
Return a tupel with format str and a list of fields.
Flag to indicate if the action should be available in the bundled actions
Optional. Configure where the action will be displayed. If display is ‘secondary’ the action will be rendererd in the advanced dropdown context menu. Default is ‘primary’
Optional. Configure an alternative permission the user must have to be allowed to call this action. Known values are ‘list’, ‘create’, ‘read’, ‘update’, ‘delete’, ‘import’, ‘export’. If empty the permission system will use the the lowered name of the action.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Return True if the user has the given role. Else False” :user: User instance :include_group_roles: Boolean flag to configure if the roles of the groups the user is member of should be checked too. Defaults to True. :returns: True or False
Returns a list of roles the user has. The list contains Role object and are collected by loading roles directly attached to the user plus optionally roles attached to the groups the user is member of
Include_group_roles: | |
---|---|
Booloan flag to configure if the roles of |
the groups the user is member of should be included in the list. Defaults to True. :returns: List of Role instances
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Returns a list of roles the group has. The list contains Role object and are collected by loading roles directly attached to the group.
Returns: | List of Role instances |
---|
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A Role is used to configure which actions are permitted to users. Therefor each role will have an internal list of modul actions. A user will be allowed to call all actions assigned to the role he is equiped with.
Flag to set the role as administrational role which means that the user will gain the assigned permissions irrespective from checking the ownership
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Textual representation of the user. This will even stay if the origin creator (user) is deleted.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Tags (keywords) can be used to mark items.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in kwargs.
Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
A state machine, is a mathematical model of computation used to design sequential logic circuits for items of a module. It is conceived as an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition.
Initialise the statemachine for the given item.
Item: | Attach the state machine to this BaseItem |
---|---|
Item_state_attr: | |
name of the attribute which store the value of |
the current state of the statemachine in the given item. :init_state: Initialize the statemachine with an alternative state. (Not the value coming from item_state_attr) :request: Current request.
Need to be implemented in the inherited class.
Example:
s1 = State(self, 1, "On")
s2 = State(self, 2, "Off")
s1.add_transition(s2, "Turn on", handler, condition)
s2.add_transition(s1, "Turn off", handler, condition)
return s1
Returns a list of all states in the statemachine
Ignore_checks: | Do not check if a transition is avaible. Return |
---|
all states. :returns: List of State objects.
Will set the current state of the state machine
State: | Id of the State or the State object to |
---|
be set as current state :returns: None
Returns the current state of the Statemachine
Returns: | Current State |
---|
A single state in a statemachine.
Initialise the State
Statemachine: | Statemachine |
---|---|
Id: | Id of the state |
Label: | Label of the Statemachine (short description) |
Description: | Long description of the state. |
Disabled_actions: | |
Dictionary with a list of actions which are |
disabled for a role. {‘rolename’: [‘read’, ‘update’]}
Will add a transtion to the given state
To_state: | End state of the transition |
---|---|
Label: | Label of the transition. Is usually a verb. |
Handler: | TransitionHandler which will be called if the state has been changed |
Condition: | TransitionCondition which must be true to make the transition available |
Returns: | None |
Returns a list of disabled actions of the state for the given role
Returns: | List of disabled actions |
---|
Returns the available transitions to other states.
Ignore_checks: | Do not check if a transition is avaible. Return |
---|
all available transitions. :returns: List of Transition objects.
A transitions is used to switch from one state into another. The two states are called start state and end state where the end state is the state of the state machine after the transtions has been done.
Every transtion can have a handler and a condition. The handler can be used to add some logic which should be trigger after the transition has been finished. The handler is a simple callable which is called with the item of the state machine.
The condition is also a callable and can be used to restrict the availability to whatever want. The function is called with the item of the state machine and returns true or false. If the condition returns true then a transition is available.
Creates a transition between to states.
Start_state: | Start State of the transition |
---|---|
End_state: | End of the transition |
Handler: | TransitionHandler which will be called if the state has been changed |
Condition: | TransitionCondition which must be true to make the transition available |
Returns the start state of the transition
Returns: | Start State |
---|
Returns the end state of the transition
Returns: | End State |
---|
Returns the label of the transtion. If no label was set return the two lables of the start and end state separated with a “->”.
Returns: | Label of the State |
---|
Do the transition! Exchanges the start state to the end state.
Returns: | End State of the transtion. |
---|
Check is the transition is available for the item in the statemachine. The function will call the condition function with the item of the statemachine. It returns true if the state is available (check succeeds) and returns False if the conditions for a state change are not met.
Handler callable which will be called if the transition between to State objects has been finished.
Condition callable which must be true to make the Transition between two State objects applicable.
Wrapper for pyramid’s buitin has_permission function. This wrapper sets dynamically the __acl__ attribute of the given context and then . check if the user has the given permission in the current context using pyramid’s has_permission function.
Context can be: * Instance of BaseItem * Subclass of BaseItem * Ressource, built from a RessourceFactory
If context is an instance or subclass of BaseItem the wrapper will dynamically set the __acl__ attribute. This attribute is used by the pyramid’s has_permission function the check the permission. If the context is a resource the function does nothing as the resource already has the __acl__ attribute set.
If the user has the permission the it returns True, else False (Actually it returns a boolean like object, see pyramids has_permission doc for more details.)
Permission: | String. Name of the permission. E.g list, create, read |
---|---|
Context: | Either Resource, Instance of BaseItem or Subclass of BaseItem |
Request: | current request |
Returns: | True or False (Boolean like object) |
Will return a list permissions attached to the modul and optionally to particular item of the modul. The returned list is suitable for using it as ACL in pyramid’s authorization system. The function will at least return class based permissions. If a item is provided then additional item level permissions are returned.
The function will iterate over all available actions of the given modul and tries to adds a permission entry to the for every role which has granted access to the action.
For every role it will check the following things:
Model: | The modul for which the permissions are returned |
---|---|
Item: | Optional: Item of the model for which the permissons as returned |
Returns: | List of permissions |
Returns a list of pricipals for the user with userid for the given request.
Principals are basically strings naming the groups or roles the user have. Example: role:admin or group:users are typical principals.
Userid: | id of the user |
---|---|
Request: | current request |
Returns: | list with pricipals |
Return True if the user has the given role. Else False” :user: User instance :returns: True or False
Returns a list of roles the user has. The list contains Role object and are collected by loading roles directly attached to the user plus roles attached to the groups the user is member of
User: | User instance |
---|---|
Returns: | List of Role instances |
Return True if the user is in the the given group. Else False” :user: User instance :returns: True or False