Hours of Operation Middleware

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

fromdatetimeimportdatetimefromdjango.shortcutsimportrender_to_responseTIME_OPEN=(9,0)# 9am and 0 minutesTIME_CLOSED=(12+8,0)# 8pm and 0 minutesclassHoursOfOperationMiddleware(object):defprocess_request(self,request):# Slice [3:5] of a timetuple is the hours and minutesifnotTIME_OPEN<=datetime.now().timetuple()[3:5]<TIME_CLOSED:returnrender_to_response('hoursofoperation/closed.html')