API

Warning

django-resources is in alpha state. That means everything can be changed.

Classes

class resources.models.Resource(*args, **kwargs)

A registered resource like CSS or Javascript.

Attributes:

path
The path to the resource (without MEDIA_URL).
position
The position of the resource within the merged file (important if one resource is dependend of another).
type
The type of the resource: At the time being: Javascript or CSS.
minify
If True the resource is minified.
media
The media type of the resource. Only used for CSS resources.
get_path()
Returns the full path to the resource.
class resources.models.MergedResource(*args, **kwargs)

A merged resource out of one or more registered Resources.

Attibute:

last_updated
The date the merged resources has been updated.
type
The type of resources which has been merged.
group
The group of resources which has been merged.
filename
The current filename of the merged resource. It is created automatically if one requests the creation of resources.
position
The position of the merged resource. That is the maxmimum position of all merged resources.
get_path()
Returns the full path to the resource.
update(text, position)
Creates a new resources file and sets text and timestamp.

Utils

Registration

resources.utils.register_resource(path, type, merge=True, minify=True, group=None, media=None, position=None)

Registers a resource.

Parameters:

path
The relative path (to MEDIA_URL) to the resource. Must be unique.
type
The type of the resource. One of resources.config.CSS, resources.config.JS
merge
If True the resource will be merged with other resources of the same group.
minify
If True the resource will be minified.
group
The group of the resource. Groups can be merged together and seperately included in the HTML page.
position
The position of the resource within its group. Lower positions come first within HTML.
media
The media type of the resource. This is only valid for CSS sheets.
resources.utils.unregister_resource(path)

Unregisters the resource.

Parameters:

path
The unique path to the resource.

Creation

resources.utils.create_resources()
Creates merged and minified CSS and Javascript of registered resources.
resources.utils.create_css()
Creates merged and minified CSS of registered CSS resources.
resources.utils.create_javascript()
Creates merged and minified javascript of registered Javascript resources.

Miscellaneous

resources.utils.create_directory()
Creates the resources directory.
resources.utils.delete_directory()
Deletes the resources directory with all files inside.
resources.utils.get_groups(type)
Returns list of names of all groups.

Template Tags

resources.templatetags.resources_tags.css(context, group=None)

Returns HTML to embed generated css.

Parameters

group
The group for which the CSS should be displayed.
resources.templatetags.resources_tags.javascript(context, group=None)

Returns HTML to embed generated javascript.

Parameters

group
The group for which the javascript should be displayed.

Settings

RESOURCES_DEBUG
If True registered resources will be displayed individually. If False the resources are merged (as requested). Default is False.

Table Of Contents

Previous topic

Usage

This Page