示例#1
0
def detail(req, mid):
    try:
        # 获取Cookies判断用户是否已登陆
        username = get_cookies(req, 'username')
        u = user_dao.get_user_info(username)
        obj_hot = dao.the_most_hot()
        obj_new = dao.the_most_new()
        page_all = dao.count_com_page(3, mid, 10)
        # 获取具体记录并返回
        det = picture_dao.article_detail(mid)
        picture_dao.read_num(mid)
        my_detail = {
            'a_id': det.p_id,
            'a_user': user_dao.get_user_name(det.p_user),
            'a_title': det.p_title,
            'a_content': det.p_content,
            'a_kind': "摄影佳作",
            'a_cat': 3,
            'u_id': det.p_user,
            'a_time': det.p_release_time.strftime('%Y-%m-%d %H:%M:%S'),
            'a_url': det.p_url,
            'a_read': det.p_read,
            'a_thumb': det.p_thumb,
            'a_com': picture_dao.get_com_count(det.p_id)
        }
        con = Context({
            'username': username,
            'u': u,
            'detail': my_detail,
            'obj_hot': obj_hot,
            'obj_new': obj_new,
            'page_all': page_all,
            'page_this': 1
        })
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        return render(req, 'detail.html', con)
示例#2
0
def index(req, crt_page):
    try:
        # 获取Cookies判断用户是否已登陆
        username = get_cookies(req, 'username')
        u = user_dao.get_user_info(username)
        obj_hot = dao.the_most_hot()
        obj_new = dao.the_most_new()
        # 查询所有头条
        list_obs = []
        page_all = picture_dao.count_page(5)
        my_list = picture_dao.get_page(int(crt_page), 5)
        for x in my_list:  # 内容
            com_num = picture_dao.get_com_count(x.p_id)
            list_obs.append({
                'title': x.p_title,
                'url': x.p_url,
                'content': x.p_content,
                'id': x.p_id,
                'time': str(x.p_release_time),
                'read': x.p_read,
                'thumb': x.p_thumb,
                'com_num': com_num
            })
        con = Context({
            'username': username,
            'u': u,
            'obj': list_obs,
            'page_all': page_all,
            'page_this': int(crt_page),
            'site_title': "摄影佳作",
            'cat': 3,
            'obj_hot': obj_hot,
            'obj_new': obj_new
        })
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        return render(req, 'index.html', con)
示例#3
0
def search_all(req, crt_page, q):
    try:
        # 获取Cookies判断用户是否已登陆
        username = get_cookies(req, 'username')
        u = user_dao.get_user_info(username)
        obj_hot = dao.the_most_hot()
        obj_new = dao.the_most_new()
        # 获取全部的信息的页面数
        sql = """
            SELECT
            (SELECT COUNT(*) FROM pz_topic WHERE t_title LIKE '%""" + str(
                q.encode('utf-8')) + """%' OR t_content LIKE '%""" + str(q.encode('utf-8')) + """%') +
            (SELECT COUNT(*) FROM pz_skill WHERE s_title LIKE '%""" + str(
                q.encode('utf-8')) + """%' OR s_content LIKE '%""" + str(q.encode('utf-8')) + """%') +
            (SELECT COUNT(*) FROM pz_picture WHERE p_title LIKE '%""" + str(
                q.encode('utf-8')) + """%' OR p_content LIKE '%""" + str(q.encode('utf-8')) + """%') +
            (SELECT COUNT(*) FROM pz_equipment WHERE e_title LIKE '%""" + str(
                q.encode('utf-8')) + """%' OR e_content LIKE '%""" + str(q.encode('utf-8')) + """%')
            AS data;
        """
        alpage = int(dao.get_one_db(sql)[0])
        # 获取首页的信息
        count = 20

        all_page = alpage / count
        temp = alpage % count
        if temp != 0:
            all_page += 1

        sql = """
            SELECT * FROM (
            select t_id as id, t_title as title, t_content as content, t_read as read1,
            t_thumb as thumb, t_release_time as time, 'topic' as type from pz_topic union all
            select s_id as id, s_title as title, s_content as content, s_read as read1,
            s_thumb as thumb, s_release_time as time, 'skill' as type from pz_skill union all
            select p_id as id, p_title as title, p_content as content, p_read as read1,
            p_thumb as thumb, p_release_time as time, 'picture' as type from pz_picture union all
            select e_id as id, e_title as title, e_content as content, e_read as read1,
            e_thumb as thumb, e_release_time as time, 'equipment' as type from pz_equipment
            ) AS T WHERE title LIKE '%""" + str(q.encode('utf-8')) + """%' OR content LIKE '%""" + str(
                q.encode('utf-8')) + """
            %' ORDER BY time DESC LIMIT """ + str(count * (int(crt_page) - 1)) + ", " + str(count) + ";"
        my_list = dao.get_all_db(sql)
        obj_list = []
        for x in my_list:
            if x[6] == 'topic':
                cat = 1
                num = topic_dao.get_com_count(x[0])
            elif x[6] == 'skill':
                cat = 2
                num = skill_dao.get_com_count(x[0])
            elif x[6] == 'picture':
                cat = 3
                num = picture_dao.get_com_count(x[0])
            elif x[6] == 'equipment':
                cat = 4
                num = equipment_dao.get_com_count(x[0])
            else:
                cat = 0
            time = x[5].strftime('%Y-%m-%d %H:%M:%S')
            obj_list.append({'id': x[0], 'title': x[1],
                             'content': x[2], 'read': x[3], 'thumb': x[4],
                             'time': time, 'cat': cat, 'com_num': int(num)})
        con = Context({'username': username, 'u': u, 'site_title': "首页", 'q': q,
                       'obj_hot': obj_hot, 'obj_new': obj_new, 'obj': obj_list, 'qn': alpage,
                       'page_all': all_page, 'page_this': int(crt_page)})
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        return render(req, 'search.html', con)
示例#4
0
def index(req, crt_page):
    try:
        # 获取Cookies判断用户是否已登陆
        username = get_cookies(req, 'username')
        u = user_dao.get_user_info(username)
        obj_hot = dao.the_most_hot()
        obj_new = dao.the_most_new()
        # 获取全部的信息的页面数
        sql = """
            SELECT
            (select count(*) from pz_topic) +
            (select count(*) from pz_skill) +
            (select count(*) from pz_picture) +
            (select count(*) from pz_equipment)
            AS data;
        """
        alpage = int(dao.get_one_db(sql)[0])
        # 获取首页的信息
        count = 5

        all_page = alpage / count
        temp = alpage % count
        if temp != 0:
            all_page += 1

        sql = """
            select t_id as id, t_url as url, t_title as title, t_content as content, t_read as read1,
            t_thumb as thumb, t_release_time as time, 'topic' as type from pz_topic union all
            select s_id as id, s_url as url, s_title as title, s_content as content, s_read as read1,
            s_thumb as thumb, s_release_time as time, 'skill' as type from pz_skill union all
            select p_id as id, p_url as url, p_title as title, p_content as content, p_read as read1,
            p_thumb as thumb, p_release_time as time, 'picture' as type from pz_picture union all
            select e_id as id, e_url as url, e_title as title, e_content as content, e_read as read1,
            e_thumb as thumb, e_release_time as time, 'equipment' as type from pz_equipment order by time desc LIMIT
        """ + str(count * (int(crt_page) - 1)) + ", " + str(count) + ";"
        my_list = dao.get_all_db(sql)
        obj_list = []
        for x in my_list:
            if x[7] == 'topic':
                cat = 1
                num = topic_dao.get_com_count(x[0])
            elif x[7] == 'skill':
                cat = 2
                num = skill_dao.get_com_count(x[0])
            elif x[7] == 'picture':
                cat = 3
                num = picture_dao.get_com_count(x[0])
            elif x[7] == 'equipment':
                cat = 4
                num = equipment_dao.get_com_count(x[0])
            else:
                cat = 0
            time = x[6].strftime('%Y-%m-%d %H:%M:%S')
            obj_list.append({'id': x[0], 'url': x[1], 'title': x[2],
                             'content': x[3], 'read': x[4], 'thumb': x[5],
                             'time': time, 'cat': cat, 'com_num': int(num)})
        con = Context(
                {'username': username, 'u': u, 'site_title': "首页",
                 'obj_hot': obj_hot, 'obj_new': obj_new, 'obj': obj_list,
                 'page_all': all_page, 'page_this': int(crt_page)})
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        return render(req, 'index.html', con)