Developpers’ documentation


See drink as a tree of items stored in a database. Since the database is structured (a single trunk, then branches, more branches etc... until “leafs”, the children-most items), it is easy to map it as HTTP URLs this way:

In our case, the trunk is “/” and the first “public” branch id is “pages”. This way, most URLs will start with “/pages/”. The final “/” indicates we want to access some item (or object or element, call it whatever you prefer). If there is no final slash at the end of the URL, then it’s a item action or property (ex: view, edit, list, etc... or struct, actions, etc...).

This way, if you add an item called “My Calendar” under “Pages”, the automatically-crafted url will be /pages/my-calendar/, if you want to link directly to its edit form, then use /pages/my-calendar/edit. If you experiment some troubles, you probably made in inconsistant usage of trailing slash.

Database access

Objects can be safely retrieved (with permission checks) using drink.get_object()


All objects inheriting drink.Page should implement a view method with the same prototype as the default function which is drink.default_view().

In case you need a simple but correct handling of unauthorized accesses, it is recommanded to return the value of drink.unauthorized() call in your handler. It will either show an error message or an authentication screen.

Text conversion

In case you have random kind of input (url encoded, latin string, utf-8 str, unicode) and want to ensure you can work with it as unicode data then you may use drink.omni().

To render file sizes as readable strings for humans, just use drink.bytes2human().

Adding upload capabilities

Creating a new uploadable type

First, your page type you contain a properly filled classes property and the user must have permissions to add content to the desired Page.

Then, your object must be registered using drink.add_upload_handler().

API index

Base classes

Page(name[, rootpath]) A dict-like object, defining all properties required by a standard page
ListPage(name[, rootpath])

Base functions & data

make_app([full]) Returns Drink WSGI application
classes dict() -> new empty dictionary
get_object(current, objpath[, no_raise]) Fetch an object from database, looking at permissions to approve
omni(txt) Converts any text form to unicode text
default_view(self[, page, obj, css, js, ...]) Renders the Page as HTML using a template
add_upload_handler(ext, obj_name) Add an opload handler into drink upload system
request A thread-local subclass of BaseRequest.
response A thread-local subclass of BaseResponse.
bytes2human(num) Converts an integer or float value to human-readable string
unauthorized([message, code]) Returns proper value to indicate the user has no access to this ressource
init() Re-initialize drink’s database

Database backends


WSGI Building block

make_app([full]) Returns Drink WSGI application

Properties types

objects.markdown.MarkdownEditor([caption, group])

Builtin object types

generic.WebFile(name[, rootpath])
generic.Settings(name[, rootpath])
markdown.MarkdownPage(name[, rootpath])
tasks.TODO(name, rootpath)
tasks.TODOList(name[, rootpath])
users.User(name, rootpath)
users.UserList(name[, rootpath])
users.Group(name[, rootpath])
users.GroupList(name[, rootpath])
finder.ObjectBrowser(name, rootpath)
filesystem.Filesystem(name, rootpath)
sonic.SonicHome(name[, rootpath])

Project Versions

Table Of Contents

Previous topic


Next topic


This Page