API

Model

BaseItem

class ringo.model.base.BaseList(clazz, request, user=None, cache='', items=None)
class ringo.model.base.BaseFactory(clazz)
class ringo.model.base.BaseItem

Modul

class ringo.model.modul.ModulItem(**kwargs)

Usermanagement

class ringo.model.user.User(**kwargs)
class ringo.model.user.Usergroup(**kwargs)
class ringo.model.user.Role(**kwargs)
class ringo.model.user.Profile(**kwargs)

News

class ringo.model.news.News(**kwargs)

Appointment

class ringo.model.appointment.Appointment(**kwargs)
class ringo.model.appointment.Reminders(db, cache='')

File

class ringo.model.file.File(**kwargs)

Log

class ringo.model.log.Log(**kwargs)

Tag

class ringo.model.tag.Tag(**kwargs)

Tags (keywords) can be used to mark items.

Todo

class ringo.model.todo.Todo(**kwargs)

Comment

class ringo.model.comment.Comment(**kwargs)

Statemachine

class ringo.model.statemachine.Statemachine(item, item_state_attr, init_state=None, request=None)

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.

__init__(item, item_state_attr, init_state=None, request=None)

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.

setup()

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
get_states()

Returns a list of all states in the statemachine

Returns:List of State objects.
set_state(state)

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

get_state()

Returns the current state of the Statemachine

Returns:Current State
class ringo.model.statemachine.State(statemachine, id, label, description=None, disabled_actions={})

A single state in a statemachine.

__init__(statemachine, id, label, description=None, disabled_actions={})

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’]}

add_transition(to_state, label=None, handler=None, condition=None)

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
get_disabled_actions(role)

Returns a list of disabled actions of the state for the given role

Returns:List of disabled actions
get_transitions()

Returns the available transitions to other states.

Returns:List of Transition objects.
class ringo.model.statemachine.Transition(start_state, end_state, label=None, handler=None, condition=None)

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.

__init__(start_state, end_state, label=None, handler=None, condition=None)

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
get_start()

Returns the start state of the transition

Returns:Start State
get_end()

Returns the end state of the transition

Returns:End State
get_label()

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
exchange()

Do the transition! Exchanges the start state to the end state.

Returns:End State of the transtion.
is_available()

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.

class ringo.model.statemachine.TransitionHandler

Handler callable which will be called if the transition between to State objects has been finished.

class ringo.model.statemachine.TransitionCondition

Condition callable which must be true to make the Transition between two State objects applicable.

Lib

Security

ringo.lib.security.has_permission(permission, context, request)

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)
ringo.lib.security.get_permissions(modul, item=None)

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:

  1. If the role is marked as “administrational” role, then add the permission for role and action.
  2. Elif action is either “list” or “create” (permissons on class level) then add the permission for the role and action.
  3. Elif an item is provided add item level permissions for the role _and_ only the owner or users which are member of the items group.
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
ringo.lib.security.get_principals(userid, request)

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
ringo.lib.security.has_role(user, role)

Return True if the user has the given role. Else False” :user: User instance :returns: True or False

ringo.lib.security.get_roles(user)

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
ringo.lib.security.has_group(user, group)

Return True if the user is in the the given group. Else False” :user: User instance :returns: True or False

Table Of Contents

Previous topic

Development

This Page