-
-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The app is great! 😀 You do a great job for Django users!
However, a nice feature would to have admin toggler turning the 503 mode on and off. Something like this.
I know it's quite simple to implement, for instance by adding a view as follows:
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
def toggle_maintenance_mode(request):
"""
Toggle between 'on' and 'off' mode of the maintenance mode.
"""
if request.user.is_superuser:
set_maintenance_mode(not get_maintenance_mode())
return redirect(request.GET.get("next")) or "/"
raise PermissionDenied
the corresponding URL path, a overriden admin/base.html template:
{% block userlinks %}
{% if maintenance_mode %}<strong>{% endif %}{% translate "Maintenance mode" %}{% if maintenance_mode %}</strong>{% endif %}
<a href="{% url 'maintenance_mode_toggle' %}?next={{ request.path }}">{% if maintenance_mode %}{% translate "OFF" %}{% else %}{% translate "ON" %}{% endif %}</a>
•
{{ block.super }}
{% endblock %}
I did this in my project and had to additionally add /maintenance-mode/ to the MAINTENANCE_MODE_IGNORE_URLS settings, because redirects were blocked by the app.
Feel free to use this idea. I have no abilities to write tests.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Projects
Status
Todo