Example #1
0
def blogs(request):
    '''blog list'''
    html_dict = {}
    
    page = request.GET.get('page', '1')
    try:
        page_num = int(page)
    except:
        page_num = 1

    qs = Blog.objects.all().order_by('-id')
    
    #分页
    PAGE_MSG_NUM = 10
    split_dict = gcommon.split_page(request, page_num, PAGE_MSG_NUM, qs)
    html_dict.update(split_dict)
    
    #限制长度
    article_list = split_dict['split_list']
    for article in article_list:
        article.content = article.content[:800]
    
    db_tools.get_category_latelyblogs(html_dict)
    
    return render_to_response('blog/articles.html', html_dict, context_instance=RequestContext(request))
Example #2
0
def blogs(request):
    """blog list"""
    page = request.GET.get("page", "1")
    try:
        page_num = int(page)
    except:
        page_num = 1

    html_dict = {}
    PAGE_MSG_NUM = 10

    qs = Blog.objects.all().order_by("-id")

    all_msg_num = qs.count()

    _offset = (page_num - 1) * PAGE_MSG_NUM
    article_list = qs[_offset : _offset + PAGE_MSG_NUM]

    for article in article_list:
        article.content = article.content[:800]
    html_dict["article_list"] = article_list
    db_tools.get_category_latelyblogs(html_dict)

    split_dict = gcommon.split_page(page_num, PAGE_MSG_NUM, all_msg_num)
    html_dict.update(split_dict)

    print split_dict

    return render_to_response("articles.html", html_dict)
Example #3
0
def category(request, cid):
    '''分类'''
    html_dic = {}
    category_set = Category.objects.filter(id=cid)
    if not category_set:
        return HttpResponseRedirect('/blog/')

    cate = category_set[0]
    article_list = cate.blog_set.all()
    html_dic['article_list'] = article_list
    db_tools.get_category_latelyblogs(html_dic)
    return render_to_response('blog/articles.html', html_dic)
Example #4
0
def category(request, cid):
    """分类"""
    html_dic = {}
    category_set = Category.objects.filter(id=cid)
    if not category_set:
        return HttpResponseRedirect("/blog/")

    cate = category_set[0]
    article_list = cate.blog_set.all()
    html_dic["article_list"] = article_list
    db_tools.get_category_latelyblogs(html_dic)
    return render_to_response("articles.html", html_dic)
Example #5
0
def blog(request, blogid):
    article_set = Blog.objects.filter(id=blogid)

    article = article_set[0]
    visit_times = article.visit_times + 1
    article_set.update(visit_times=visit_times)

    comment_list = article.comment_set.all()
    comment_len = len(comment_list)

    html_dic = {"article": article, "comment_list": comment_list, "comment_len": comment_len}
    db_tools.get_category_latelyblogs(html_dic)
    return render_to_response("article.html", html_dic, context_instance=RequestContext(request))
Example #6
0
def modifyblog(request, bid):
    html_dic = {}
    article = Blog.objects.filter(id=bid)[0]

    category_str = ''
    cate_set = article.categorys.all()
    for cate in cate_set:
        category_str += cate.name
        category_str += ', '
    article.category_str = category_str
    
    html_dic['article'] = article
    db_tools.get_category_latelyblogs(html_dic)
    return render_to_response('blog/writeblog.html', html_dic, context_instance=RequestContext(request))
Example #7
0
def modifyblog(request, bid):
    html_dic = {}
    article_set = Blog.objects.filter(id=bid)
    article = article_set[0]

    category_str = ""
    cate_set = article.categorys.all()
    for cate in cate_set:
        # print cate.name
        category_str += cate.name
        category_str += ", "
    article.category_str = category_str

    html_dic["article"] = article
    db_tools.get_category_latelyblogs(html_dic)
    return render_to_response("writeblog.html", html_dic, context_instance=RequestContext(request))
Example #8
0
def blog(request, blogid):
    try:
        article = Blog.objects.get(id=blogid)
        article.visit_times += 1
        article.save()
    except Blog.DoesNotExist:
        return HttpResponseRedirect('/')
    
    page = request.GET.get('page', '1')
    try:
        page_num = int(page)
    except:
        page_num = 1
    
    qs = article.comment_set.all().order_by('id')
    
    html_dict = {'article': article,}
    db_tools.get_category_latelyblogs(html_dict)

    #分页
    PAGE_MSG_NUM = 10
    split_dict = gcommon.split_page(request, page_num, PAGE_MSG_NUM, qs)
    html_dict.update(split_dict)

    username = request.POST.get('username', '').strip()
    content = request.POST.get('content', '').strip()
    if not username and not content:
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
        
    if len(username) < 4 or len(content) < 4:
        html_dict['remind_msg'] = u'名称和内容不能少于4个字符'
        return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
    
    comment = Comment()
    comment.blog = Blog.objects.get(id=blogid)
    comment.blog.comment_times += 1
    comment.blog.save()
    comment.submit_name = username
    comment.content = content
    comment.ip = gcommon.get_remote_addr(request) #request.META['REMOTE_ADDR']
    comment.save()

    return render_to_response('blog/article.html', html_dict, context_instance=RequestContext(request))
Example #9
0
def writeblog(request):
    html_dict = {}
    db_tools.get_category_latelyblogs(html_dict)
    return render_to_response('blog/writeblog.html', html_dict, context_instance=RequestContext(request))