1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
Metadata-Version: 2.1
Name: django-maintenance-mode
Version: 0.16.1
Summary: django-maintenance-mode shows a 503 error page when maintenance-mode is on.
Home-page: https://github.com/fabiocaccamo/django-maintenance-mode
Author: Fabio Caccamo
Author-email: fabio.caccamo@gmail.com
License: MIT
Download-URL: https://github.com/fabiocaccamo/django-maintenance-mode/archive/0.16.1.tar.gz
Description: [](https://www.python.org/)
[](https://www.djangoproject.com/)
[](https://pypi.org/project/django-maintenance-mode/)
[](https://pepy.tech/project/django-maintenance-mode)
[](https://github.com/fabiocaccamo/django-maintenance-mode/)
[](https://badges.pufler.dev)
[](https://github.com/fabiocaccamo/django-maintenance-mode/blob/master/LICENSE.txt)
[](https://travis-ci.org/fabiocaccamo/django-maintenance-mode)
[](https://codecov.io/gh/fabiocaccamo/django-maintenance-mode)
[](https://www.codacy.com/app/fabiocaccamo/django-maintenance-mode)
[](https://codeclimate.com/github/fabiocaccamo/django-maintenance-mode/)
[](https://requires.io/github/fabiocaccamo/django-maintenance-mode/requirements/?branch=master)
# django-maintenance-mode
django-maintenance-mode shows a 503 error page when **maintenance-mode** is **on**.
It works at application level, so your django instance should be up.
It doesn't use database and doesn't prevent database access.
## Installation
1. Run ``pip install django-maintenance-mode`` or [download django-maintenance-mode](http://pypi.python.org/pypi/django-maintenance-mode) and add the **maintenance_mode** package to your project
2. Add ``'maintenance_mode'`` to ``settings.INSTALLED_APPS`` before custom applications
3. Add ``'maintenance_mode.middleware.MaintenanceModeMiddleware'`` to ``settings.MIDDLEWARE_CLASSES``/``settings.MIDDLEWARE`` as last middleware
4. Add your custom ``templates/503.html`` file
5. Restart your application server
## Configuration (optional)
### Settings
All these settings are optional, if not defined in ``settings.py`` the default values (listed below) will be used.
```python
# if True the maintenance-mode will be activated
MAINTENANCE_MODE = None
```
```python
# by default, to get/set the state value a local file backend is used
# if you want to use the db or cache, you can create a custom backend
# custom backends must extend 'maintenance_mode.backends.AbstractStateBackend' class
# and implement get_value(self) and set_value(self, val) methods
MAINTENANCE_MODE_STATE_BACKEND = 'maintenance_mode.backends.LocalFileBackend'
# alternatively it is possible to use the default storage backend
MAINTENANCE_MODE_STATE_BACKEND = 'maintenance_mode.backends.DefaultStorageBackend'
```
```python
# by default, a file named "maintenance_mode_state.txt" will be created in the settings.py directory
# you can customize the state file path in case the default one is not writable
MAINTENANCE_MODE_STATE_FILE_PATH = 'maintenance_mode_state.txt'
```
```python
# if True admin site will not be affected by the maintenance-mode page
MAINTENANCE_MODE_IGNORE_ADMIN_SITE = False
```
```python
# if True anonymous users will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_ANONYMOUS_USER = False
```
```python
# if True authenticated users will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_AUTHENTICATED_USER = False
```
```python
# if True the staff will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_STAFF = False
```
```python
# if True the superuser will not see the maintenance-mode page
MAINTENANCE_MODE_IGNORE_SUPERUSER = False
```
```python
# list of ip-addresses that will not be affected by the maintenance-mode
# ip-addresses will be used to compile regular expressions objects
MAINTENANCE_MODE_IGNORE_IP_ADDRESSES = ()
```
```python
# the path of the function that will return the client IP address given the request object -> 'myapp.mymodule.myfunction'
# the default function ('maintenance_mode.utils.get_client_ip_address') returns request.META['REMOTE_ADDR']
# in some cases the default function returns None, to avoid this scenario just use 'django-ipware'
MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = None
```
Retrieve user's real IP address using [`django-ipware`](https://github.com/un33k/django-ipware):
```python
MAINTENANCE_MODE_GET_CLIENT_IP_ADDRESS = 'ipware.ip.get_ip'
```
```python
# list of urls that will not be affected by the maintenance-mode
# urls will be used to compile regular expressions objects
MAINTENANCE_MODE_IGNORE_URLS = ()
```
```python
# if True the maintenance mode will not return 503 response while running tests
# useful for running tests while maintenance mode is on, before opening the site to public use
MAINTENANCE_MODE_IGNORE_TESTS = False
```
```python
# the absolute url where users will be redirected to during maintenance-mode
MAINTENANCE_MODE_REDIRECT_URL = None
```
```python
# the template that will be shown by the maintenance-mode page
MAINTENANCE_MODE_TEMPLATE = '503.html'
```
```python
# the path of the function that will return the template context -> 'myapp.mymodule.myfunction'
MAINTENANCE_MODE_GET_TEMPLATE_CONTEXT = None
```
```python
# the HTTP status code to send
MAINTENANCE_MODE_STATUS_CODE = 503
```
```python
# the value in seconds of the Retry-After header during maintenance-mode
MAINTENANCE_MODE_RETRY_AFTER = 3600 # 1 hour
```
#### Context Processors
Add **maintenance_mode.context_processors.maintenance_mode** to your context_processors list in ``settings.py`` if you want to access the maintenance_mode status in your templates.
```python
TEMPLATES = [
{
# ...
'OPTIONS': {
'context_processors': [
# ...
'maintenance_mode.context_processors.maintenance_mode',
# ...
],
},
# ...
},
]
```
#### Logging
You can disable emailing 503 errors to admins while maintenance mode is enabled:
```python
LOGGING = {
'filters': {
'require_not_maintenance_mode_503': {
'()': 'maintenance_mode.logging.RequireNotMaintenanceMode503',
},
...
},
'handlers': {
...
},
...
}
```
### Context Managers
You can force a block of code execution to run under maintenance mode or not using context managers:
```python
from maintenance_mode.core import maintenance_mode_off, maintenance_mode_on
with maintenance_mode_on():
# do stuff
pass
with maintenance_mode_off():
# do stuff
pass
```
### URLs
Add **maintenance_mode.urls** to ``urls.py`` if you want superusers able to set maintenance_mode using urls.
```python
urlpatterns = [
# ...
url(r'^maintenance-mode/', include('maintenance_mode.urls')),
# ...
]
```
### Views
You can force maintenance mode on/off at view level using view decorators:
```python
from maintenance_mode.decorators import force_maintenance_mode_off, force_maintenance_mode_on
@force_maintenance_mode_off
def my_view_a(request):
# never return 503 response
pass
@force_maintenance_mode_on
def my_view_b(request):
# always return 503 response
pass
```
## Usage
### Python
```python
from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
set_maintenance_mode(True)
if get_maintenance_mode():
set_maintenance_mode(False)
```
or
```python
from django.core.management import call_command
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
call_command('maintenance_mode', 'on')
# call your command(s)
call_command('maintenance_mode', 'off')
```
### Templates
```html
{% if maintenance_mode %}
<!-- html -->
{% endif %}
```
### Terminal
Run ``python manage.py maintenance_mode <on|off>``
*(**This is not Heroku-friendly because** any execution of heroku run* `manage.py` *will be run on a separate worker dyno, not the web one. Therefore **the state-file is set but on the wrong machine. You should use a custom*** `MAINTENANCE_MODE_STATE_BACKEND`*.)*
### URLs
Superusers can change maintenance-mode using the following urls:
``/maintenance-mode/off/``
``/maintenance-mode/on/``
## Testing
```bash
# create python virtual environment
virtualenv testing_django_maintenance_mode
# activate virtualenv
cd testing_django_maintenance_mode && . bin/activate
# clone repo
git clone https://github.com/fabiocaccamo/django-maintenance-mode.git src && cd src
# run tests
tox
# or
python setup.py test
# or
python -m django test --settings "tests.settings"
```
## License
Released under [MIT License](LICENSE.txt).
---
## See also
- [`django-admin-interface`](https://github.com/fabiocaccamo/django-admin-interface) - the default admin interface made customizable by the admin itself. popup windows replaced by modals. 🧙 ⚡
- [`django-colorfield`](https://github.com/fabiocaccamo/django-colorfield) - simple color field for models with a nice color-picker in the admin. 🎨
- [`django-extra-settings`](https://github.com/fabiocaccamo/django-extra-settings) - config and manage typed extra settings using just the django admin. ⚙️
- [`django-redirects`](https://github.com/fabiocaccamo/django-redirects) - redirects with full control. ↪️
- [`django-treenode`](https://github.com/fabiocaccamo/django-treenode) - probably the best abstract model / admin for your tree based stuff. 🌳
- [`python-benedict`](https://github.com/fabiocaccamo/python-benedict) - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
- [`python-codicefiscale`](https://github.com/fabiocaccamo/python-codicefiscale) - encode/decode Italian fiscal codes - codifica/decodifica del Codice Fiscale. 🇮🇹 💳
- [`python-fsutil`](https://github.com/fabiocaccamo/python-fsutil) - file-system utilities for lazy devs. 🧟♂️
Keywords: django,maintenance,mode,offline,under,503,service,temporarily,unavailable
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.7
Classifier: Framework :: Django :: 1.8
Classifier: Framework :: Django :: 1.9
Classifier: Framework :: Django :: 1.10
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Build Tools
Requires: django(>=1.7)
Description-Content-Type: text/markdown
|