edc-navbar


Nameedc-navbar JSON
Version 0.3.32 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-navbar
SummarySimple navbar classes in clinicedc/edc projects
upload_time2024-11-28 03:30:11
maintainerNone
docs_urlNone
authorErik van Widenfelt
requires_python>=3.12
licenseGPL license, see LICENSE
keywords django edc navbar clinicedc clinical trials
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |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``:

.. code-block:: python

    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:

.. code-block:: python

    {% 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``:

.. code-block:: python

    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.

.. code-block:: python

    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:

.. code-block:: python

    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.

.. code-block:: python

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

See also:

* https://github.com/clinicedc/edc-auth
* https://docs.djangoproject.com/en/2.1/topics/auth


.. |pypi| image:: https://img.shields.io/pypi/v/edc-navbar.svg
    :target: https://pypi.python.org/pypi/edc-navbar

.. |actions| image:: https://github.com/clinicedc/edc-navbar/actions/workflows/build.yml/badge.svg
  :target: https://github.com/clinicedc/edc-navbar/actions/workflows/build.yml

.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-navbar/branch/develop/graph/badge.svg
  :target: https://codecov.io/gh/clinicedc/edc-navbar

.. |downloads| image:: https://pepy.tech/badge/edc-navbar
   :target: https://pepy.tech/project/edc-navbar

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clinicedc/edc-navbar",
    "name": "edc-navbar",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "django Edc navbar, clinicedc, clinical trials",
    "author": "Erik van Widenfelt",
    "author_email": "ew2789@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/33/d66fdb9b0d15224c690e1e1b11741439e8bc01a5c704e7a0b98e5ed733d3/edc_navbar-0.3.32.tar.gz",
    "platform": null,
    "description": "|pypi| |actions| |codecov| |downloads|\n\nedc_navbar\n----------\n\nSimple Navbar class for edc\n\nInstallation\n============\n\nInclude ``edc_navbar.apps.AppConfig`` in ``INSTALLED_APPS``.\n\nOveriew\n=======\n\nNavbars are declared in your apps ``navbars.py`` and will be autodiscovered by ``edc_navbar`` and stored in the  site global ``site_navbars``.\n\nBy 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.\n\nFor example, in the \"main\" project app ``urls.py``:\n\n.. code-block:: python\n\n    urlpatterns = [\n        ...\n        path('login', LoginView.as_view(), name='login_url'),\n        path('logout', LogoutView.as_view(\n            pattern_name='login_url'), name='logout_url'),\n        path('admininistration/', AdministrationView.as_view(),\n             name='administration_url'),\n        path('', HomeView.as_view(manual_revision='1.0'), name='home_url'),\n        ...\n        ]\n\nYou 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``.\n\n\nThe default template for ``NavbarItem`` is ``navbar_item.html``. You can declare a custom template on the ``NavbarItem``.\n\n\nRender the Navbar\n=================\n\nFor example, in base.html:\n\n.. code-block:: python\n\n    {% load edc_dashboard_extras %}\n\n    ...\n\n    {% show_edc_navbar %}\n\n    ...\n\nThe rendered html comes from ``edc_navbar.html``\n\n\nDeclaring and registering a navbar\n==================================\n\nA navbar is defined and registered to the site global in the ``navbars.py`` module of each app that needs a navbar.\n\nAn example ``navbars.py``:\n\n.. code-block:: python\n\n    from edc_navbar import NavbarItem, site_navbars, Navbar\n\n    url_namespace = 'edc_pharmacy_dashboard'\n\n    # instantiate a Navbar\n    pharmacy_dashboard = Navbar(name='pharmacy_dashboard')\n\n    # add items to the navbar\n    pharmacy_dashboard.register(\n        NavbarItem(\n            name='prescribe',\n            title='Prescribe',\n            label='prescribe',\n            glyphicon='glyphicon-edit',\n            url_name=f'{url_namespace}:prescribe_listboard_url'))\n\n    pharmacy_dashboard.register(\n        NavbarItem(\n            name='dispense',\n            title='Dispense',\n            label='dispense',\n            glyphicon='glyphicon-share',\n            url_name=f'{url_namespace}:dispense_listboard_url'))\n\n    # register the navbar to the site\n    site_navbars.register(pharmacy_dashboard)\n\nAccessing the navbar in your views\n==================================\n\nNext, add ``NavbarViewMixin`` to your views and set the navbar by name. The navbar will be rendered to string and added to the view context.\n\n.. code-block:: python\n\n    from edc_navbar import NavbarViewMixin\n\n    class HomeView(EdcViewMixin, NavbarViewMixin, TemplateView):\n\n        navbar_name = 'pharmacy_dashboard'\n        navbar_selected_item = 'prescribe'\n\n\nRendering Navbar items\n======================\n\nThe default template for ``NavbarItem`` is ``navbar_item.html``. You can declare a custom template on the ``NavbarItem``.\n\n\nPermissions per NavbarItem\n==========================\n\nEach NavbarItem can declare a Django permissions ``codename``. The codename will be associated with model ``edc_navbar.navbar``.\n\nFor example:\n\n.. code-block:: python\n\n    from edc_navbar import NavbarItem, site_navbars, Navbar\n\n    url_namespace = 'edc_pharmacy_dashboard'\n\n    # instantiate a Navbar\n    pharmacy_dashboard = Navbar(name='pharmacy_dashboard')\n\n    # add items to the navbar\n    pharmacy_dashboard.register(\n        NavbarItem(\n            name='prescribe',\n            title='Prescribe',\n            label='prescribe',\n            glyphicon='glyphicon-edit',\n            permissions_codename='nav_pharmacy_prescribe',\n            url_name=f'{url_namespace}:prescribe_listboard_url'))\n\n    pharmacy_dashboard.register(\n        NavbarItem(\n            name='dispense',\n            title='Dispense',\n            label='dispense',\n            glyphicon='glyphicon-share',\n            permissions_codename='nav_pharmacy_dispense',\n            url_name=f'{url_namespace}:dispense_listboard_url'))\n\n    # register the navbar to the site\n    site_navbars.register(pharmacy_dashboard)\n\nFrom the above, you can reference ``edc_navbar.nav_pharmacy_prescribe`` and ``edc_navbar.nav_pharmacy_dispense`` in your code.\n\n.. code-block:: python\n\n    {% if perms.edc_navbar.nav_pharmacy_dispense %}\n        href=\"some_url\"\n    {% else%}\n        disabled\n    {% endif %}\n\nSee also:\n\n* https://github.com/clinicedc/edc-auth\n* https://docs.djangoproject.com/en/2.1/topics/auth\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/edc-navbar.svg\n    :target: https://pypi.python.org/pypi/edc-navbar\n\n.. |actions| image:: https://github.com/clinicedc/edc-navbar/actions/workflows/build.yml/badge.svg\n  :target: https://github.com/clinicedc/edc-navbar/actions/workflows/build.yml\n\n.. |codecov| image:: https://codecov.io/gh/clinicedc/edc-navbar/branch/develop/graph/badge.svg\n  :target: https://codecov.io/gh/clinicedc/edc-navbar\n\n.. |downloads| image:: https://pepy.tech/badge/edc-navbar\n   :target: https://pepy.tech/project/edc-navbar\n",
    "bugtrack_url": null,
    "license": "GPL license, see LICENSE",
    "summary": "Simple navbar classes in clinicedc/edc projects",
    "version": "0.3.32",
    "project_urls": {
        "Homepage": "https://github.com/clinicedc/edc-navbar"
    },
    "split_keywords": [
        "django edc navbar",
        " clinicedc",
        " clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7d0cc9de93140b61d658510dcb2c725d50137c676444cbd6056eeb7078a6941",
                "md5": "9987f321365bb9c5aa1f021ed92b5557",
                "sha256": "69c6062503148fbcb5f0bfa5a538c3b1909e858fbffeabeecb52dfbb83ff71aa"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.32-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9987f321365bb9c5aa1f021ed92b5557",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 40209,
            "upload_time": "2024-11-28T03:30:09",
            "upload_time_iso_8601": "2024-11-28T03:30:09.735482Z",
            "url": "https://files.pythonhosted.org/packages/a7/d0/cc9de93140b61d658510dcb2c725d50137c676444cbd6056eeb7078a6941/edc_navbar-0.3.32-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e933d66fdb9b0d15224c690e1e1b11741439e8bc01a5c704e7a0b98e5ed733d3",
                "md5": "19269022103302be37e1d80c2a53542d",
                "sha256": "082af6608a2b05da4d34d3ce797105325c366e9bf6f5f48e72ba27c079ca5c56"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.32.tar.gz",
            "has_sig": false,
            "md5_digest": "19269022103302be37e1d80c2a53542d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 37279,
            "upload_time": "2024-11-28T03:30:11",
            "upload_time_iso_8601": "2024-11-28T03:30:11.535577Z",
            "url": "https://files.pythonhosted.org/packages/e9/33/d66fdb9b0d15224c690e1e1b11741439e8bc01a5c704e7a0b98e5ed733d3/edc_navbar-0.3.32.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-28 03:30:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "clinicedc",
    "github_project": "edc-navbar",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "edc-navbar"
}
        
Elapsed time: 0.38140s