app/soc/middleware/value_store.py
changeset 2903 bf17c6a843dd
child 2906 6fb53ed7aff4
equal deleted inserted replaced
2902:23e00d707255 2903:bf17c6a843dd
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2009 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Middleware to set up and empty the value store.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 from soc.modules import callback
       
    26 
       
    27 
       
    28 class ValueStoreMiddleware(object):
       
    29   """Middleware class to set up and empty the value store.
       
    30   """
       
    31 
       
    32   def start(self, request):
       
    33     """Sets up the value store.
       
    34 
       
    35     Args:
       
    36       request: a Django HttpRequest object
       
    37     """
       
    38 
       
    39     core = callback.getCore()
       
    40     core.startNewRequest(request)
       
    41 
       
    42   def end(self, request):
       
    43     """Empties the value store.
       
    44 
       
    45     Args:
       
    46       request: a Django HttpRequest object
       
    47     """
       
    48 
       
    49     core = callback.getCore()
       
    50     core.endRequest(request)
       
    51 
       
    52   def process_request(self, request):
       
    53     self.start(request)
       
    54 
       
    55   def process_response(self, request, response):
       
    56     self.end(request)
       
    57     return response
       
    58 
       
    59   def process_exception(self, request, exception):
       
    60     self.end(request)