Beispiel #1
0
def log_page_view(request, context):
    entry = {}

    # get the nav root
    pps = context.restrictedTraverse('@@plone_portal_state')
    navroot = pps.navigation_root()
    # get the subject
    subject = navroot.getId()
    entry['subject'] = subject
    entry['domain'] = 'everything%s.co.za' %subject

    # get the GA code from the registry
    registry = queryUtility(IRegistry)
    settings = registry.forInterface(IEmasMobileThemeSettings)

    gacode = getattr(settings, '%s_gacode' %subject, None)
    if not gacode:
        return
    entry['gacode'] = gacode
    
    # We try to get the referef off the url param 'referef' first.
    # This is due to the fact that we have viewlet which crafts an img src
    # with this param.  It was introduced to stop caches from breaking our
    # stats gathering.
    entry['referer'] = request.get('referer', request.getHeader('HTTP_REFERER'))

    entry['title'] = context.Title()

    remote_address = request.getHeader(
            'HTTP_X_FORWARDED_FOR', request.getHeader('REMOTE_ADDR'))
    entry['remote_address'] = remote_address
    entry['user_agent'] = request.getHeader('HTTP_USER_AGENT')

    # drop the science or maths from the path
    path = context.getPhysicalPath()
    path_elements = ('',) + path[3:]
    path = '/'.join(path_elements)
    entry['path'] = path

    locale = getattr(request, 'locale')
    entry['locale'] = locale.getLocaleID()
    
    for key in ['REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_USER_AGENT',
                'HTTP_ACCEPT_LANGUAGE', 'AUTHENTICATED_USER',]:
        value = request.get(key)
        if hasattr(value, 'aq_inner'):
            value = request.get(key).aq_base
            if key == 'AUTHENTICATED_USER':
                value = value.getId()
        if value:
            entry[key] = value

    port = getattr(settings, 'redis_port', 6379)
    entry['redis-port'] = port
    gaq = get_q(q_name='google_analytics_q', port=port)
    LOGGER.debug(entry)
    gaq.enqueue(GoogleQueue.deliver, entry)
Beispiel #2
0
 def test_05_redis_worker_delivery(self):
     ga = MockGoogleAnalytics()
     # add a stuff to a test q
     testq = get_q(self.qname)
     testq.enqueue(ga.deliver, 'message 002')
     self.assertEqual(testq.count, 1, 'Queue must have one message.')
     
     # let the worker deliver it
     worker = Worker(testq, name='test worker')
     worker.work(burst=True)
     self.assertEqual(testq.count, 0, 'Queue should have no messages.')
Beispiel #3
0
 def test_03_getq(self):
     testq = get_q(self.qname)
     assert testq is not None, 'No queue found.'
     self.assertEqual(testq.name, self.qname, 'Queue name incorrect.')
     self.assertEqual(testq.is_empty(), True, 'Queue should be empty.')
     self.assertEqual(testq.count, 0, 'Queue should not have items.')
Beispiel #4
0
 def test_04_enque(self):
     ga = MockGoogleAnalytics()
     testq = get_q(self.qname)
     testq.enqueue(ga.deliver, 'message 001')
     self.assertEqual(testq.count, 1, 'The queue should have 1 item.')
     testq.empty()