Exemplo n.º 1
0
def pageview(request):
    if getattr(settings, 'SCRYER_SKIP', False):
        pass

    elif getattr(settings, 'SCRYER_SKIP_USERS', True) and not request.user.id is None:
        pass

    else:
        if request.META.has_key('HTTP_X_FORWARDED_FOR'):
            ip = request.META['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()
        elif request.META.has_key('REMOTE_ADDR'):
            ip = request.META['REMOTE_ADDR']
        else:
            ip = '0.0.0.0'

        if request.GET.has_key('site'):
            site = sites.get_object(pk=int(request.GET['site']))
        else:
            site = sites.get_object(pk=settings.SITE_ID)

        session_key = None
        # If there is a cookie with a session use that use that
        # FIXME -- should it expire before the Django-session cookie?!
        try:
            session_key = request.session['scryer-session']
        except KeyError:
            pass

        # Look for a recent request with this IP-address, if this exists,
        # reuse that session; this is a band-aid when the browser refuses
        # our cookie.
        if session_key is None:
            oldest = datetime.datetime.now() - pageviews.session_lifetime
            hits = pageviews.get_list(ip_address__exact=ip,
                                      served__gt=oldest,
                                      order_by=['-served'],
                                      limit=1)
            if hits:
                session_key = hits[0].session_key

        # Finally, create a new session
        if session_key is None:
            session_key = pageviews.get_new_session_key()

        request.session['scryer-session'] = session_key
        
        url = '/' + request.GET['url'].split('/', 3)[-1]

        pv = pageviews.PageView(site=site, url=url)
        pv.referrer = request.GET.get('ref', '') or None
        pv.user_agent = request.META.get('HTTP_USER_AGENT', None)
        pv.session_key = session_key
        pv.ip_address = ip
        pv.save()

    r = HttpResponse('/* Intentionally left empty */', 'text/css')
    r['Cache-Control'] = 'max-age=0'
    r['Expires'] = 'Fri, 16 Sep 2005 10:01:26 GMT'
    return r
Exemplo n.º 2
0
def template_detail(request, template):
    templates = []
    for site_settings_module in settings.ADMIN_FOR:
        settings_mod = __import__(site_settings_module, '', '', [''])
        for dir in settings_mod.TEMPLATE_DIRS:
            template_file = os.path.join(dir, "%s.html" % template)
            templates.append({
                'file'      : template_file,
                'exists'    : os.path.exists(template_file),
                'contents'  : lambda: os.path.exists(template_file) and open(template_file).read() or '',
                'site_id'   : settings_mod.SITE_ID,
                'site'      : sites.get_object(pk=settings_mod.SITE_ID),
                'order'     : list(settings_mod.TEMPLATE_DIRS).index(dir),
            })
    return render_to_response('admin_doc/template_detail', {
        'name': template,
        'templates': templates,
    }, context_instance=DjangoContext(request))
Exemplo n.º 3
0
def view_index(request):
    if not doc:
        return missing_docutils_page(request)

    views = []
    for site_settings_module in settings.ADMIN_FOR:
        settings_mod = __import__(site_settings_module, '', '', [''])
        urlconf = __import__(settings_mod.ROOT_URLCONF, '', '', [''])
        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
        for (func, regex) in view_functions:
            views.append({
                'name'   : func.__name__,
                'module' : func.__module__,
                'site_id': settings_mod.SITE_ID,
                'site'   : sites.get_object(pk=settings_mod.SITE_ID),
                'url'    : simplify_regex(regex),
            })
    return render_to_response('admin_doc/view_index', {'views': views}, context_instance=DjangoContext(request))