fabiocaccamo / django-maintenance-mode

:construction: :hammer_and_wrench: shows a 503 error page when maintenance-mode is on.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a view decorator

ziima opened this issue · comments

For a complex applications, such as we have, the split of views available and unavailable during the maintenance can be non-trivial. Decorator which marks views turned off during the maintenance would allow fine-tuning of the application maintenance.

This is a very useful feature. Thanks for the suggestion, I will work on it as soon as possible.

If you don't insist on writing it yourself, I should be able to find time to do it next week.

If you can write it with tests it would be great.

By default all views are affected by maintenance-mode when active, so my idea is to add a single decorator named ignore_maintenance_mode.

That's only true if middleware is turned on. Some of our use cases requires only few views to be turned on, while most of the application is not affected by the middleware. My original idea was to add possitive decorator.

But I see you case, so I suggest to add both decorators - force and ignore, similarly to CSRF in Django itself.

So you need to have some views under a forced maintenance-mode also if the maintenance-mode is not set to True, is it correct?

Nope, we need only a few views to be subject of the maintenance mode, while most of them is not affected. Thus we want to decorate those views and avoid usage of the middleware.

By default all views are affected by maintenance-mode when active, so my idea is to add a single decorator named ignore_maintenance_mode (to avoid usage of the middleware for the views that must not be affected by maintenance-mode)

I think we are saying the same thing...

I think that the best approach would be add a new setting:

MAINTENANCE_MODE_IGNORE_VIEWS = ('app.views.no_maintenance_mode', )

Have you any reason to prefere a view decorator?

  1. I can't imagine this to work for class based views.
  2. The list could be really long. In such case, the decorator would be much easier to maintain.

Released 0.9.0
Now you can use force_maintenance_mode_on and force_maintenance_mode_off decorators.

Thanks, but force_maintenance_mode_on seems somewhat ridiculous. It always enforces maintenance mode on a view, which I can't find any use for.

Instead such decorator should check maintenance mode, even if maintenance middleware is not active.