This app provides app-related features, such as base model and view, a registry and a base class for kii apps, autoregistration of kii apps urls, and menu management.


This module provides two core components for kii:

  • apps, an instance of AppManager, used especialy for

    automatic URL inclusion of kii apps.

  • App, a class that extends django regular django.apps.AppConfig and you should use for building your own kii apps.

class, app_module)[source]

A base class for all kii apps

api_urls = None

See urls for more details: a string containing the path to an URLconf that contains API urls (if any). This URLconf will be included under the kii:api namespace.


Return a prefix for used for URLconf inclusion, such as r'^myapp/'. It must be a raw string, starting with ^ and ending with a trailing slash.

By default, uses the label as the prefix.

Returns:A URL pointing to the app index
Returns:a boolean that indicates if the app is marked as installed by django
kii_app = True

wether the app should be considered as a kii app or not.

menu = None

If you attach a MenuNode instance here, the corresponding menu will be automatically built and included in templates.

App.ready() is a good place for registering your menu.


return a list of models from this app that can be created by any user TODO: is this used ?

Parameters:target (str) – The targeted path
Returns:The full path to the targeted URLconf, for further inclusion in a URL pattern
urls = None

A string containing the path to the app URLconf (if any). This URLconf will then be automatically registered under the kii namespace with AppManager.get_apps_urls().

You can use an absolute path, such as your_app.subpackage.urls or a relative path, like .urls. In the last case, a full path will be built using name.


Provide a cleaner API to django.apps.apps

Returns:An iterable containing all the registered app configs
Returns:an iterable of installed apps that match given filters
Parameters:app_label (str) –
Returns:A django.apps.AppConfig instance corresponding to the given app_abel.

Gather all URLs for kii apps so they can easily be included in a URLconf.

Returns:A list of django url patterns
Returns:An iterable containing all registered django apps marked that are also kii apps



Describe a menu element, and may be attached to an App instance (via the menu attribute) for automatic inclusion in templates.

  • route (str) – Either a relative URL, absolute URL or a django URL name, such as kii:myapp:index. Defaults to #.
  • reverse (bool) – Wether the given route should be reversed using django’s reverse() or returned ‘as is’. Defaults to True.
  • parent – TODO, seems useless
  • weight (int) – Indicate the importance of the node. Higher is more important, default to 0.
  • require_authentication (bool) – Used to determine if the node should be shown to unauthenticated users. Defaults to True.
  • reverse_kwargs (list) – A list of strings that the route will accept when reversing. Defaults to []
  • children (list) – A list of children MenuNode instances that will be considered as submenus of this instance. Defaults to [].
  • icon – TODO, seems useless.

list of weak references to the object (if defined)


Add a new node to the instance children and sort them by weight.

Parameters:item – A menu node instance
Parameters:kwargs – a dictionary of values that will be used for reversing, if the corresponding key is present in self.reverse_kwargs
Returns:The target URL of the node, after reversing (if needed)


class*args, **kwargs)[source]

A base class for all apps related models. It implements URL reversing for model instances, so one can do:

instance = MyModel.objects.get(pk=42)
assert instance.reverse_update() == "/kii/myapp/mymodel/42/update"
classmethod class_reverse(suffix)[source]

Same as reverse but callable from class instead of instances. :return: a reversed URL for the model

Returns:The absolute URL of the instance, which is equal to self.reverse_detail() by default
public_model = False

: If True, any authenticated user will be able to create isntances of this model TODO : is it useful ?

reverse(suffix, **kwargs)[source]

Get a model-instance relative URL, such as a detail, delete or update URL. You can override per-suffix URLs by defining reverse_<suffix> methods on the model class.

  • suffix (str) – a string that will be used to find the corresponding reverse method on the model class (if any)
  • kwargs (dict) – optional URL kwargs that will be passed to the reverse function

a reversed URL

Returns:The delete URL of the instance
Returns:The detail URL of the instance
Returns:The update URL of the instance
Parameters:user_area (bool) – whether the URL namespace should include the username part
Returns:a string representing the URL namespace of the model, such as kii:myapp:mymodel:

Template tags, suffix, **kwargs)[source]

Return a model-related URL. Usage:

{% load app_tags %}

{% model_url my_object "delete" as url %}
{% if url %}
    {{ url }}
{% endif %}

Will ouptut something like /myapp/mymodel/12/delete if the URL exists.

Model can be an instance or a Model subclass.

This tag will fail silently if the URL is not foun and return an empty string., **kwargs)[source]

Typical usage (look at kii/glue/templates/default/glue/menu_node.html for a real example):

{% load app_tags %}

{% with %}

    {% node_url node as url %}
    <a href="{{ url }}">My app root menu node</a>

    {% for child_node in node.children %}

        {% node_url child_node as child_url %}
        <a href="{{ child_url }}">A child node</a>

    {% endfor %}
{% endwith %}
  • node – a instance
  • kwargs – kwargs that will be passed to the reverse() function

the target URL of the menu node



Add extra method and context to all apps views

dispatch(request, *args, **kwargs)[source]

Set up some hooks before calling the actual dispatch method

Returns:a list of breadcrumb elements , such as (('Delete' '/delete'), ('My model', None), ('My app', None)) for use in templates. The first item of each tuple is the title of the element, the second is the URL. URL can be None.

Add the current app, the page title, the breadcrumbs and the root URL of kii to context


Override this method if you want to return a custom title for the page. :return: A page title, as a string

page_title = ''

a page title that will be display in templates and <title> tags

pre_dispatch(request, *args, **kwargs)[source]

Called just after setup(). If you return anything but None, the view will stop and return the returned value.

This method is convenient for checking a permission, for example.

setup(request, *args, **kwargs)[source]

Called at the beginning of dispatch(), you can extend this method if you need to set some variables for later use