:py:mod:`core.modules.script` ============================= .. py:module:: core.modules.script Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: core.modules.script.BaseScriptAbstractSkel core.modules.script.ScriptNodeSkel core.modules.script.ScriptLeafSkel core.modules.script.Script Attributes ~~~~~~~~~~ .. autoapisummary:: core.modules.script.DIRECTORY_PATTERN core.modules.script.FILE_PATTERN .. py:data:: DIRECTORY_PATTERN .. py:data:: FILE_PATTERN .. py:class:: BaseScriptAbstractSkel(*args, **kwargs) Bases: :py:obj:`viur.core.prototypes.tree.TreeSkel` This is a container-object holding information about one database entity. It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an :class:`OrderedDict`-Instance, so the definition order of the contained bones remains constant. :ivar key: This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does *not* affect the actual key its stored in. :vartype key: server.bones.BaseBone :ivar creationdate: The date and time where this entity has been created. :vartype creationdate: server.bones.DateBone :ivar changedate: The date and time of the last change to this entity. :vartype changedate: server.bones.DateBone .. py:attribute:: path .. py:method:: fromClient(skel, data, *args, **kwargs) :classmethod: This function works similar to :func:`~viur.core.skeleton.Skeleton.setValues`, except that the values retrieved from *data* are checked against the bones and their validity checks. Even if this function returns False, all bones are guaranteed to be in a valid state. The ones which have been read correctly are set to their valid values; Bones with invalid values are set back to a safe default (None in most cases). So its possible to call :func:`~viur.core.skeleton.Skeleton.toDB` afterwards even if reading data with this function failed (through this might violates the assumed consistency-model). :param skel: The skeleton instance to be filled. :param data: Dictionary from which the data is read. :param amend: Defines whether content of data may be incomplete to amend the skel, which is useful for edit-actions. :returns: True if all data was successfully read and complete. False otherwise (e.g. some required fields where missing or where invalid). .. py:class:: ScriptNodeSkel(*args, **kwargs) Bases: :py:obj:`BaseScriptAbstractSkel` This is a container-object holding information about one database entity. It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an :class:`OrderedDict`-Instance, so the definition order of the contained bones remains constant. :ivar key: This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does *not* affect the actual key its stored in. :vartype key: server.bones.BaseBone :ivar creationdate: The date and time where this entity has been created. :vartype creationdate: server.bones.DateBone :ivar changedate: The date and time of the last change to this entity. :vartype changedate: server.bones.DateBone .. py:attribute:: kindName :value: 'viur-script-node' .. py:attribute:: rootNode .. py:attribute:: plugin .. py:attribute:: name .. py:class:: ScriptLeafSkel(*args, **kwargs) Bases: :py:obj:`BaseScriptAbstractSkel` This is a container-object holding information about one database entity. It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an :class:`OrderedDict`-Instance, so the definition order of the contained bones remains constant. :ivar key: This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does *not* affect the actual key its stored in. :vartype key: server.bones.BaseBone :ivar creationdate: The date and time where this entity has been created. :vartype creationdate: server.bones.DateBone :ivar changedate: The date and time of the last change to this entity. :vartype changedate: server.bones.DateBone .. py:attribute:: kindName :value: 'viur-script-leaf' .. py:attribute:: name .. py:attribute:: script .. py:attribute:: access .. py:class:: Script(moduleName, modulePath, *args, **kwargs) Bases: :py:obj:`viur.core.prototypes.tree.Tree` Tree module prototype. It is used for hierarchical structures, either as a tree with nodes and leafs, or as a hierarchy with nodes only. .. py:attribute:: leafSkelCls .. py:attribute:: nodeSkelCls .. py:attribute:: roles .. py:method:: adminInfo() .. py:method:: getAvailableRootNodes() Default function for providing a list of root node items. This list is requested by several module-internal functions and *must* be overridden by a custom functionality. The default stub for this function returns an empty list. An example implementation could be the following: .. code-block:: python # Example def getAvailableRootNodes(self, *args, **kwargs): q = db.Query(self.rootKindName) ret = [{"key": str(e.key()), "name": e.get("name", str(e.key().id_or_name()))} #FIXME for e in q.run(limit=25)] return ret :param args: Can be used in custom implementations. :param kwargs: Can be used in custom implementations. :return: Returns a list of dicts which must provide a "key" and a "name" entry with respective information. .. py:method:: view(skelType, key, *args, **kwargs) Prepares and renders a single entry for viewing. The entry is fetched by its *key* and its *skelType*. The function performs several access control checks on the requested entity before it is rendered. .. seealso:: :func:`canView`, :func:`onView` :returns: The rendered representation of the requested entity. :param skelType: May either be "node" or "leaf". :param key: URL-safe key of the parent. :raises: :exc:`viur.core.errors.NotAcceptable`, when an incorrect *skelType* is provided. :raises: :exc:`viur.core.errors.NotFound`, when no entry with the given *key* was found. :raises: :exc:`viur.core.errors.Unauthorized`, if the current user does not have the required permissions. .. py:method:: onEdit(skelType, skel) Hook function that is called before editing an entry. It can be overridden for a module-specific behavior. :param skelType: Defines the type of the node that shall be edited. :param skel: The Skeleton that is going to be edited. .. seealso:: :func:`edit`, :func:`onEdited` .. py:method:: onEdited(skelType, skel) Hook function that is called after modifying an entry. It should be overridden for a module-specific behavior. The default is writing a log entry. :param skelType: Defines the type of the node that has been edited. :param skel: The Skeleton that has been modified. .. seealso:: :func:`edit`, :func:`onEdit` .. py:method:: update_path_recursive(skel_type, path, parent_key, cursor=None) Recursively updates all items under a given parent key. .. py:method:: update_path(skel) Updates the path-value of a either a folder or a script file, by resolving the repository's root node.