edc-navbar


Nameedc-navbar JSON
Version 0.3.27 PyPI version JSON
download
home_pagehttps://github.com/clinicedc/edc-navbar
SummarySimple navbar classes in clinicedc/edc projects
upload_time2024-03-12 03:35:58
maintainer
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": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "django Edc navbar,clinicedc,clinical trials",
    "author": "Erik van Widenfelt",
    "author_email": "ew2789@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/58/69/f02b4c5b59e9eb2509a640498239a029744f80d4a25bfc4b3a2ad34de9bb/edc-navbar-0.3.27.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.27",
    "project_urls": {
        "Homepage": "https://github.com/clinicedc/edc-navbar"
    },
    "split_keywords": [
        "django edc navbar",
        "clinicedc",
        "clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be7813b1e89db0fce1708d86012db0aa9ed84098b0230aba8e7f4c255ea39fd7",
                "md5": "3f553753483986343b30461546e1650d",
                "sha256": "d149264f91af021a7fc063db2d8c1d68ed7c8f06479b2f85723a2104cb30087f"
            },
            "downloads": -1,
            "filename": "edc_navbar-0.3.27-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f553753483986343b30461546e1650d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 40139,
            "upload_time": "2024-03-12T03:35:56",
            "upload_time_iso_8601": "2024-03-12T03:35:56.569823Z",
            "url": "https://files.pythonhosted.org/packages/be/78/13b1e89db0fce1708d86012db0aa9ed84098b0230aba8e7f4c255ea39fd7/edc_navbar-0.3.27-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5869f02b4c5b59e9eb2509a640498239a029744f80d4a25bfc4b3a2ad34de9bb",
                "md5": "353a0fd99cc8aab14561f1cbdc7126ea",
                "sha256": "88f46d959efb148e9cbb8cd7ff8241e12c763006e08f7165abd2fd18a4ca268b"
            },
            "downloads": -1,
            "filename": "edc-navbar-0.3.27.tar.gz",
            "has_sig": false,
            "md5_digest": "353a0fd99cc8aab14561f1cbdc7126ea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 37062,
            "upload_time": "2024-03-12T03:35:58",
            "upload_time_iso_8601": "2024-03-12T03:35:58.788614Z",
            "url": "https://files.pythonhosted.org/packages/58/69/f02b4c5b59e9eb2509a640498239a029744f80d4a25bfc4b3a2ad34de9bb/edc-navbar-0.3.27.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 03:35:58",
    "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.20843s