Middleware for implementing "hours of operation" for a website. In use (as configured here) on http://ianab.com/.
1 2 3 4 5 6 7 8 9 10 11 | from datetime import datetime
from django.shortcuts import render_to_response
TIME_OPEN = (9, 0) # 9am and 0 minutes
TIME_CLOSED = (12 + 8, 0) # 8pm and 0 minutes
class HoursOfOperationMiddleware(object):
def process_request(self, request):
# Slice [3:5] of a timetuple is the hours and minutes
if not TIME_OPEN <= datetime.now().timetuple()[3:5] < TIME_CLOSED:
return render_to_response('hoursofoperation/closed.html')
|
More like this
- Form field with fixed value by roam 1 week, 5 days ago
- New Snippet! by Antoliny0919 2 weeks, 5 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 7 months ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
How comes this can be a useful thing for the whole site?! :)
#
It lets the server rest so it can be in a better mood the next day.
#
Please login first before commenting.