django-stronghold 0.2.7

Get inside your stronghold and make all your Django views default login_required
.. figure:: https://travis-ci.org/mgrouchy/django-stronghold.png?branch=master
   :alt: travis

Stronghold
==========

Get inside your stronghold and make all your Django views default
login\_required

Stronghold is a very small and easy to use django app that makes all
your Django project default to require login for all of your views.

WARNING: still in development, so some of the DEFAULTS and such will be
changing without notice.

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

Install via pip.

.. code:: sh

    pip install django-stronghold

Add stronghold to your INSTALLED\_APPS in your Django settings file

.. code:: python


    INSTALLED_APPS = (
        #...
        'stronghold',
    )

Then add the stronghold middleware to your MIDDLEWARE\_CLASSES in your
Django settings file

.. code:: python

    MIDDLEWARE_CLASSES = (
        #...
        'stronghold.middleware.LoginRequiredMiddleware',
    )

Usage
-----

If you followed the installation instructions now all your views are
defaulting to require a login. To make a view public again you can use
the public decorator provided in ``stronghold.decorators`` like so:

For function based views
~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from stronghold.decorators import public


    @public
    def someview(request):
        # do some work
        #...

for class based views
~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    from django.utils.decorators import method_decorator
    from stronghold.decorators import public


    class SomeView(View):
        def get(self, request, *args, **kwargs):
            # some view logic
            #...

        @method_decorator(public)
        def dispatch(self, *args, **kwargs):
            return super(SomeView, self).dispatch(*args, **kwargs)

Configuration (optional)
------------------------

STRONGHOLD\_DEFAULTS
~~~~~~~~~~~~~~~~~~~~

Use Strongholds defaults in addition to your own settings.

**Default**:

.. code:: python

    STRONGHOLD_DEFAULTS = True

You can add a tuple of url regexes in your settings file with the
``STRONGHOLD_PUBLIC_URLS`` setting. Any url that matches against these
patterns will be made public without using the ``@public`` decorator.

STRONGHOLD\_PUBLIC\_URLS
~~~~~~~~~~~~~~~~~~~~~~~~

**Default**:

.. code:: python

    STRONGHOLD_PUBLIC_URLS = ()

If STRONGHOLD\_DEFAULTS is True STRONGHOLD\_PUBLIC\_URLS contains:

.. code:: python

    (
        r'^%s.+$' % settings.STATIC_URL,
        r'^%s.+$' % settings.MEDIA_URL,
    )

When settings.DEBUG = True. This is additive to your settings to support
serving Static files and media files from the development server. It
does not replace any settings you may have in
``STRONGHOLD_PUBLIC_URLS``.

    Note: Public URL regexes are matched against
    `HttpRequest.path\_info`_.

STRONGHOLD\_PUBLIC\_NAMED\_URLS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can add a tuple of url names in your settings file with the
``STRONGHOLD_PUBLIC_NAMED_URLS`` setting. Names in this setting will be
reversed using ``django.core.urlresolvers.reverse`` and any url matching
the output of the reverse call will be made public without using the
``@public`` decorator:

**Default**:

.. code:: python

    STRONGHOLD_PUBLIC_NAMED_URLS = ()

If STRONGHOLD\_DEFAULTS is True additionally we search for
``django.contrib.auth`` if it exists, we add the login and logout view
names to ``STRONGHOLD_PUBLIC_NAMED_URLS``

STRONGHOLD\_PERMISSIONS\_DECORATOR
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Optionally configure STRONGHOLD_PERMISSIONS_DECORATOR to be something besides
``login_required``. This allows the developer to set this to an alternative
decorator like ``staff_member_required`` or a user created decorator that
processes a view function and returns ``None`` or a ``HTTPResponse``.

**Default**:

.. code:: python
    STRONGHOLD_PERMISSIONS_DECORATOR = login_required


Compatiblity
------------

Tested with:

- Django 1.4.x
- Django 1.5.x
- Django 1.6.x
- Django 1.7.x

Contribute
----------

See CONTRIBUTING.md

.. _HttpRequest.path\_info: https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path_info
MIT license

Author

Mike Grouchy

Pip

django-stronghold==0.2.7

Classifiers

  • Development Status :: 5 - Production/Stable
  • Intended Audience :: Developers
  • License :: OSI Approved :: MIT License
  • Programming Language :: Python
  • Programming Language :: Python :: 2.6
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.4
  • Natural Language :: English
File Type Python Version Uploaded On Downloads
django_stronghold-0.2.7-py2.py3-none-any.whl Wheel 2.7 Feb. 16, 2015 1,422
django_stronghold-0.2.7-py2-none-any.whl Wheel 2.7 Feb. 16, 2015 3,356
django-stronghold-0.2.7.tar.gz Source Feb. 16, 2015 815
Version Release Date
0.2.7 Feb. 16, 2015
0.2.6 May 28, 2014
0.2.5 May 28, 2014
0.2.4 Jan. 7, 2014
0.2.3 Jan. 5, 2014
0.2.2 July 2, 2013
0.2.1 March 31, 2013
0.2.0 March 24, 2013
0.1.1 March 10, 2013
0.1.0 March 9, 2013
0.0.8 March 7, 2013
0.0.7 March 6, 2013
0.0.6 Feb. 26, 2013
0.0.5 Feb. 26, 2013
0.0.4 Feb. 12, 2013
0.0.3 Feb. 8, 2013
0.0.2 Feb. 1, 2013
0.0.1 Aug. 26, 2015
Date Package Version Action
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.1.1 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.1.0 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.0 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.1 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.2 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.3 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.4 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.5 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.6 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.2.7 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.8 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.2 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.3 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.1 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.6 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.7 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.4 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold 0.0.5 Release Created
Aug. 26, 2015, 12:27 a.m. django-stronghold Package Created