Sujet précédent

5.1. controllers — Controllers

Sujet suivant

5.1.6. controllers.document — Controllers for documents

Cette page

Autres langues

5.1.5. controllers.base — Base class for controllers

class plmapp.controllers.base.MetaController[source]

Bases: type

Metaclass used to register a controller and get a controller associated to a type (see get_controller()).

See How to add a controller for more explanations.

controllers_dict = {}

dict<type_name(str) : Controller(like PLMObjectController)>

classmethod get_controller(type_name)[source]

Returns the controller (subclass of PLMObjectController) associated to type_name (a string).

For example, get_controller("Part") will return the class PartController.

plmapp.controllers.base.get_controller = <bound method type.get_controller of <class 'plmapp.controllers.base.MetaController'>>

shortcut for MetaController.get_controller()

plmapp.controllers.base.permission_required(func=None, role='owner')[source]

Decorator for methods of PLMObjectController which raises PermissionError if PLMObjectController._user has not the role role

class plmapp.controllers.base.Controller(obj, user, block_mails=False, no_index=False)[source]

Bases: object

Object used to manage a PLMObject and store his modification in a history

Attributes :
object

The PLMObject managed by the controller

_user

User who modifies object

Paramètres:
  • obj (a subinstance of PLMObject) – managed object
  • user (User) – user who modifies obj
HISTORY

alias de AbstractHistory

object
classmethod load(type, reference, revision, user)[source]
save(with_history=True)[source]

Saves object and records its history in the database. If with_history is False, the history is not recorded.

get_verbose_name(attr_name)[source]

Returns a verbose name for attr_name.

Example:

>>> ctrl.get_verbose_name("ctime")
u'date of creation'
update_from_form(form)[source]

Updates object from data of form

Raises :ValueError if form is invalid.
Raises :PermissionError if _user is not the owner of object.
Raises :PermissionError if object is not editable.
check_permission(role, raise_=True)[source]

This method checks if _user has permissions implied by role. For example, role can be owner or notified.

If the check succeeds, True is returned. Otherwise, if raise_ is True (the default), a PermissionError is raised and if raise_ is False, False is returned.

Implementation details

This method keeps a cache, so that you dont have to worry about multiple calls to this method.

clear_permissions_cache()[source]
has_permission(role)[source]
check_contributor(user=None)[source]

This method checks if user is a contributor. If not, it raises PermissionError.

If user is None (the default), _user is used.

check_editable()[source]
block_mails()[source]

Blocks mails sending. Call unblock_mails() to send blocked mails.

unblock_mails()[source]

Unblock mails sending. This sends all previously blocked mails.

histories[source]