kotti.resources¶
The resources module contains all the classes for Kotti’s persistance layer, which is based on SQLAlchemy.
Inheritance Diagram¶
- class kotti.resources.ContainerMixin[source]¶
Bases: object, UserDict.DictMixin
Containers form the API of a Node that’s used for subitem access and in traversal.
- children_with_permission(request, permission='view')[source]¶
Return only those children for which the user initiating the request has the asked permission.
Parameters: - request (pyramid.request.Request) – current request
- permission (str) – The permission for which you want the allowed children
Result: List of child nodes
Return type: list
- class kotti.resources.Content(name=None, parent=None, title=u'', annotations=None, default_view=None, description=u'', language=None, owner=None, creation_date=None, modification_date=None, in_navigation=True, tags=None, **kwargs)[source]¶
Bases: kotti.resources.Node
Content adds some attributes to Node that are useful for content objects in a CMS.
- 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)
- id¶
Primary key column in the DB (sqlalchemy.types.Integer)
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)
- owner¶
Owner (username) of the content object (sqlalchemy.types.Unicode)
- state¶
Workflow state of the content object (sqlalchemy.types.String)
Tags assigned to the content object (list of str)
- class kotti.resources.Document(body=u'', mime_type='text/html', **kwargs)[source]¶
Bases: kotti.resources.Content
Document extends Content with a body and its mime_type. In addition Document and its descendants implement IDefaultWorkflow and therefore are associated with the default workflow (at least in unmodified Kotti installations).
- body¶
Body text of the Document (sqlalchemy.types.Unicode)
- id¶
Primary key column in the DB (sqlalchemy.types.Integer)
- mime_type¶
MIME type of the Document (sqlalchemy.types.String)
- class kotti.resources.File(data=None, filename=None, mimetype=None, size=None, **kwargs)[source]¶
Bases: kotti.resources.Content
File adds some attributes to Content that are useful for storing binary data.
- filename¶
The filename is used in the attachment view to give downloads the original filename it had when it was uploaded. (sqlalchemy.types.Unicode)
- 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 a pyramid.request.Request‘s POST MultiDict. Result: The created instance. Return type: kotti.resources.File
- id¶
Primary key column in the DB (sqlalchemy.types.Integer)
- mimetype¶
MIME type of the file (sqlalchemy.types.String)
- size¶
Size of the file in bytes (sqlalchemy.types.Integer)
- class kotti.resources.Image(data=None, filename=None, mimetype=None, size=None, **kwargs)[source]¶
Bases: kotti.resources.File
Image doesn’t add anything to File, but images have different views, that e.g. support on the fly scaling.
- class kotti.resources.Node(name=None, parent=None, title=u'', annotations=None, **kwargs)[source]¶
Bases: sqlalchemy.ext.declarative.api.Base, kotti.resources.ContainerMixin, kotti.security.PersistentACLMixin
Basic node in the persistance hierarchy.
- annotations¶
Annotations can be used to store arbitray data in a nested dictionary (kotti.sqla.NestedMustationDict)
- id¶
Primary key for the node in the DB (sqlalchemy.types.Integer)
- 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). Its set to a length of 767 by default because MySQL doesn’t allow indexes on columns that are larger than 767 bytes (by default).
- position¶
Position of the node within its container / parent (sqlalchemy.types.Integer)
- title¶
Title of the node, e.g. as shown in serach results (sqlalchemy.types.Unicode)
- type¶
Lowercase class name of the node instance (sqlalchemy.types.String)
- class kotti.resources.Tag(**kwargs)[source]¶
Bases: sqlalchemy.ext.declarative.api.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 of TagsToContents.
- 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: sqlalchemy.ext.declarative.api.Base
Tags to contents mapping
- content_id¶
Foreign key referencing Content.id (sqlalchemy.types.Integer)
- position¶
Ordering position of the tag sqlalchemy.types.Integer
- tag¶
Relation that adds a content_tags sqlalchemy.orm.backref() to Tag instances to allow easy access to all content tagged with that tag. (sqlalchemy.orm.relationship())
- tag_id¶
Foreign key referencing Tag.id (sqlalchemy.types.Integer)
- 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_selectable_default_view(name, title)[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 (unicode or TranslationString) – Title for the view for display in the UI.
- addable(context, request)[source]¶
Parameters: - context (Content or subclass thereof (or anything that has a type_info attribute of type TypeInfo)) –
- request (pyramid.request.Request) – current request
Result: True if the type described in ‘self’ may be added to ‘context’, False otherwise.
Return type: Boolean
- is_uploadable_mimetype(mimetype)[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 for image/png than * (1). Return type: int
- kotti.resources.and_(*clauses)¶
Produce a conjunction of expressions joined by AND.
E.g.:
from sqlalchemy import and_ stmt = select([users_table]).where( and_( users_table.c.name == 'wendy', users_table.c.enrolled == True ) )
The and_() conjunction is also available using the Python & operator (though note that compound expressions need to be parenthesized in order to function with Python operator precedence behavior):
stmt = select([users_table]).where( (users_table.c.name == 'wendy') & (users_table.c.enrolled == True) )
The and_() operation is also implicit in some cases; the Select.where() method for example can be invoked multiple times against a statement, which will have the effect of each clause being combined using and_():
stmt = select([users_table]).\ where(users_table.c.name == 'wendy').\ where(users_table.c.enrolled == True)
See also
- kotti.resources.default_get_root(request=None)[source]¶
Default implementation for get_root().
Parameters: request (pyramid.request.Request) – Current request (optional) Result: Node in the object tree that has no parent. Return type: Node or descendant; in a fresh Kotti site with Kotti’s default populator this will be an instance of Document.
- kotti.resources.get_root(request=None)[source]¶
- Call the function defined by the kotti.root_factory setting and
- return its result.
Parameters: request (pyramid.request.Request) – current request (optional) Result: a node in the node tree Return type: Node or descendant;
- kotti.resources.migrate_blobs(from_db=False, to_db=False)[source]¶
Perform migration of BLOBs between different storage providers.
Parameters: - from_db (bool) – Perform a BLOB migration from the DB to another provider
- to_db (bool) – Perform a BLOB migration from another provider to the DB
- kotti.resources.select(columns=None, whereclause=None, from_obj=None, distinct=False, having=None, correlate=True, prefixes=None, **kwargs)¶
Construct a new Select.
Similar functionality is also available via the FromClause.select() method on any FromClause.
All arguments which accept ClauseElement arguments also accept string arguments, which will be converted as appropriate into either text() or literal_column() constructs.
Parameters: - columns –
A list of ClauseElement objects, typically ColumnElement objects or subclasses, which will form the columns clause of the resulting statement. For all members which are instances of Selectable, the individual ColumnElement members of the Selectable will be added individually to the columns clause. For example, specifying a Table instance will result in all the contained Column objects within to be added to the columns clause.
This argument is not present on the form of select() available on Table.
- whereclause – A ClauseElement expression which will be used to form the WHERE clause.
- from_obj – A list of ClauseElement objects which will be added to the FROM clause of the resulting statement. Note that “from” objects are automatically located within the columns and whereclause ClauseElements. Use this parameter to explicitly specify “from” objects which are not automatically locatable. This could include Table objects that aren’t otherwise present, or Join objects whose presence will supercede that of the Table objects already located in the other clauses.
- autocommit – Deprecated. Use .execution_options(autocommit=<True|False>) to set the autocommit option.
- bind=None – an Engine or Connection instance to which the resulting Select object will be bound. The Select object will otherwise automatically bind to whatever Connectable instances can be located within its contained ClauseElement members.
- correlate=True – indicates that this Select object should have its contained FromClause elements “correlated” to an enclosing Select object. This means that any ClauseElement instance within the “froms” collection of this Select which is also present in the “froms” collection of an enclosing select will not be rendered in the FROM clause of this select statement.
- distinct=False –
when True, applies a DISTINCT qualifier to the columns clause of the resulting statement.
The boolean argument may also be a column expression or list of column expressions - this is a special calling form which is understood by the Postgresql dialect to render the DISTINCT ON (<columns>) syntax.
distinct is also available via the distinct() generative method.
- for_update=False – when True, applies FOR UPDATE to the end of the resulting statement.
Deprecated since version 0.9.0: - use GenerativeSelect.with_for_update() to specify the structure of the FOR UPDATE clause.
for_update accepts various string values interpreted by specific backends, including:
- "read" - on MySQL, translates to LOCK IN SHARE MODE; on Postgresql, translates to FOR SHARE.
- "nowait" - on Postgresql and Oracle, translates to FOR UPDATE NOWAIT.
- "read_nowait" - on Postgresql, translates to FOR SHARE NOWAIT.
See also
GenerativeSelect.with_for_update() - improved API for specifying the FOR UPDATE clause.
- group_by – a list of ClauseElement objects which will comprise the GROUP BY clause of the resulting select.
- having – a ClauseElement that will comprise the HAVING clause of the resulting select when GROUP BY is used.
- limit=None – a numerical value which usually compiles to a LIMIT expression in the resulting select. Databases that don’t support LIMIT will attempt to provide similar functionality.
- offset=None – a numeric value which usually compiles to an OFFSET expression in the resulting select. Databases that don’t support OFFSET will attempt to provide similar functionality.
- order_by – a scalar or list of ClauseElement objects which will comprise the ORDER BY clause of the resulting select.
- use_labels=False –
when True, the statement will be generated using labels for each column in the columns clause, which qualify each column with its parent table’s (or aliases) name so that name conflicts between columns in different tables don’t occur. The format of the label is <tablename>_<column>. The “c” collection of the resulting Select object will use these names as well for targeting column members.
use_labels is also available via the apply_labels() generative method.
- columns –