Skip to main content

Simple navbar classes in clinicedc/edc projects

Project description

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:

urlpatterns = [
    ...
    path('login', LoginView.as_view(), name='login_url'),
    path('logout', LogoutView.as_view(
        pattern_name='login_url'), name='logout_url'),
    path('admininistration/', AdministrationView.as_view(),
         name='administration_url'),
    path('', HomeView.as_view(manual_revision='1.0'), name='home_url'),
    ...
    ]

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:

{% load edc_dashboard_extras %}

...

{% show_edc_navbar %}

...

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:

from edc_navbar import NavbarItem, site_navbars, Navbar

url_namespace = 'edc_pharmacy_dashboard'

# instantiate a Navbar
pharmacy_dashboard = Navbar(name='pharmacy_dashboard')

# add items to the navbar
pharmacy_dashboard.register(
    NavbarItem(
        name='prescribe',
        title='Prescribe',
        label='prescribe',
        glyphicon='glyphicon-edit',
        url_name=f'{url_namespace}:prescribe_listboard_url'))

pharmacy_dashboard.register(
    NavbarItem(
        name='dispense',
        title='Dispense',
        label='dispense',
        glyphicon='glyphicon-share',
        url_name=f'{url_namespace}:dispense_listboard_url'))

# register the navbar to the site
site_navbars.register(pharmacy_dashboard)

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.

from edc_navbar import NavbarViewMixin

class HomeView(EdcViewMixin, NavbarViewMixin, TemplateView):

    navbar_name = 'pharmacy_dashboard'
    navbar_selected_item = 'prescribe'

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 edc_navbar import NavbarItem, site_navbars, Navbar

url_namespace = 'edc_pharmacy_dashboard'

# instantiate a Navbar
pharmacy_dashboard = Navbar(name='pharmacy_dashboard')

# add items to the navbar
pharmacy_dashboard.register(
    NavbarItem(
        name='prescribe',
        title='Prescribe',
        label='prescribe',
        glyphicon='glyphicon-edit',
        permissions_codename='nav_pharmacy_prescribe',
        url_name=f'{url_namespace}:prescribe_listboard_url'))

pharmacy_dashboard.register(
    NavbarItem(
        name='dispense',
        title='Dispense',
        label='dispense',
        glyphicon='glyphicon-share',
        permissions_codename='nav_pharmacy_dispense',
        url_name=f'{url_namespace}:dispense_listboard_url'))

# register the navbar to the site
site_navbars.register(pharmacy_dashboard)

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

{% if perms.edc_navbar.nav_pharmacy_dispense %}
    href="some_url"
{% else%}
    disabled
{% endif %}

See also:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edc_navbar-0.3.29.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

edc_navbar-0.3.29-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file edc_navbar-0.3.29.tar.gz.

File metadata

  • Download URL: edc_navbar-0.3.29.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for edc_navbar-0.3.29.tar.gz
Algorithm Hash digest
SHA256 b49cc3f423a06b1bb86a86f164f778c5b00f660e4d3d6636833f8e387ae1dc8f
MD5 60b3e95d26859aa37d3ad49dfa74f23a
BLAKE2b-256 83e1f78ca22b36e916fb2b04533c8df76667924a04bb68219a4cb863b4811706

See more details on using hashes here.

File details

Details for the file edc_navbar-0.3.29-py3-none-any.whl.

File metadata

  • Download URL: edc_navbar-0.3.29-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for edc_navbar-0.3.29-py3-none-any.whl
Algorithm Hash digest
SHA256 fed7c0943871e46a15a38be29a041ac63bdb9d85252274ef40a56611aa6c6ce1
MD5 962dafb49f88eb8013fcacebc0a4d336
BLAKE2b-256 c4502853f47b345be7e7391feda5d6c2271a0f0a83d9d0fb0430c56a17e95bf2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page