def user_message(req): try: # 获取Cookies判断用户是否已登陆 username = get_cookies(req, 'username') if username: my_list = user_dao.get_messages(user_dao.get_user_id(username)) obj_list = [] i = 0 # 获取未读的信息 for x in my_list: name = user_dao.get_user_name(x.c_user_give) ava = user_dao.get_user_avatar(x.c_user_give) time = x.c_time.strftime('%Y-%m-%d %H:%M:%S') obj_list.append({ 'id': x.c_id, 'name': name, 'ava': ava, 'con': x.c_content, 'uid': x.c_user_give, 'time': time, 'cat': int(x.c_category), 'item': x.c_item_id }) i += 1 con = Context({'username': username, 'obj': obj_list, 'count': i}) return render(req, 'message.html', con) else: return redirect('/index/') except Exception as e: print(e) return render(req, 'error.html') else: pass
def get_com_children(req, qid, page): try: com_list = dao.get_com_children_page(qid, int(page), 10) obj_list = [] page_all = dao.count_com_children_page(qid, 10) for x in com_list: cid = x.c_id con = x.c_content ava = user_dao.get_user_avatar(x.c_user_give) user = user_dao.get_user_name(x.c_user_give) urev = user_dao.get_user_name(x.c_user_recive) time = x.c_time.strftime('%Y-%m-%d %H:%M:%S') give_link = reverse('user_other', args=(x.c_user_give,)) recv_link = reverse('user_other', args=(x.c_user_recive,)) obj_list.append({'c_ava': ava, 'c_uid': user, 'c_time': time, 'c_id': cid, 'u_give': x.c_user_give, 'c_con': con, 'c_rid': urev, 'p_all': page_all, 'p_this': int(page), 'glink': give_link, 'rlink': recv_link}) except Exception as e: print(e) return render(req, 'error.html') else: return JsonResponse(obj_list, safe=False)
def get_com(req, cat, qid, page): try: com_list = dao.get_com_page(cat, qid, int(page), 10) obj_list = [] page_all = dao.count_com_page(cat, qid, 10) for x in com_list: ava = user_dao.get_user_avatar(x.c_user_give) name = user_dao.get_user_name(x.c_user_give) time = x.c_time.strftime('%Y-%m-%d %H:%M:%S') rep = dao.count_com_reply(cat, qid, x.c_id) c_link = str(reverse('com_children', args=(x.c_id, 1))) u_link = str(reverse('user_other', args=(x.c_user_give,))) obj_list.append({'c_ava': ava, 'c_id': x.c_user_give, 'c_name': name, 'c_rep': rep, 'c_time': time, 'c_flt': 1, 'c_con': x.c_content, 'c_com_id': int(x.c_id), 'page_all': int(page_all), 'page_this': int(page), 'com_link': c_link, 'user_link': u_link}) obj_list.reverse() except Exception as e: print(e) return render(req, 'error.html') else: return JsonResponse(obj_list, safe=False)
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)
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 user_recv(self): return get_user_name(self.c_user_recive)
def user_give(self): return get_user_name(self.c_user_give)
def usr(self): return get_user_name(self.t_user)
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)