django-decorator-include


Namedjango-decorator-include JSON
Version 3.2 PyPI version JSON
download
home_pagehttps://github.com/twidi/django-decorator-include
SummaryInclude Django URL patterns with decorators
upload_time2024-10-21 06:35:30
maintainerNone
docs_urlNone
authorJeff Kistler
requires_python>=3.6
licenseBSD
keywords django urls
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            django-decorator-include
========================

Include Django URL patterns with decorators.

Maintained by Steve Mapes, Stéphane "Twidi" Angel, and Jon Dufresne on
https://github.com/twidi/django-decorator-include
based on the original work from Jeff Kistler on
https://github.com/jeffkistler/django-decorator-include.

.. image:: https://img.shields.io/pypi/v/django-decorator-include.svg
    :target: https://pypi.org/project/django-decorator-include/

.. image:: https://github.com/twidi/django-decorator-include/workflows/build/badge.svg
    :target: https://github.com/twidi/django-decorator-include/actions?query=workflow%3Abuild

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/twidi/django-decorator-include

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
    :target: https://github.com/twidi/django-decorator-include

Installation
------------

Assuming you have pip installed, run the following command to install from
PyPI::

    pip install django-decorator-include

Usage
-----

``decorator_include`` is intended for use in URL confs as a replacement for the
``django.conf.urls.include`` function. It works in almost the same way as
``include`` however the first argument should be either a decorator or an
iterable of decorators to apply to all included views (if an iterable, the order of the
decorators is the order in which the functions will be applied on the views).
Here is an example URL conf

.. code-block:: python

    from django.contrib import admin
    from django.core.exceptions import PermissionDenied
    from django.urls import path
    from django.contrib.auth.decorators import login_required, user_passes_test

    from decorator_include import decorator_include

    from mysite.views import index

    def only_user(username):
        def check(user):
            if user.is_authenticated and user.username == username:
                return True
            raise PermissionDenied
        return user_passes_test(check)

    urlpatterns = [
        path('', views.index, name='index'),
        # will redirect to login page if not authenticated
        path('secret/', decorator_include(login_required, 'mysite.secret.urls')),
        # will redirect to login page if not authenticated
        # will return a 403 http error if the user does not have the "god" username
        path('admin/', decorator_include([login_required, only_user('god')], admin.site.urls),
    ]

Supported versions
------------------

=============== ========================
Django versions Python versions
=============== ========================
2.2             3.6, 3.7, 3.8, 3.9
3.0             3.6, 3.7, 3.8, 3.9
3.1             3.6, 3.7, 3.8, 3.9
3.2             3.6, 3.7, 3.8, 3.9, 3.10
4.0             3.8, 3.9, 3.10
4.1             3.8, 3.9, 3.10, 3.11
4.2             3.8, 3.9, 3.10, 3.11, 3.12
5.0             3.10, 3.11, 3.12, 3.13
5.1             3.10, 3.11, 3.12, 3.13, 3.14

=============== ========================

* Python 3.11 only works with Django 4.1.3+

All library versions to use for old Django/Python support
---------------------------------------------------------

=============== =============================== ==================
Django versions Python versions                  Library versions
=============== =============================== ==================
1.4, 1.5        2.6, 2.7                         1.2
1.6             2.6, 2.7, 3.2, 3.3               1.2
1.7             2.7, 3.2, 3.3, 3.4               1.2
1.8             2.7, 3.2, 3.3, 3.4, 3.5          1.3
1.9, 1.10       2.7, 3.4, 3.5                    1.3
1.11            2.7, 3.4, 3.5, 3.6               1.4.x (>=1.4.1,<2)
2.0             3.4, 3.5, 3.6, 3.7               3.0
2.1             3.5, 3.6, 3.7                    3.0
2.2             3.5, 3.6, 3.7, 3.8, 3.9          3.0
3.0             3.6, 3.7, 3.8, 3.9               3.0
3.1             3.6, 3.7, 3.8, 3.9               3.0
3.2             3.6, 3.7, 3.8, 3.9, 3.10         3.0
4.0             3.8, 3.9, 3.10                   3.1
4.1             3.8, 3.9, 3.10                   3.1
4.2             3.10, 3.11, 3.12                 3.1
4.2             3.10, 3.11, 3.12                 3.1
5.0             3.10, 3.11, 3.12, 3.13           3.1
5.1             3.10, 3.11, 3.12, 3.13, 3.14     3.1, 3.2 *
=============== =============================== ==================

* Python 3.14 flagged as supported added in 3.2

Development
-----------

Make sure you are in a virtualenv on a valid python version.

Grab the sources from Github::

    git clone -b develop https://github.com/twidi/django-decorator-include.git


Then go into the newly created ``django-decorator-include`` directory and install
the package in editable mode::

    pip install -e .


To run the tests, this library provides a test project, so you can launch
them this way::

    django-admin test --settings=tests.settings tests

Or simply launch the ``runtests.sh`` script (it will run this exact command)::

    ./runtests.sh

This project uses `pre-commit`_ to automatically run `black`_ , `flake8`_ and `isort`_ on
every commit. If you haven't already, first install pre-commit using the
project's documentation. Then, to enable pre-commit for
django-decorator-include::

    pre-commit install

After that, the next commit will run the tools on changed files. If you want to
run the pre-commit hooks on all files, use::

    pre-commit run --all-files

The above command is also available as a tox environment::

    tox -e lint

Base your work on the ``develop`` branch. Iit should be the default branch on
git assuming you used the ``-b develop`` argument on the ``git clone``
command as shown above.

When creating the pull request, ensure you are using the correct base
(twidi/django-decorator-include on develop).

.. _pre-commit: https://pre-commit.com/
.. _flake8: https://flake8.pycqa.org/
.. _isort: https://pycqa.github.io/isort/
.. _black: https://github.com/psf/black/


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/twidi/django-decorator-include",
    "name": "django-decorator-include",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "django, urls",
    "author": "Jeff Kistler",
    "author_email": "jeff@jeffkistler.com",
    "download_url": "https://files.pythonhosted.org/packages/ac/60/b1ac7f9a69f5357573a3934bae6a090d7ed53becae59917126c0373c1234/django_decorator_include-3.2.tar.gz",
    "platform": null,
    "description": "django-decorator-include\n========================\n\nInclude Django URL patterns with decorators.\n\nMaintained by Steve Mapes, St\u00e9phane \"Twidi\" Angel, and Jon Dufresne on\nhttps://github.com/twidi/django-decorator-include\nbased on the original work from Jeff Kistler on\nhttps://github.com/jeffkistler/django-decorator-include.\n\n.. image:: https://img.shields.io/pypi/v/django-decorator-include.svg\n    :target: https://pypi.org/project/django-decorator-include/\n\n.. image:: https://github.com/twidi/django-decorator-include/workflows/build/badge.svg\n    :target: https://github.com/twidi/django-decorator-include/actions?query=workflow%3Abuild\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/twidi/django-decorator-include\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white\n    :target: https://github.com/twidi/django-decorator-include\n\nInstallation\n------------\n\nAssuming you have pip installed, run the following command to install from\nPyPI::\n\n    pip install django-decorator-include\n\nUsage\n-----\n\n``decorator_include`` is intended for use in URL confs as a replacement for the\n``django.conf.urls.include`` function. It works in almost the same way as\n``include`` however the first argument should be either a decorator or an\niterable of decorators to apply to all included views (if an iterable, the order of the\ndecorators is the order in which the functions will be applied on the views).\nHere is an example URL conf\n\n.. code-block:: python\n\n    from django.contrib import admin\n    from django.core.exceptions import PermissionDenied\n    from django.urls import path\n    from django.contrib.auth.decorators import login_required, user_passes_test\n\n    from decorator_include import decorator_include\n\n    from mysite.views import index\n\n    def only_user(username):\n        def check(user):\n            if user.is_authenticated and user.username == username:\n                return True\n            raise PermissionDenied\n        return user_passes_test(check)\n\n    urlpatterns = [\n        path('', views.index, name='index'),\n        # will redirect to login page if not authenticated\n        path('secret/', decorator_include(login_required, 'mysite.secret.urls')),\n        # will redirect to login page if not authenticated\n        # will return a 403 http error if the user does not have the \"god\" username\n        path('admin/', decorator_include([login_required, only_user('god')], admin.site.urls),\n    ]\n\nSupported versions\n------------------\n\n=============== ========================\nDjango versions Python versions\n=============== ========================\n2.2             3.6, 3.7, 3.8, 3.9\n3.0             3.6, 3.7, 3.8, 3.9\n3.1             3.6, 3.7, 3.8, 3.9\n3.2             3.6, 3.7, 3.8, 3.9, 3.10\n4.0             3.8, 3.9, 3.10\n4.1             3.8, 3.9, 3.10, 3.11\n4.2             3.8, 3.9, 3.10, 3.11, 3.12\n5.0             3.10, 3.11, 3.12, 3.13\n5.1             3.10, 3.11, 3.12, 3.13, 3.14\n\n=============== ========================\n\n* Python 3.11 only works with Django 4.1.3+\n\nAll library versions to use for old Django/Python support\n---------------------------------------------------------\n\n=============== =============================== ==================\nDjango versions Python versions                  Library versions\n=============== =============================== ==================\n1.4, 1.5        2.6, 2.7                         1.2\n1.6             2.6, 2.7, 3.2, 3.3               1.2\n1.7             2.7, 3.2, 3.3, 3.4               1.2\n1.8             2.7, 3.2, 3.3, 3.4, 3.5          1.3\n1.9, 1.10       2.7, 3.4, 3.5                    1.3\n1.11            2.7, 3.4, 3.5, 3.6               1.4.x (>=1.4.1,<2)\n2.0             3.4, 3.5, 3.6, 3.7               3.0\n2.1             3.5, 3.6, 3.7                    3.0\n2.2             3.5, 3.6, 3.7, 3.8, 3.9          3.0\n3.0             3.6, 3.7, 3.8, 3.9               3.0\n3.1             3.6, 3.7, 3.8, 3.9               3.0\n3.2             3.6, 3.7, 3.8, 3.9, 3.10         3.0\n4.0             3.8, 3.9, 3.10                   3.1\n4.1             3.8, 3.9, 3.10                   3.1\n4.2             3.10, 3.11, 3.12                 3.1\n4.2             3.10, 3.11, 3.12                 3.1\n5.0             3.10, 3.11, 3.12, 3.13           3.1\n5.1             3.10, 3.11, 3.12, 3.13, 3.14     3.1, 3.2 *\n=============== =============================== ==================\n\n* Python 3.14 flagged as supported added in 3.2\n\nDevelopment\n-----------\n\nMake sure you are in a virtualenv on a valid python version.\n\nGrab the sources from Github::\n\n    git clone -b develop https://github.com/twidi/django-decorator-include.git\n\n\nThen go into the newly created ``django-decorator-include`` directory and install\nthe package in editable mode::\n\n    pip install -e .\n\n\nTo run the tests, this library provides a test project, so you can launch\nthem this way::\n\n    django-admin test --settings=tests.settings tests\n\nOr simply launch the ``runtests.sh`` script (it will run this exact command)::\n\n    ./runtests.sh\n\nThis project uses `pre-commit`_ to automatically run `black`_ , `flake8`_ and `isort`_ on\nevery commit. If you haven't already, first install pre-commit using the\nproject's documentation. Then, to enable pre-commit for\ndjango-decorator-include::\n\n    pre-commit install\n\nAfter that, the next commit will run the tools on changed files. If you want to\nrun the pre-commit hooks on all files, use::\n\n    pre-commit run --all-files\n\nThe above command is also available as a tox environment::\n\n    tox -e lint\n\nBase your work on the ``develop`` branch. Iit should be the default branch on\ngit assuming you used the ``-b develop`` argument on the ``git clone``\ncommand as shown above.\n\nWhen creating the pull request, ensure you are using the correct base\n(twidi/django-decorator-include on develop).\n\n.. _pre-commit: https://pre-commit.com/\n.. _flake8: https://flake8.pycqa.org/\n.. _isort: https://pycqa.github.io/isort/\n.. _black: https://github.com/psf/black/\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Include Django URL patterns with decorators",
    "version": "3.2",
    "project_urls": {
        "Homepage": "https://github.com/twidi/django-decorator-include"
    },
    "split_keywords": [
        "django",
        " urls"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac60b1ac7f9a69f5357573a3934bae6a090d7ed53becae59917126c0373c1234",
                "md5": "2b426a14bf6e20c63d2675cb6d13b08a",
                "sha256": "9c76bdd5908b30fe8b9c8053b73f6afc187b14bff76d40b8ca3bcd8161c0d21d"
            },
            "downloads": -1,
            "filename": "django_decorator_include-3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2b426a14bf6e20c63d2675cb6d13b08a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7039,
            "upload_time": "2024-10-21T06:35:30",
            "upload_time_iso_8601": "2024-10-21T06:35:30.680248Z",
            "url": "https://files.pythonhosted.org/packages/ac/60/b1ac7f9a69f5357573a3934bae6a090d7ed53becae59917126c0373c1234/django_decorator_include-3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 06:35:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "twidi",
    "github_project": "django-decorator-include",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-decorator-include"
}
        
Elapsed time: 0.81192s