Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maintenance mode toggler in the admin site #95

Open
paduszyk opened this issue Nov 8, 2022 · 1 comment
Open

Add maintenance mode toggler in the admin site #95

paduszyk opened this issue Nov 8, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@paduszyk
Copy link
Contributor

paduszyk commented Nov 8, 2022

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>
  &bull;
  {{ 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.

Fund with Polar
@paduszyk paduszyk added the enhancement New feature or request label Nov 8, 2022
@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Nov 8, 2022

@paduszyk thank you, I'm glad you enjoy this app!

It's possible to write a custom backend that uses a django model for reading/writing the state to the database and then having the relative model-admin for allow admins changing the state from the backend.

Anyway, your solution is independent by the backend used (cool) and the UI is very intuitive!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants