Ejemplo n.º 1
0
def blog_search(request):
    """
    实现对文章标题,标签,分类的搜索
    """
    is_search = True
    new_post = get_popular_top10_blogs('tmp_new_post')
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags',
                                               'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')
    error = False

    query = Q()
    s = request.GET.get('s') or ""
    if s:
        query &= (Q(title__icontains=s) | Q(classification__name=s)
                  | Q(tags__name=s))

    articles = Article.objects.filter(
        status=BlogStatus.PUBLISHED).filter(query)
    page_num = request.GET.get("page") or 1
    page_size = request.GET.get("page_size") or 5
    articles, total = paginate(articles,
                               page_num=page_num,
                               page_size=page_size)
    if total == 0:
        error = True

    return render(request, 'blog/index.html', locals())
Ejemplo n.º 2
0
def home(request):
    """
    博客首页
    """
    is_home = True
    articles = get_articles('tmp_articles')
    page_num = request.GET.get("page") or 1
    page_size = request.GET.get("page_size") or 5
    articles, total = paginate(articles, page_num=page_num, page_size=page_size)

    new_post = get_popular_top10_blogs('tmp_new_post')  # 阅读量最高的十篇文章
    classification = get_classifications('tmp_classification')  # 分类,以及对应的数目
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')  # 按月归档,以及对应的文章数目
    carouse_imgs = get_carousel_imgs('tmp_carouse_imgs', CarouselImgType.BANNER)  # 轮播图
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    return render(request, 'blog/index.html', locals())
Ejemplo n.º 3
0
def links(request):
    """
    友情链接
    """
    links = get_links('tmp_links')
    random.shuffle(links)  # 友情链接随机排序
    new_post = get_popular_top10_blogs('tmp_new_post')
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')
    return render(request, 'blog/links.html', locals())
Ejemplo n.º 4
0
def message(request):
    """
    主人寄语
    """
    own_messages = OwnerMessage.objects.all()
    own_message = random.sample(list(own_messages), 1)[0] if own_messages else ""  # 随机返回一个主人寄语
    date_list = get_date_list('tmp_date_list')
    classification = get_classifications('tmp_classification')
    new_post = get_popular_top10_blogs('tmp_new_post')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    return render(request, 'blog/message.html', locals())
Ejemplo n.º 5
0
def archive(request):
    """
    文章归档
    """
    archive = get_archieve('tmp_archive')
    new_post = get_popular_top10_blogs('tmp_new_post')
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/archive.html', locals())
Ejemplo n.º 6
0
def about(request):
    """
    关于我
    """
    new_post = get_popular_top10_blogs('tmp_new_post')
    comments = get_cache_comments(request.path)
    page_num = request.GET.get("page") or 1
    comments, total = paginate(comments, page_num=page_num)
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/about.html', locals())
Ejemplo n.º 7
0
def archive_month(request, year, month):
    is_arch_month = True

    articles = Article.objects.filter(publish_time__year=year, publish_time__month=month, status=BlogStatus.PUBLISHED)  # 当前日期下的文章列表
    page_num = request.GET.get("page") or 1
    page_size = request.GET.get("page_size") or 5
    articles, total = paginate(articles, page_num=page_num, page_size=page_size)

    new_post = get_popular_top10_blogs('tmp_new_post')
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())
Ejemplo n.º 8
0
def tagDetail(request, tag):
    is_tag, articles, total = True, [], 0
    temp = Tag.objects.filter(name=tag).first()
    if temp:
        articles = temp.article_set.filter(status=BlogStatus.PUBLISHED)
    page_num = request.GET.get("page") or 1
    page_size = request.GET.get("page_size") or 5
    articles, total = paginate(articles, page_num=page_num, page_size=page_size)

    new_post = get_popular_top10_blogs('tmp_new_post')
    classification = get_classifications('tmp_classification')
    tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
    ads_imgs = get_carousel_imgs('tmp_ads_imgs', CarouselImgType.ADS)  # 广告轮播图
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())