Add banner for informate user hours and date of the maintenance
scwall opened this issue · 3 comments
Hello, I integrated a maintenance signalling system for a project, quickly. I thought it would be a good idea to have this system in django-maintenance-mode. Which allows you to signal users of maintenance hours. I am in the process of following up for an email sending with the scheduled maintenance to all users of the company.
(i'm use django solo : https://github.com/lazybird/django-solo for singleton model) but now several hours could be scheduled
models :
class MaintenanceSchedule(SingletonModel):
day = models.DateField('Day of the maintenance', help_text='Day of the maintenance',default=timezone.now)
start_time = models.TimeField('Starting time', help_text='Starting time',default=timezone.now)
end_time = models.TimeField('Final time', help_text='Final time',default=timezone.now)
active = models.BooleanField(default=False)
tags_maintenance:
@register.simple_tag
def maintenance_schedule():
maintenance = MaintenanceSchedule.get_solo()
return maintenance
and base.html
{% maintenance_schedule as maintenance_schelude %}
{% if maintenance_schelude.active %}
<div style="padding-bottom: 80px;width:100%; height: 50px;position: fixed;bottom: 0;background-color: #ffcc00" id="maintenance-banner">
<p style="font-size: 22px;" class="text-center"> <b>{% blocktrans %}The site will be under maintenance : {% endblocktrans %}</b>{{ maintenance_schelude.day }}{% blocktrans %} between{% endblocktrans %} {{ maintenance_schelude.start_time }} {% blocktrans %}and{% endblocktrans %} {{ maintenance_schelude.end_time }} </p>
</div>
{% endif %}
Hi @scwall,
thank you for this suggestion.
Maintenance-mode schedule is already in the 'todo' of this library.
Frankly my idea was to add support to it using a simple setting:
settings.MAINTENANCE_MODE_SCHEDULE = {
'sun': {'start':'01:00', 'end':'02:00'},
'mon': None,
'tue': None,
'wed': {'start':'01:00', 'end':'02:00'},
'thu': None,
'fri': None,
'sat': None,
}
# or this to schedule maintenance every day:
settings.MAINTENANCE_MODE_SCHEDULE = {
'*': {'start':'01:00', 'end':'02:00'},
}
Now, looking at your suggestion, I understand the flexibility to manage maintenance schedule using the admin and also the necessity to send an email to users to warn them about the incoming maintenance (which needs a cronjob).
Actually this library doesn't use database at all and I would prefer to keep it tiny and db free, but I also want to implement maintenance schedule in the best and flexible way...
I take some time to think better about it, in the meanwhile any other idea/suggestion will be appreciated.
Ok I understand, maybe adding an external yarml file for the hours, for don't modify settings file . Personally I will have to use a db, because I use docker (with dj cookie cutter) for the deployment of my projects. If I change the settings I will have to rebuild my image and redeploy it just to publish the time. For the use of a recurring stain: https://pypi.org/project/django-crontab/ is quite light.
example maintenance.yml:
schelude:
- date: 14/05/2020
start_time: 12h20
end_time: 14h30
- date: 14/05/2021
start_time: 10h20
end_time: 19h30
I close this issue because it is very similar to another one, everything related to maintenance mode schedule will be discussed in #64.