Beispiel #1
0
def search(request):
    """
    ===============================================================================
    function:    博客搜索
    developer:    BeginMan
    add-time      2014/1/7
    ===============================================================================
    """
    context = {}
    try:
        if request.method == 'GET':
            search_text = request.GET.get('search')
            page = request.GET.get('page', 1)
            sql = u"""select id, title from blog_article where title like '%%%%%s%%%%'""" % search_text
            fetchall = ExecuteSql(sql)

            result = get_page_result(page, fetchall, 20)
            search_result = []
            for obj in result.object_list:
                dic = {}
                dic['id'] = obj[0]
                dic['title'] = obj[1]
                search_result.append(dic)
            context['search_result'] = search_result
            context['result'] = result
            context['search_text'] = search_text

    except Exception, e:
        log.error('blog/search:%s' %e)
        return HttpResponse('err')
Beispiel #2
0
def list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/8
    ===============================================================================
    """
    context = {}
    if request.method == "POST":
        blog = Blog.objects.filter(status=1, istop=0).order_by('-add_time')
        page = request.POST.get('page')
        # 最新博客(12个一分页)

        new_blogs = get_page_result(page, blog, 12)

        blog_list = []
        for obj in new_blogs.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
        context['new_blogs'] = new_blogs
    return render_template(request, 'blog/list.html', context)
Beispiel #3
0
def category(request, id=None):
    """
    ===============================================================================
    function:    博客搜索
    developer:    BeginMan
    add-time      2014/1/7
    ===============================================================================
    """
    context = {}
    if request.method == "GET":
        if not id:
            return HttpResponseRedirect('/404/')
        category = Category.objects.get(pk=id)
        blogs = Blog.objects.filter(category_id__id=id, status=1).order_by('-add_time')
        page = request.GET.get('page', None)
        result = get_page_result(page, blogs, 20)
        context['result'] = result
        context['category_title'] = category.title
        context['num'] = len(blogs)

        blog_list = []
        for obj in result.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
    return render_template(request, 'blog/category.html', context)
Beispiel #4
0
def tag(request, id=None):
    """
    ===============================================================================
    function:    博客搜索
    developer:    BeginMan
    add-time      2014/1/7
    ===============================================================================
    """
    context = {}
    if request.method == "GET":
        if not id:
            return HttpResponseRedirect('/404/')
        tag = Tags.objects.get(pk=id)
        tag_name = tag.name
        b_list = []
        blogList = Blog.objects.filter(status=1).order_by('-add_time')
        for obj in blogList.extra(where=['length(tags)>0']):        # 获取标签不为空的
            if tag_name in [i for i in obj.tags.split('|') if i]:        # 如果该标签在其中则填充
                b_list.append(obj)

        page = request.GET.get('page', None)
        result = get_page_result(page, b_list, 20)
        context['result'] = result
        context['tag_name'] = tag_name
        context['num'] = len(b_list)

        blog_list = []
        for obj in result.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
    return render_template(request, 'blog/tag.html', context)
Beispiel #5
0
def manager_list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/14
    ===============================================================================
    """
    try:
        context = {}
        if request.method == "POST":
            categoryId = request.POST.get("categoryId")  # 分类
            date1 = request.POST.get("date1")  # 日期1
            date2 = request.POST.get("date2")  # 日期2
            is_top = request.POST.get("is_top")  # 是否置顶 2全部 1置顶;0不置顶
            status = request.POST.get("status")  # 状态 2全部;1分布;0草稿
            title = request.POST.get("title")  # 搜索的标题

            transList = Translate.objects.filter(status__lt=2).order_by("-add_time")
            if categoryId != "0":
                if TransCategory.objects.get(pk=categoryId).parent_id == 0:  # 父分类
                    c_id_list = list(TransCategory.objects.filter(parent_id=categoryId).values_list("id", flat=True))
                    c_id_list.append(int(categoryId))
                    transList = Translate.objects.filter(category__id__in=c_id_list, status__lt=2)
                else:
                    transList = Translate.objects.filter(category__id=categoryId, status__lt=2)

            if is_top != "2":
                transList = transList.filter(istop=is_top)

            if status != "2":
                transList = transList.filter(status=status)
            if title:
                transList = transList.filter(title__icontains=title)  # icontains 不区分大小写

            # 日期
            start = datetime.date(2013, 1, 1)  # 起始时间
            if date1 and date2:
                split_date1 = date1.split("-")
                split_date2 = date2.split("-")
                d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                transList = transList.filter(add_time__range=(d_date1, d_date2))
            else:
                if date1:
                    split_date1 = date1.split("-")
                    d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                    transList = transList.filter(add_time__range=(start, d_date1))

                if date2:
                    split_date2 = date2.split("-")
                    d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                    transList = transList.filter(add_time__range=(start, d_date2))

            page = request.POST.get("page", "1")
            trans = get_page_result(page, transList, 20)
            context["trans"] = trans
            return render_template(request, "translate/manager_list.html", context)

    except Exception, e:
        log.error("translate/manager_list:%s" % e)
        return HttpResponse("err")