def user_post(req): try: username = get_cookies(req, 'username') if username: list_obs = [] page_all = topic_dao.count_page_u(10, user_dao.get_user_id(username)) my_list = topic_dao.get_page_u(1, 10, user_dao.get_user_id(username)) for x in my_list: # 内容 com_num = topic_dao.get_com_count(x.t_id) list_obs.append({ 'title': x.t_title, 'id': x.t_id, 'time': str(x.t_release_time), 'read': x.t_read, 'thumb': x.t_thumb, 'com_num': com_num, 'cat': 1 }) con = Context({ 'username': username, 'obj': list_obs, 'page_all': page_all, 'page_this': 1 }) return render(req, 'post.html', con) else: return redirect('/index/') except Exception as e: print(e) return render(req, 'error.html') else: pass
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(1, mid, 10) # 获取具体记录并返回 det = topic_dao.article_detail(mid) topic_dao.read_num(mid) my_detail = { 'a_id': det.t_id, 'a_user': user_dao.get_user_name(det.t_user), 'a_title': det.t_title, 'a_content': det.t_content, 'a_kind': "摄影头条", 'a_cat': 1, 'u_id': det.t_user, 'a_time': det.t_release_time.strftime('%Y-%m-%d %H:%M:%S'), 'a_url': det.t_url, 'a_read': det.t_read, 'a_thumb': det.t_thumb, 'a_com': topic_dao.get_com_count(det.t_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)
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 = topic_dao.count_page(5) my_list = topic_dao.get_page(int(crt_page), 5) for x in my_list: # 内容 com_num = topic_dao.get_com_count(x.t_id) list_obs.append({ 'title': x.t_title, 'url': x.t_url, 'content': x.t_content, 'id': x.t_id, 'time': str(x.t_release_time), 'read': x.t_read, 'thumb': x.t_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': 1, '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)
def user_other(req, uid): try: u = user_dao.get_user_info2(user_dao.get_user_name(int(uid))) list_obs = [] my_list = topic_dao.get_page_u(1, 10, int(uid)) for x in my_list: # 内容 com_num = topic_dao.get_com_count(x.t_id) list_obs.append({ 'title': x.t_title, 'id': x.t_id, 'time': str(x.t_release_time), 'read': x.t_read, 'thumb': x.t_thumb, 'com_num': com_num, 'cat': 1 }) con = Context({'u': u, 'obj': list_obs}) return render(req, 'other.html', con) except Exception as e: print(e) return render(req, 'error.html') else: pass
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)
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)
def user_other_json(req, uid, cat, page): try: username = user_dao.get_user_name(int(uid)) list_obs = [] p = int(page) if int(cat) == 1: page_all = topic_dao.count_page_u(10, user_dao.get_user_id(username)) my_list = topic_dao.get_page_u(p, 10, user_dao.get_user_id(username)) elif int(cat) == 2: page_all = picture_dao.count_page_u(10, user_dao.get_user_id(username)) my_list = picture_dao.get_page_u(p, 10, user_dao.get_user_id(username)) elif int(cat) == 3: page_all = skill_dao.count_page_u(10, user_dao.get_user_id(username)) my_list = skill_dao.get_page_u(p, 10, user_dao.get_user_id(username)) elif int(cat) == 4: page_all = equipment_dao.count_page_u( 10, user_dao.get_user_id(username)) my_list = equipment_dao.get_page_u(p, 10, user_dao.get_user_id(username)) else: pass for x in my_list: # 内容 if int(cat) == 1: com_num = topic_dao.get_com_count(x.t_id) list_obs.append({ 'title': x.t_title, 'id': x.t_id, 'time': str(x.t_release_time), 'read': x.t_read, 'thumb': x.t_thumb, 'com_num': com_num, 'cat': 1, 'page_all': page_all, 'page_this': int(page) }) elif int(cat) == 2: com_num = picture_dao.get_com_count(x.p_id) list_obs.append({ 'title': x.p_title, 'id': x.p_id, 'time': str(x.p_release_time), 'read': x.p_read, 'thumb': x.p_thumb, 'com_num': com_num, 'cat': 2, 'page_all': page_all, 'page_this': int(page) }) elif int(cat) == 3: com_num = skill_dao.get_com_count(x.s_id) list_obs.append({ 'title': x.s_title, 'id': x.s_id, 'time': str(x.s_release_time), 'read': x.s_read, 'thumb': x.s_thumb, 'com_num': com_num, 'cat': 3, 'page_all': page_all, 'page_this': int(page) }) elif int(cat) == 4: com_num = equipment_dao.get_com_count(x.e_id) list_obs.append({ 'title': x.e_title, 'id': x.e_id, 'time': str(x.e_release_time), 'read': x.e_read, 'thumb': x.e_thumb, 'com_num': com_num, 'cat': 4, 'page_all': page_all, 'page_this': int(page) }) else: pass except Exception as e: print(e) return render(req, 'error.html') else: return JsonResponse(list_obs, safe=False)