edc-navbar


Nameedc-navbar JSON
Version 0.3.29 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-navbar
SummarySimple navbar classes in clinicedc/edc projects
upload_time2024-08-23 16:50:19
maintainerNone
docs_urlNone
authorErik van Widenfelt
requires_python>=3.11
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.11",
    "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/83/e1/f78ca22b36e916fb2b04533c8df76667924a04bb68219a4cb863b4811706/edc_navbar-0.3.29.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\n",
    "bugtrack_url": null,
    "license": "GPL license, see LICENSE",
    "summary": "Simple navbar classes in clinicedc/edc projects",
    "version": "0.3.29",
    "project_urls": {
        "Homepage": "https://github.com/clinicedc/edc-navbar"
    },
    "split_keywords": [
        "django edc navbar",
        " clinicedc",
        " clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4502853f47b345be7e7391feda5d6c2271a0f0a83d9d0fb0430c56a17e95bf2",
                "md5": "962dafb49f88eb8013fcacebc0a4d336",
                "sha256": "fed7c0943871e46a15a38be29a041ac63bdb9d85252274ef40a56611aa6c6ce1"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.29-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "962dafb49f88eb8013fcacebc0a4d336",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 40318,
            "upload_time": "2024-08-23T16:50:18",
            "upload_time_iso_8601": "2024-08-23T16:50:18.490882Z",
            "url": "https://files.pythonhosted.org/packages/c4/50/2853f47b345be7e7391feda5d6c2271a0f0a83d9d0fb0430c56a17e95bf2/edc_navbar-0.3.29-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83e1f78ca22b36e916fb2b04533c8df76667924a04bb68219a4cb863b4811706",
                "md5": "60b3e95d26859aa37d3ad49dfa74f23a",
                "sha256": "b49cc3f423a06b1bb86a86f164f778c5b00f660e4d3d6636833f8e387ae1dc8f"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.29.tar.gz",
            "has_sig": false,
            "md5_digest": "60b3e95d26859aa37d3ad49dfa74f23a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 37237,
            "upload_time": "2024-08-23T16:50:19",
            "upload_time_iso_8601": "2024-08-23T16:50:19.597618Z",
            "url": "https://files.pythonhosted.org/packages/83/e1/f78ca22b36e916fb2b04533c8df76667924a04bb68219a4cb863b4811706/edc_navbar-0.3.29.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-23 16:50:19",
    "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.31981s