Login

Hours of Operation Middleware

Author:
andrew
Posted:
March 10, 2009
Language:
Python
Version:
1.0
Score:
0 (after 2 ratings)

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

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

buriy (on March 13, 2009):

How comes this can be a useful thing for the whole site?! :)

#

andrew (on December 7, 2009):

It lets the server rest so it can be in a better mood the next day.

#

Please login first before commenting.