edc-navbar


Nameedc-navbar JSON
Version 0.3.30 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-navbar
SummarySimple navbar classes in clinicedc/edc projects
upload_time2024-11-20 22:39:10
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/1d/29/e6d90f334f4cd70157ad45eb2c0eecca5f0329f07a3a6c75ceed65f1d2cd/edc_navbar-0.3.30.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.30",
    "project_urls": {
        "Homepage": "https://github.com/clinicedc/edc-navbar"
    },
    "split_keywords": [
        "django edc navbar",
        " clinicedc",
        " clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c106b7eae02f0bfdf038557f71175b54f76e0d6ca4c9dcee5884b5f3a8a7a9f",
                "md5": "e10a1237e0cd02b9b152595e55d1bd90",
                "sha256": "16fd210deb8e1f56f9093b15d04230ade4028ce71406f46def16142ef8d06a13"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e10a1237e0cd02b9b152595e55d1bd90",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 40234,
            "upload_time": "2024-11-20T22:39:08",
            "upload_time_iso_8601": "2024-11-20T22:39:08.837668Z",
            "url": "https://files.pythonhosted.org/packages/3c/10/6b7eae02f0bfdf038557f71175b54f76e0d6ca4c9dcee5884b5f3a8a7a9f/edc_navbar-0.3.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1d29e6d90f334f4cd70157ad45eb2c0eecca5f0329f07a3a6c75ceed65f1d2cd",
                "md5": "a864cf9a19b1829bd97d47dc3358e51e",
                "sha256": "8dcc1ff76dd6337317953c7cd5b9e9dbea92cec3dfc927ac46ce44f38a78f8f6"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.30.tar.gz",
            "has_sig": false,
            "md5_digest": "a864cf9a19b1829bd97d47dc3358e51e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 37254,
            "upload_time": "2024-11-20T22:39:10",
            "upload_time_iso_8601": "2024-11-20T22:39:10.644048Z",
            "url": "https://files.pythonhosted.org/packages/1d/29/e6d90f334f4cd70157ad45eb2c0eecca5f0329f07a3a6c75ceed65f1d2cd/edc_navbar-0.3.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-20 22:39:10",
    "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.46883s