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 kii.app.core.App(app_name, app_module)¶
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.
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.
- class kii.app.core.AppManager¶
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
- class kii.app.models.AppModel(*args, **kwargs)¶
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)¶
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)¶
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:
- class kii.app.views.AppMixin¶
Add extra method and context to all apps views
- dispatch(request, *args, **kwargs)¶
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)¶
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.