Get a datetime object or a int() Epoch timestamp and return a pretty string like ‘an hour ago’, ‘Yesterday’, ‘3 months ago’, ‘just now’, etc
Get a list of all categories. Uses caching for quicker results.
Get a list of recent posts. Uses caching for quicker results.
Pass in the email address and only return the administrator principal if id_ matches the configuration value admin_email
A single blog entry.
id: ID of the entry, used in URLs for instance.
title: The title of the entry, rendered as <h1>-Tag in template.
_text: The raw markdown text. Use Entry.text instead.
entry_time: The the entry was made.
category_name: Primary key of Category and the name of the category this article belongs to.
category: Full access to the associated Category.
A category in the blog.
A simple factory for the ACL/Authorization system.
A decorator to track mutation and propagate it to the database.
The decorator is to be used on all functions that change the value of the Session.additional_data dict. Functions like set or pop need this decorator to ensure the changes are afterwards propagated into the database.
From an implementation point it just sets the complete dictionary as a new value.
Make a mutable dict for SQLAlchemy’s PickleType.
Usage:
class MyModel(Base):
my_data = Column('additional_data',
MutableDict.as_mutable(PickleType))
A session object for pyramid sessions.
Implements the pyramid.interfaces.ISession interface. While it uses a database to store the session, the session id is stored in the cookie. Howevever, under certain conditions the data might be accessed after the request was processed and then the object may be detached from the database session. Thus a caching mechanism is implemented that locally keeps the relevant copies. It tries to fetch values from the database and if a sqlalchemy.orm.exc.DetachedInstanceError occurs, it just returns a default (empty) value.
id: The session id, a 20 byte hex string matching the one stored on the users end in a cookie, e.g. 298f74562fa2c2abfd158725d6e40fdb88cc6503.
created: A unix timestamp of when the cookie was created. The database stores a datetime.datetime object that can be accessed through the internal _created attribute if needed.
csrf_token: On creation a CSRF token is automatically created. This can be used to prevent CSRF attacks (see OWASP for details).
Note
Make sure this is used where needed as it prevents security problems.
additional_data: Don’t access this directy, use the session object itself as a dictionary (as specified by the ISession interface).
message_queue: A list of flash messages of type SessionMessage. Use it as per interface definition.
Note
This does not implement the caching mechanism so lazy loading might be a problem. However, since all messages are eagerly loaded, it should not be a problem.
new: Whether this is a new session.
cache_*: These attributes are cache managed. Don’t access them directly. Ever.
Store configuration for cookie
List of names that are handled dynamically by a cache
Default values for specific attributes to be returned if the session is detached.
Store a given message in the flash queue.
msg: unicode string to be stored as the message.
queue: Optionally a queue name. This may be used to implement a different error queue. By default it is empty ('').
allow_duplicate: Whether the same message is allowed. If set to False, the message will not be added a second time if it is already present.
Invalidate the current session.
Remove the object from the database and delete the cookie on the client side. The actual deletion is done by _set_cookie() with a request callback. Here, only the _delete_cookie value is set to True.
Same as pop_flash() but does not delete elements.
A single message from a specific queue and a specific session.
id: ID of the message. Only needed as primary key
session_id: Foreign key of the session.id column.
message: String with the message to display to the user.
queue: The queue to which the message belongs. Default: ''
Session factory for use in app configuration.
Usage:
from mtc3.models.session import get_session
config = Configurator(session_factory=get_session)
For a secret and a request create a new session and cookie.
secret: A unicode string with the configured secret.
request: The current request.
Calculate a signature in the form of an HMAC for the cookie.
secret: Configured secret for session signature.
session_id: The id of the user’s session.
timestamp: An int denoting the Session.created value.
Retrieve settings from configuration.
Only mandatory setting: session.secret.