Simple navbar classes in clinicedc/edc projects


Keywords
django, Edc, navbar, clinicedc, clinical, trials, clinical-trial-management-system
Licenses
xpp/MIT-feh
Install
pip install edc-navbar==0.3.28

Documentation

pypi actions codecov downloads

edc_navbar

Simple Navbar class for edc

Installation

Include edc_navbar.apps.AppConfig in INSTALLED_APPS.

Overiew

Navbars are declared in your apps navbars.py and will be autodiscovered by edc_navbar and stored in the site global site_navbars.

By default, a basic navbar is added to the site global. For it to load you need to define the named urls for home_url, administration_url and logout_url in your main project urls.py. The named urls defined in the default navbar do not include a namespace.

For example, in the "main" project app urls.py:

You can change the default navbar to another navbar by setting settings.DEFAULT_NAVBAR to the name of your custom navbar. You will need to declare and register your custom navbar manually. See edc_navbar.navbars.

The default template for NavbarItem is navbar_item.html. You can declare a custom template on the NavbarItem.

Render the Navbar

For example, in base.html:

The rendered html comes from edc_navbar.html

Declaring and registering a navbar

A navbar is defined and registered to the site global in the navbars.py module of each app that needs a navbar.

An example navbars.py:

Accessing the navbar in your views

Next, add NavbarViewMixin to your views and set the navbar by name. The navbar will be rendered to string and added to the view context.

Rendering Navbar items

The default template for NavbarItem is navbar_item.html. You can declare a custom template on the NavbarItem.

Permissions per NavbarItem

Each NavbarItem can declare a Django permissions codename. The codename will be associated with model edc_navbar.navbar.

For example:

From the above, you can reference edc_navbar.nav_pharmacy_prescribe and edc_navbar.nav_pharmacy_dispense in your code.

See also: