Esempio n. 1
0
def read_statistics(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_week_read_data(blog_content_type)

    # 获取一周热门博客的缓存数据
    week_hot_blogs = cache.get('week_hot_blogs')
    if week_hot_blogs is None:
        week_hot_blogs = get_week_hot_blogs()
        cache.set('week_hot_blogs', week_hot_blogs, 3600)
    # 测试
    #     print('cache')
    # else:
    #     print('use cache')

    # 获取一个月的热门博客缓存数据
    month_hot_blogs = cache.get('month_hot_blogs')
    if month_hot_blogs is None:
        month_hot_blogs = get_month_hot_blogs()
        cache.set('month_hot_blogs', month_hot_blogs, 3600)

    context = {}
    context['dates'] = dates
    context['read_nums'] = read_nums
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['week_hot_blogs'] = week_hot_blogs
    context['month_hot_blogs'] = month_hot_blogs
    return render(request, 'read_statistics/read_statistics.html', context)
Esempio n. 2
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_week_read_data(blog_content_type)

    # 获取缓存数据
    week_hot_data = cache.get('week_hot_data')
    if week_hot_data is None:
        week_hot_data = get_7_days_hot_blogs()
        cache.set('week_hot_data', week_hot_data, 3600)

    context = {}
    context['read_nums'] = read_nums
    context['dates'] = dates
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['week_hot_data'] = week_hot_data
    return render(request, 'home.html', context)
Esempio n. 3
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_week_read_data(blog_content_type)

    # 设置缓存
    week_hot_data = get_week_hot_data()
    hot_blogs_for_week = cache.get('hot_blogs_for_week')
    if hot_blogs_for_week is None:
        hot_blogs_for_week = week_hot_data
        cache.set('hot_blogs_for_week', hot_blogs_for_week, 3600)

    context = {}
    context['dates'] = dates
    context['read_nums'] = read_nums
    context['today_hot_data'] = get_today_hot_data(blog_content_type)
    context['yesterday_hot_data'] = get_yesterday_hot_data(blog_content_type)
    context['week_hot_data'] = week_hot_data
    return render(request, 'home.html', context)
Esempio n. 4
0
def home(request):
    blog_content_type = ContentType.objects.get_for_model(Blog)
    dates, read_nums = get_week_read_data(blog_content_type)

    # 获取近一周热门博客的缓存数据
    week_hot_blogs = cache.get('week_hot_blogs')
    if week_hot_blogs is None:
        week_hot_blogs = get_week_hot_data()
        cache.set('week_hot_blogs', week_hot_blogs, 3600)

    context = {
        'dates': dates,
        'read_nums': read_nums,
        'today_hot_data': get_today_hot_data(blog_content_type),
        'yesterday_hot_data': get_yesterday_hot_data(blog_content_type),
        'week_hot_blogs': week_hot_blogs,
    }
    return render(request, 'home.html', context)