Get inside your stronghold and make all your Django views default login_required
Project description
![travis](https://travis-ci.org/mgrouchy/django-stronghold.png?branch=master)
#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.
```sh
pip install django-stronghold
```
Add stronghold to your INSTALLED_APPS in your Django settings file
```python
INSTALLED_APPS = (
#...
'stronghold',
)
```
Then add the stronghold middleware to your MIDDLEWARE_CLASSES in your Django settings file
```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
```python
from stronghold.decorators import public
@public
def someview(request):
# do some work
#...
```
###for class based views
```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**:
```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**:
```python
STRONGHOLD_PUBLIC_URLS = ()
```
If STRONGHOLD_DEFAULTS is True STRONGHOLD_PUBLIC_URLS contains:
```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](https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.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**:
```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`
##Compatiblity
Test with:
* Django 1.4.x
* Django 1.5
##Contribute
See CONTRIBUTING.md
#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.
```sh
pip install django-stronghold
```
Add stronghold to your INSTALLED_APPS in your Django settings file
```python
INSTALLED_APPS = (
#...
'stronghold',
)
```
Then add the stronghold middleware to your MIDDLEWARE_CLASSES in your Django settings file
```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
```python
from stronghold.decorators import public
@public
def someview(request):
# do some work
#...
```
###for class based views
```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**:
```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**:
```python
STRONGHOLD_PUBLIC_URLS = ()
```
If STRONGHOLD_DEFAULTS is True STRONGHOLD_PUBLIC_URLS contains:
```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](https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.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**:
```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`
##Compatiblity
Test with:
* Django 1.4.x
* Django 1.5
##Contribute
See CONTRIBUTING.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-stronghold-0.2.2.tar.gz
.
File metadata
- Download URL: django-stronghold-0.2.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fa03e022030b0485337272d49c532aedf85f9afa494644e453bad5b236c67f6 |
|
MD5 | 1b9267228934daf57b938def25b01a63 |
|
BLAKE2b-256 | 9feb3ccefb7017811446ffd6ec17af4c6fe246f459c5261ef12cfdf841e0bb63 |
File details
Details for the file django_stronghold-0.2.2-py27-none-any.whl
.
File metadata
- Download URL: django_stronghold-0.2.2-py27-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 2.7
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea11632438748e05d3caf31a92ebba7e75b40e2a24d8f2bdb41bb9e54134537f |
|
MD5 | ac003506df51de0427393b112547e8a6 |
|
BLAKE2b-256 | e1dec28cfa82d0d5750c3cbce57fd499c590b3c9f53ee6fc0953c1b5430b5ad1 |