kotti.resources¶
The resources
module contains all the classes for Kotti’s
persistence layer, which is based on SQLAlchemy.
Inheritance Diagram¶
- class kotti.resources.ContainerMixin[source]¶
Bases:
MutableMapping
Containers form the API of a Node that’s used for subitem access and in traversal.
- children¶
- Result
all child nodes without considering permissions.
- Return type
list
- children_with_permission(request: Request, permission: str = 'view') List[Node] [source]¶
Return only those children for which the user initiating the request has the asked permission.
- Parameters
request (
kotti.request.Request
) – current requestpermission (str) – The permission for which you want the allowed children
- Result
List of child nodes
- Return type
list
- class kotti.resources.LocalGroup(node, principal_name, group_name)[source]¶
Bases:
Base
Local groups allow the assignment of groups or roles to principals (users or groups) for a certain context (i.e. a
Node
in the content tree).- id¶
Primary key for the node in the DB (
sqlalchemy.types.Integer
)
- node_id¶
ID of the node for this assignment (
sqlalchemy.types.Integer
)
- principal_name¶
Name of the principal (user or group) (
sqlalchemy.types.Unicode
)
- group_name¶
Name of the assigned group or role (
sqlalchemy.types.Unicode
)
- class kotti.resources.Node(name=None, parent=None, title='', annotations=None, **kwargs)[source]¶
Bases:
Base
,ContainerMixin
,PersistentACLMixin
Basic node in the persistance hierarchy.
- id¶
Primary key for the node in the DB (
sqlalchemy.types.Integer
)
- type¶
Lowercase class name of the node instance (
sqlalchemy.types.String
)
- parent_id¶
ID of the node’s parent (
sqlalchemy.types.Integer
)
- position¶
Position of the node within its container / parent (
sqlalchemy.types.Integer
)
- path¶
The path can be used to efficiently filter for child objects (
sqlalchemy.types.Unicode
).
- name¶
Name of the node as used in the URL (
sqlalchemy.types.Unicode
)
- title¶
Title of the node, e.g. as shown in search results (
sqlalchemy.types.Unicode
)
- annotations¶
Annotations can be used to store arbitrary data in a nested dictionary (
kotti.sqla.NestedMustationDict
)
- class kotti.resources.TypeInfo(**kwargs)[source]¶
Bases:
object
TypeInfo instances contain information about the type of a node.
You can pass arbitrary keyword arguments in the constructor, they will become instance attributes. The most common are:
name
title
add_view
addable_to
edit_links
selectable_default_views
uploadable_mimetypes
add_permission
- addable(context: Content, request: Optional[Request]) bool [source]¶
- Parameters
context (Content or subclass thereof (or anything that has a type_info attribute of type
TypeInfo
)) –request (
kotti.request.Request
) – current request
- Result
True if the type described in ‘self’ may be added to ‘context’, False otherwise.
- Return type
Boolean
- add_selectable_default_view(name: str, title: str) None [source]¶
Add a view to the list of default views selectable by the user in the UI.
- Parameters
name (str) – Name the view is registered with
title (str or TranslationString) – Title for the view for display in the UI.
- is_uploadable_mimetype(mimetype: str) int [source]¶
Check if uploads of the given MIME type are allowed.
- Parameters
mimetype (str) – MIME type
- Result
Upload allowed (>0) or forbidden (0). The greater the result, the better is the match. E.g.
image/*
(6) is a better match forimage/png
than * (1).- Return type
int
- class kotti.resources.Tag(**kwargs)[source]¶
Bases:
Base
Basic tag implementation. Instances of this class are just the tag itself and can be mapped to instances of
Content
(or any of its descendants) via instances ofTagsToContents
.- id¶
Primary key column in the DB (
sqlalchemy.types.Integer
)
- title¶
Title of the tag
sqlalchemy.types.Unicode
- class kotti.resources.TagsToContents(**kwargs)[source]¶
Bases:
Base
Tags to contents mapping
- content_id¶
Foreign key referencing
Content.id
(sqlalchemy.types.Integer
)
- tag¶
Relation that adds a
content_tags
sqlalchemy.orm.backref()
toTag
instances to allow easy access to all content tagged with that tag. (sqlalchemy.orm.relationship()
)
- position¶
Ordering position of the tag
sqlalchemy.types.Integer
- class kotti.resources.Content(name=None, parent=None, title='', annotations=None, default_view=None, description='', language=None, owner=None, creation_date=None, modification_date=None, in_navigation=True, tags=None, **kwargs)[source]¶
Bases:
Node
Content adds some attributes to
Node
that are useful for content objects in a CMS.- id¶
Primary key column in the DB (
sqlalchemy.types.Integer
)
- state¶
Workflow state of the content object (
sqlalchemy.types.String
)
- default_view¶
Name of the view that should be displayed to the user when visiting an URL without a explicit view name appended (
sqlalchemy.types.String
)
- description¶
Description of the content object. In default Kotti this is used e.g. in the description tag in the HTML, in the search results and rendered below the title in most views. (
sqlalchemy.types.Unicode
)
- language¶
Language code (ISO 639) of the content object (
sqlalchemy.types.Unicode
)
- owner¶
Owner (username) of the content object (
sqlalchemy.types.Unicode
)
Shall the content be visible in the navigation? (
sqlalchemy.types.Boolean
)
- creation_date¶
Date / time the content was created (
sqlalchemy.types.DateTime
)
- modification_date¶
Date / time the content was last modified (
sqlalchemy.types.DateTime
)
- tags = ObjectAssociationProxyInstance(AssociationProxy('_tags', 'title'))¶
Tags assigned to the content object (list of str)
- annotations¶
Annotations can be used to store arbitrary data in a nested dictionary (
kotti.sqla.NestedMustationDict
)
- name¶
Name of the node as used in the URL (
sqlalchemy.types.Unicode
)
- parent_id¶
ID of the node’s parent (
sqlalchemy.types.Integer
)
- path¶
The path can be used to efficiently filter for child objects (
sqlalchemy.types.Unicode
).
- position¶
Position of the node within its container / parent (
sqlalchemy.types.Integer
)
- title¶
Title of the node, e.g. as shown in search results (
sqlalchemy.types.Unicode
)
- type¶
Lowercase class name of the node instance (
sqlalchemy.types.String
)
- class kotti.resources.Document(body='', mime_type='text/html', **kwargs)[source]¶
Bases:
Content
Document extends
Content
with a body and its mime_type. In addition Document and its descendants implementIDefaultWorkflow
and therefore are associated with the default workflow (at least in unmodified Kotti installations).- id¶
Primary key column in the DB (
sqlalchemy.types.Integer
)
- body¶
Body text of the Document (
sqlalchemy.types.Unicode
)
- mime_type¶
MIME type of the Document (
sqlalchemy.types.String
)
- annotations¶
Annotations can be used to store arbitrary data in a nested dictionary (
kotti.sqla.NestedMustationDict
)
- creation_date¶
Date / time the content was created (
sqlalchemy.types.DateTime
)
- default_view¶
Name of the view that should be displayed to the user when visiting an URL without a explicit view name appended (
sqlalchemy.types.String
)
- description¶
Description of the content object. In default Kotti this is used e.g. in the description tag in the HTML, in the search results and rendered below the title in most views. (
sqlalchemy.types.Unicode
)
Shall the content be visible in the navigation? (
sqlalchemy.types.Boolean
)
- language¶
Language code (ISO 639) of the content object (
sqlalchemy.types.Unicode
)
- modification_date¶
Date / time the content was last modified (
sqlalchemy.types.DateTime
)
- name¶
Name of the node as used in the URL (
sqlalchemy.types.Unicode
)
- owner¶
Owner (username) of the content object (
sqlalchemy.types.Unicode
)
- parent_id¶
ID of the node’s parent (
sqlalchemy.types.Integer
)
- path¶
The path can be used to efficiently filter for child objects (
sqlalchemy.types.Unicode
).
- position¶
Position of the node within its container / parent (
sqlalchemy.types.Integer
)
- state¶
Workflow state of the content object (
sqlalchemy.types.String
)
- title¶
Title of the node, e.g. as shown in search results (
sqlalchemy.types.Unicode
)
- type¶
Lowercase class name of the node instance (
sqlalchemy.types.String
)
- class kotti.resources.SaveDataMixin(data: Optional[Union[bytes, BufferedReader, FieldStorage]] = None, filename: Optional[str] = None, mimetype: Optional[str] = None, size: Optional[int] = None, **kwargs)[source]¶
Bases:
object
The classmethods must not be implemented on a class that inherits from
Base
withSQLAlchemy>=1.0
, otherwise that class cannot be subclassed further.See http://stackoverflow.com/questions/30433960/how-to-use-declare-last-in-sqlalchemy-1-0 # noqa
- classmethod from_field_storage(fs)[source]¶
- Create and return an instance of this class from a file upload
through a webbrowser.
- Parameters
fs (
cgi.FieldStorage
) – FieldStorage instance as found in akotti.request.Request
’sPOST
MultiDict.- Result
The created instance.
- Return type
- filename = Column(None, Unicode(length=100), table=None)¶
The filename is used in the attachment view to give downloads the original filename it had when it was uploaded. (
sqlalchemy.types.Unicode
)
- mimetype = Column(None, String(length=100), table=None)¶
MIME type of the file (
sqlalchemy.types.String
)
- size = Column(None, Integer(), table=None)¶
Size of the file in bytes (
sqlalchemy.types.Integer
)
- class kotti.resources.File(data=None, filename=None, mimetype=None, size=None, **kwargs)[source]¶
Bases:
SaveDataMixin
,Content
File adds some attributes to
Content
that are useful for storing binary data.- annotations¶
Annotations can be used to store arbitrary data in a nested dictionary (
kotti.sqla.NestedMustationDict
)
- creation_date¶
Date / time the content was created (
sqlalchemy.types.DateTime
)
- default_view¶
Name of the view that should be displayed to the user when visiting an URL without a explicit view name appended (
sqlalchemy.types.String
)
- description¶
Description of the content object. In default Kotti this is used e.g. in the description tag in the HTML, in the search results and rendered below the title in most views. (
sqlalchemy.types.Unicode
)
- filename¶
The filename is used in the attachment view to give downloads the original filename it had when it was uploaded. (
sqlalchemy.types.Unicode
)
Shall the content be visible in the navigation? (
sqlalchemy.types.Boolean
)
- language¶
Language code (ISO 639) of the content object (
sqlalchemy.types.Unicode
)
- mimetype¶
MIME type of the file (
sqlalchemy.types.String
)
- modification_date¶
Date / time the content was last modified (
sqlalchemy.types.DateTime
)
- name¶
Name of the node as used in the URL (
sqlalchemy.types.Unicode
)
- owner¶
Owner (username) of the content object (
sqlalchemy.types.Unicode
)
- parent_id¶
ID of the node’s parent (
sqlalchemy.types.Integer
)
- path¶
The path can be used to efficiently filter for child objects (
sqlalchemy.types.Unicode
).
- position¶
Position of the node within its container / parent (
sqlalchemy.types.Integer
)
- size¶
Size of the file in bytes (
sqlalchemy.types.Integer
)
- state¶
Workflow state of the content object (
sqlalchemy.types.String
)
- title¶
Title of the node, e.g. as shown in search results (
sqlalchemy.types.Unicode
)
- type¶
Lowercase class name of the node instance (
sqlalchemy.types.String
)
- id¶
Primary key column in the DB (
sqlalchemy.types.Integer
)
- kotti.resources.get_root(request: Optional[Request] = None) Node [source]¶
- Call the function defined by the
kotti.root_factory
setting and return its result.
- Parameters
request (
kotti.request.Request
) – current request (optional)- Result
a node in the node tree
- Return type
Node
or descendant;
- Call the function defined by the
- class kotti.resources.DefaultRootCache[source]¶
Bases:
object
Default implementation for
get_root()
- root_id¶
Query for the one node without a parent and return its id. :result: The root node’s id. :rtype: int