示例#1
0
文件: views.py 项目: robftz/diamond
def init_user_metrics():

    # user_metrics are the only way we have to track
    # the happenings of anon sessions, so we can't
    # do anything about recovering that data.
    # however, we can still work backward frome existing
    # user accounts and fill in most of the pieces there

    for user in User.objects.all():

        try:
            m = UserMetrics.objects.get(user=user)
            pass
        except:
            # init metrics
            metrics = UserMetrics(
                user=user,
                first_visit_date=None,
                signup_date=user.get_profile().signup_date,
                first_visit_version=0,
                signup_version=VERSION,
            )

            metrics.save()
            metrics.first_visit_date = None
            metrics.save()
示例#2
0
文件: views.py 项目: robftz/diamond
def init_metrics(user, pre_login_session_key):

    try:
        metrics = UserMetrics.objects.get(anon_session_key=pre_login_session_key)
        
    except:
        # they apparently logged in before doing ANYTHING, so
        # create new metrics for them
        metrics = UserMetrics(user=user)

    metrics.user = user
    metrics.signup_version = VERSION
    metrics.signup_date = datetime.now()

    metrics.save() 
示例#3
0
文件: util.py 项目: robftz/diamond
    def inner(request, *args, **kwargs):

        user_agent=request.META.get('HTTP_USER_AGENT',None)

        request.is_crawler=False 
                
        if not user_agent:
            return HttpResponseForbidden('request without username are not supported. sorry')
            request.is_crawler=False
                                    
        for agent in user_agent:
            if agent in BOT_NAMES:
                request.is_crawler=True

        if not request.is_crawler:
            # don't save metrics for bots
            if request.user.is_authenticated(): 
                # logged in user should already have metrics
                # metrics = UserMetrics.objects.get(user=user)
                try:
                    metrics = request.user.metrics
                except:
                    metrics = UserMetrics(user=request.user)
                    metrics.save() 

            else:
                try:
                    metrics = UserMetrics.objects.get(anon_session_key=request.session.session_key)
                except:
                    metrics = UserMetrics(anon_session_key=request.session.session_key)
                    metrics.save()

            if len(metrics.login_dates) == 0 or metrics.login_dates[-1] != datetime.date.today():
                # if we haven't already marked the user
                # as active for today, do so now!
                
                metrics.login_dates.append(datetime.date.today())
                metrics.save()

        # call the wrapped view
        return view(request, *args, **kwargs)