예제 #1
0
 def setUp(self):
     # create 10 middleware objects
     user = User.objects.all()[0]
     for n in xrange(0, 100, 10):
         m = MiddlewareData()
         m.method = "GET"
         m.uri = "/"
         m.user = user
         m.lang = "EN_en"
         m.addr = "127.0.0.1"
         m.user_agent = "Unknown User agent"
         m.priority = n
         m.save()
예제 #2
0
    def process_request(self, request):
        """ Handler to store http request"""

        req = MiddlewareData()

        if request.user.is_anonymous():
            req.user = None
        else:
            req.user = request.user
        if 'LANG' in request.META:
            req.lang = request.META['LANG']
        else:
            req.lang = ''

        req.method = request.method
        req.uri = request.build_absolute_uri()
        if 'HTTP_USER_AGENT' in request.META.keys():
            req.user_agent = request.META['HTTP_USER_AGENT']
        else:
            req.user_agent = ""
        req.uri = request.build_absolute_uri()
        req.addr = request.META['REMOTE_ADDR']
        req.save()