Updated README.md
Paweł Adamczak authored 6 years ago
GitHub committed 6 years ago
0 | 0 | [![Build Status](https://travis-ci.org/mgrouchy/django-stronghold.svg?branch=master)](https://travis-ci.org/mgrouchy/django-stronghold) |
1 | 1 | |
2 | #Stronghold | |
2 | # Stronghold | |
3 | 3 | |
4 | 4 | Get inside your stronghold and make all your Django views default login_required |
5 | 5 | |
7 | 7 | |
8 | 8 | WARNING: still in development, so some of the DEFAULTS and such will be changing without notice. |
9 | 9 | |
10 | ##Installation | |
10 | ## Installation | |
11 | 11 | |
12 | 12 | Install via pip. |
13 | 13 | |
35 | 35 | |
36 | 36 | ``` |
37 | 37 | |
38 | ##Usage | |
38 | ## Usage | |
39 | 39 | |
40 | 40 | If you followed the installation instructions now all your views are defaulting to require a login. |
41 | 41 | To make a view public again you can use the public decorator provided in `stronghold.decorators` like so: |
42 | 42 | |
43 | ###For function based views | |
43 | ### For function based views | |
44 | 44 | ```python |
45 | 45 | from stronghold.decorators import public |
46 | 46 | |
52 | 52 | |
53 | 53 | ``` |
54 | 54 | |
55 | ###for class based views (decorator) | |
55 | ### For class based views (decorator) | |
56 | 56 | |
57 | 57 | ```python |
58 | 58 | from django.utils.decorators import method_decorator |
69 | 69 | return super(SomeView, self).dispatch(*args, **kwargs) |
70 | 70 | ``` |
71 | 71 | |
72 | ###for class based views (mixin) | |
72 | ### For class based views (mixin) | |
73 | 73 | |
74 | 74 | ```python |
75 | 75 | from stronghold.views import StrongholdPublicMixin |
79 | 79 | pass |
80 | 80 | ``` |
81 | 81 | |
82 | ##Configuration (optional) | |
82 | ## Configuration (optional) | |
83 | 83 | |
84 | 84 | |
85 | ###STRONGHOLD_DEFAULTS | |
85 | ### STRONGHOLD_DEFAULTS | |
86 | 86 | |
87 | 87 | Use Strongholds defaults in addition to your own settings. |
88 | 88 | |
97 | 97 | will be made public without using the `@public` decorator. |
98 | 98 | |
99 | 99 | |
100 | ###STRONGHOLD_PUBLIC_URLS | |
100 | ### STRONGHOLD_PUBLIC_URLS | |
101 | 101 | |
102 | 102 | **Default**: |
103 | 103 | ```python |
118 | 118 | |
119 | 119 | > Note: Public URL regexes are matched against [HttpRequest.path_info](https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.path_info). |
120 | 120 | |
121 | ###STRONGHOLD_PUBLIC_NAMED_URLS | |
121 | ### STRONGHOLD_PUBLIC_NAMED_URLS | |
122 | 122 | You can add a tuple of url names in your settings file with the |
123 | 123 | `STRONGHOLD_PUBLIC_NAMED_URLS` setting. Names in this setting will be reversed using |
124 | 124 | `django.core.urlresolvers.reverse` and any url matching the output of the reverse |
132 | 132 | If STRONGHOLD_DEFAULTS is True additionally we search for `django.contrib.auth` |
133 | 133 | if it exists, we add the login and logout view names to `STRONGHOLD_PUBLIC_NAMED_URLS` |
134 | 134 | |
135 | ###STRONGHOLD_USER_TEST_FUNC | |
135 | ### STRONGHOLD_USER_TEST_FUNC | |
136 | 136 | Optionally, set STRONGHOLD_USER_TEST_FUNC to a callable to limit access to users |
137 | 137 | that pass a custom test. The callback receives a `User` object and should |
138 | 138 | return `True` if the user is authorized. This is equivalent to decorating a |
161 | 161 | * Django 1.9.x |
162 | 162 | * Django 1.10.x |
163 | 163 | |
164 | ##Contribute | |
164 | ## Contribute | |
165 | 165 | |
166 | 166 | See CONTRIBUTING.md |