menu

Modules

Frontend module is the extension of Django application config.

API

class material.frontend.apps.ModuleMixin

Extension for the django AppConfig. Makes django app pluggable at runtime.

The application have to have <app_module>/urls.py file, with a single no-parametrized url with name=’index’, ex:

urlpatterns = [
    path('', generic.TemplateView.as_view(template_name="sales/index.html"), name="index"),
]

All AppConfigs urls will be included into material.frontend.urls automatically under /<app_label>/ prefix The AppConfig.label, used for the urls namespace.

The menu.html sample:

<ul>
    <li><a href="{% url 'sales:index' %}">Dashboard</a></li>
    <li><a href="{% url 'sales:customers' %}">Customers</a></li>
    {% if perms.sales.can_add_lead %}<li><a href="{% url 'sales:leads' %}">Leads</a></li>{% endif %}
</ul>

In all application templates, the current application config instance would be available as current_module template variable

Parameters
  • order – The relative module order priority. Modules in the site menu would be listed according its priorities.

  • icon – The module icon.

Example:

class Sales(ModuleMixin, AppConfig):
    name = 'sales'
    icon = '<i class="material-icons">call</i>'
base_template()

Base template for a module.

If <app_label>/base_module.html exists it would be used. The default is ‘material/frontend/base_module.html’

Intended to use in modules generic templates. Ex:

{% extends current_module.base_template %}
description()

Module description.

By default taken from the module docstring.

has_perm(user)

Check is user have permission to access to the module.

index_url()

Entry url for a module.

property installed

Check the module installation state.

Default implementation store installed state in the database frontend_dbmodule table.

menu()

Load module menu template.

Template should be located in <app_label>/menu.html

If no template exists, no exception raised.

Intended to use with {% include %} template tag:

{% include module.menu %}
property urls

Module url config.

By default it would be loaded from ‘<app>/urls.py’

property verbose_name

Module name.