Пример #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')  # 获取所有标签,并随机赋予颜色
    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(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())
Пример #2
0
def blog_list(request):
    form = BlogListForm(request.GET)
    form.is_valid()
    query = Q(status=BlogStatus.PUBLISHED)

    title = form.cleaned_data.get("title")
    page_num = form.cleaned_data.get('page_num')
    page_size = form.cleaned_data.get('page_size')

    if title:
        query &= (Q(title__icontains=title) | Q(classification__name=title)
                  | Q(tags__name=title))

    blogs = Article.objects.select_related().filter(query).order_by("-id")
    blogs, total = paginate(blogs, page_num, page_size)
    blog_list = []
    for blog in blogs:
        blog_list.append({
            "blog_id": blog.id,
            "title": blog.title,
            "author": blog.author.name,
            "classification": blog.classification.name,
            "content": blog.content,
            "publish_time": blog.publish_time.strftime('%Y-%m-%d'),
            "count": blog.count
        })

    return http_response(request,
                         statuscode=ERRORCODE.SUCCESS,
                         context={
                             "blog_list": blog_list,
                             "total": total,
                             "page_num": page_num,
                             "page_size": page_size,
                         })
Пример #3
0
def carousel_list_view(request):
    """
    轮播图片列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    carousels = CarouselImg.objects.filter(query).order_by("-id")
    carousel_list, total = paginate(
        carousels,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/carousel_list.html', {
        "active_classes": ['.blog', '.carousel_list'],
        "params": request.GET,
        "data_list": carousel_list,
        "total": total,
        "name": name,
        "image_types": CarouselImgType.CHOICES
    })
Пример #4
0
def detail(request, year, month, day, id):
    """
    博客详情
    """
    try:
        article = Article.objects.get(id=id)
        article.count += 1
        article.save(update_fields=['count'])
        statis_count = Article.objects.filter(status=BlogStatus.PUBLISHED).aggregate(
            blog_count=Count('id'),
            read_count=Sum('count'),
            tags_count=Count('tags', distinct=True)
        )
        # 生成文章目录
        if article.editor == EditorKind.Markdown:
            md = markdown.Markdown(extensions=[
                'markdown.extensions.extra',
                'markdown.extensions.codehilite',
                'markdown.extensions.toc',
                'markdown.extensions.tables'
            ])
            article.content = md.convert(article.content)
            toc = md.toc
        # tag_list, music_list = get_tags_and_musics('tmp_tags', 'tmp_musics')  # 获取所有标签,并随机赋予颜色
        comments = get_cache_comments(request.path)
        page_num = request.GET.get("page") or 1
        comments, total = paginate(comments, page_num=page_num)
        return render(request, 'blog/content.html', locals())
    except Article.DoesNotExist:
        raise Http404
Пример #5
0
def blog_list(request):
    form = BlogListForm(request.GET)
    form.is_valid()
    query = Q(status=BlogStatus.PUBLISHED)

    title = form.cleaned_data.get("title")
    page_num = form.cleaned_data.get('page_num')
    page_size = form.cleaned_data.get('page_size')

    if title:
        query &= (Q(title__icontains=title) | Q(classification__name=title) | Q(tags__name=title))

    blogs = Article.objects.select_related().filter(query).order_by("-id")
    blogs, total = paginate(blogs, page_num, page_size)
    blog_list = []
    for blog in blogs:
        blog_list.append({
            "blog_id": blog.id,
            "title": blog.title,
            "author": blog.author.name,
            "classification": blog.classification.name,
            "content": blog.content,
            "publish_time": blog.publish_time.strftime('%Y-%m-%d'),
            "count": blog.count
        })

    return http_response(request, statuscode=ERRORCODE.SUCCESS, context={
        "blog_list": blog_list,
        "total": total,
        "page_num": page_num,
        "page_size": page_size,
    })
Пример #6
0
def blog_list_view(request):
    """
    博客列表
    :param request:
    :return:
    """
    form = SearchBlogForm(request.GET)
    form.is_valid()
    query = Q()
    title = form.cleaned_data.get("title")
    if title:
        query &= (Q(title__icontains=title) | Q(classification__name=title) | Q(tags__name=title))

    blogs = Article.objects.select_related().filter(query).order_by("-id")
    blog_list, total = paginate(
        blogs,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/blog_list.html', {
        "active_classes": ['.blog', '.blog_list'],
        "params": request.GET,
        "form": form,
        "data_list": blog_list,
        "total": total,
    })
Пример #7
0
def blog_list_view(request):
    """
    博客列表
    :param request:
    :return:
    """
    form = SearchBlogForm(request.GET)
    form.is_valid()
    query = Q()
    title = form.cleaned_data.get("title")
    if title:
        query &= (Q(title__icontains=title) | Q(classification__name=title)
                  | Q(tags__name=title))

    blogs = Article.objects.select_related().filter(query).order_by("-id")
    blog_list, total = paginate(blogs, request.GET.get('page') or 1)

    return render(
        request, 'manager/blog_list.html', {
            "active_classes": ['.blog', '.blog_list'],
            "params": request.GET,
            "form": form,
            "data_list": blog_list,
            "total": total,
        })
Пример #8
0
def get_comments_view(request):
    """
    获取评论列表
    """
    form = GetCommentsForm(request.GET)
    if not form.is_valid():
        return http_response(request, statuscode=ERRORCODE.PARAM_ERROR)

    page_num = form.cleaned_data.get('page_num') or 1
    page_size = form.cleaned_data.get('page_size') or 10
    target = form.cleaned_data.get('target')

    md = markdown.Markdown(extensions=[
        'markdown.extensions.extra',
        'markdown.extensions.codehilite',
        'markdown.extensions.toc',
    ])
    comment_list = []
    comments = get_cache_comments(target)
    comments, total = paginate(comments, page_num, page_size)
    for item in comments:
        comment_list.append({
            "comment_id":
            item.id,
            "anchor":
            item.anchor,
            "comment":
            md.convert(item.content),
            "avatar":
            item.user.avatar,
            "website":
            item.user.website,
            "nickname":
            item.user.nickname,
            "blogger":
            True if item.user.blogger else False,
            "created_time":
            item.created_time.strftime("%Y-%m-%d %H:%M"),
            "reply_to":
            True if item.reply_to else False,
            "reply_to_user":
            item.reply_to.nickname if item.reply_to else '',
            "parent_anchor":
            item.parent.anchor if item.parent else '',
            "parent_comment":
            md.convert(item.parent.content) if item.parent else ''
        })

    return http_response(request,
                         statuscode=ERRORCODE.SUCCESS,
                         context={
                             "comment_list": comment_list,
                             "total": total,
                             "page_num": page_num,
                             "page_size": page_size,
                         })
Пример #9
0
def ownmessage_list_view(request):
    messages = OwnerMessage.objects.order_by("-id")
    ownmessage_list, total = paginate(messages, request.GET.get('page') or 1)

    return render(
        request, 'manager/ownmessage_list.html', {
            "active_classes": ['.blog', '.ownmessage_list'],
            "params": request.GET,
            "data_list": ownmessage_list,
            "total": total,
        })
Пример #10
0
def ownmessage_list_view(request):
    messages = OwnerMessage.objects.order_by("-id")
    ownmessage_list, total = paginate(
        messages,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/ownmessage_list.html', {
        "active_classes": ['.blog', '.ownmessage_list'],
        "params": request.GET,
        "data_list": ownmessage_list,
        "total": total,
    })
Пример #11
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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/about.html', locals())
Пример #12
0
def links(request):
    """
    友情链接
    """
    links = get_links('tmp_links')
    comments = get_cache_comments(request.path)
    page_num = request.GET.get("page") or 1
    comments, total = paginate(comments, page_num=page_num)
    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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')
    return render(request, 'blog/links.html', locals())
Пример #13
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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())
Пример #14
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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())
Пример #15
0
def message(request):
    """
    主人寄语
    """
    comments = get_cache_comments(request.path)
    page_num = request.GET.get("page") or 1
    comments, total = paginate(comments, page_num=page_num)
    own_messages = OwnerMessage.objects.all()
    own_message = random.sample(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')  # 获取所有标签,并随机赋予颜色
    return render(request, 'blog/message.html', locals())
Пример #16
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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())
Пример #17
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')  # 获取所有标签,并随机赋予颜色
    date_list = get_date_list('tmp_date_list')

    return render(request, 'blog/index.html', locals())
Пример #18
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')  # 轮播图
    return render(request, 'blog/index.html', locals())
Пример #19
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')  # 轮播图

    return render(request, 'blog/index.html', locals())
Пример #20
0
def classfiDetail(request, classfi):
    """
    按分类查找
    """
    is_classfi, articles, total = True, [], 0
    temp = Classification.objects.filter(name__icontains=classfi).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())
Пример #21
0
def comment_list_view(request):
    comments = Comments.objects.order_by("-id")
    comments_list, total = paginate(comments, request.GET.get('page') or 1)
    for item in comments_list:
        item.address = item.country + item.province + item.city
        if item.target == "/about":
            comment_type = u"关于我"
        elif item.target == "/links":
            comment_type = u"友情链接"
        elif item.target == "/message":
            comment_type = u"留言板"
        elif item.target.startswith("/article"):
            comment_type = u"博客详情"
        item.comment_type = comment_type
    return render(
        request, 'manager/comment_list.html', {
            "active_classes": ['.blog', '.comment_list'],
            "params": request.GET,
            "data_list": comments_list,
            "total": total,
        })
Пример #22
0
def music_list_view(request):
    """
    背景音乐列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    musics = Music.objects.filter(query).order_by("-id")
    music_list, total = paginate(musics, request.GET.get('page') or 1)

    return render(
        request, 'manager/music_list.html', {
            "active_classes": ['.blog', '.music_list'],
            "params": request.GET,
            "data_list": music_list,
            "total": total,
            "name": name
        })
Пример #23
0
def tag_list_view(request):
    """
    文章标签列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    tags = Tag.objects.filter(query).order_by("-id")
    tag_list, total = paginate(tags, request.GET.get('page') or 1)

    return render(
        request, 'manager/tag_list.html', {
            "active_classes": ['.blog', '.tag_list'],
            "params": request.GET,
            "data_list": tag_list,
            "total": total,
            "name": name
        })
Пример #24
0
def friend_link_list_view(request):
    """
    友情链接列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    links = Links.objects.filter(query).order_by("-id")
    link_list, total = paginate(links, request.GET.get('page') or 1)

    return render(
        request, 'manager/link_list.html', {
            "active_classes": ['.blog', '.link_list'],
            "params": request.GET,
            "data_list": link_list,
            "total": total,
            "name": name
        })
Пример #25
0
def classification_list_view(request):
    """
    文章分类列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    classifications = Classification.objects.filter(query).order_by("-id")
    classification_list, total = paginate(classifications,
                                          request.GET.get('page') or 1)

    return render(
        request, 'manager/classification_list.html', {
            "active_classes": ['.blog', '.classification_list'],
            "params": request.GET,
            "data_list": classification_list,
            "total": total,
            "name": name
        })
Пример #26
0
def get_comments_view(request):
    form = GetCommentsForm(request.GET)
    if not form.is_valid():
        return http_response(request, statuscode=ERRORCODE.PARAM_ERROR)

    page_num = form.cleaned_data.get('page_num') or 1
    page_size = form.cleaned_data.get('page_size') or 10
    target = form.cleaned_data.get('target')

    comment_list = []
    comments = Comments.objects.select_related().filter(target=target).order_by('-id')
    comments, total = paginate(comments, page_num, page_size)
    for item in comments:
        comment_list.append({
            "anchor": item.anchor
        })

    return http_response(request, statuscode=ERRORCODE.SUCCESS, context={
        "comments": comment_list,
        "total": total,
        "page_num": page_num,
        "page_size": page_size,
    })
Пример #27
0
def tag_list_view(request):
    """
    文章标签列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    tags = Tag.objects.filter(query).order_by("-id")
    tag_list, total = paginate(
        tags,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/tag_list.html', {
        "active_classes": ['.blog', '.tag_list'],
        "params": request.GET,
        "data_list": tag_list,
        "total": total,
        "name": name
    })
Пример #28
0
def carousel_list_view(request):
    """
    轮播图片列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    carousels = CarouselImg.objects.filter(query).order_by("-id")
    carousel_list, total = paginate(
        carousels,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/carousel_list.html', {
        "active_classes": ['.blog', '.carousel_list'],
        "params": request.GET,
        "data_list": carousel_list,
        "total": total,
        "name": name
    })
Пример #29
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')  # 获取所有标签,并随机赋予颜色
    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(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())
Пример #30
0
def friend_link_list_view(request):
    """
    友情链接列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    links = Links.objects.filter(query).order_by("-id")
    link_list, total = paginate(
        links,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/link_list.html', {
        "active_classes": ['.blog', '.link_list'],
        "params": request.GET,
        "data_list": link_list,
        "total": total,
        "name": name
    })
Пример #31
0
def music_list_view(request):
    """
    背景音乐列表
    :param request:
    :return:
    """
    query = Q()
    name = request.GET.get('name')
    if name:
        query &= Q(name__icontains=name)

    musics = Music.objects.filter(query).order_by("-id")
    music_list, total = paginate(
        musics,
        request.GET.get('page') or 1
    )

    return render(request, 'manager/music_list.html', {
        "active_classes": ['.blog', '.music_list'],
        "params": request.GET,
        "data_list": music_list,
        "total": total,
        "name": name
    })