示例#1
0
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
示例#2
0
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
示例#3
0
def index(req):
    try:
        # 获取Cookies判断用户是否已登陆
        username = get_cookies(req, 'username')
        if username:
            u = user_dao.get_user_info2(username)
            # 获取首页的信息
            count = 10
            sql = """
                 select t_id as id, t_title as title, t_read as read1, t_thumb as thumb, t_release_time as time, 'topic'
                 as type from pz_topic where t_user = """ + str(
                u['uid']) + """ union all
                 select s_id as id, s_title as title, s_read as read1, s_thumb as thumb, s_release_time as time, 'skill'
                 as type from pz_skill where s_user = """ + str(
                    u['uid']) + """ union all
                 select p_id as id, p_title as title, p_read as read1, p_thumb as thumb, p_release_time as time, 'picture'
                 as type from pz_picture where p_user = """ + str(
                        u['uid']) + """ union all
                 select e_id as id, e_title as title, e_read as read1, e_thumb as thumb, e_release_time as time, 'equipment'
                 as type from pz_equipment where e_user = """ + str(
                            u['uid']) + """
                 order by time desc LIMIT
            """ + str(count) + ";"
            my_list = user_dao.get_all_db(sql)
            obj_list = []
            for x in my_list:
                if x[5] == 'topic':
                    cat = 1
                    num = user_dao.get_com_count(x[0], cat)
                elif x[5] == 'skill':
                    cat = 2
                    num = user_dao.get_com_count(x[0], cat)
                elif x[5] == 'picture':
                    cat = 3
                    num = user_dao.get_com_count(x[0], cat)
                elif x[5] == 'equipment':
                    cat = 4
                    num = user_dao.get_com_count(x[0], cat)
                else:
                    cat = 0
                time = x[4].strftime('%Y-%m-%d %H:%M:%S')
                obj_list.append({
                    'id': x[0],
                    'title': x[1],
                    'read': x[2],
                    'thumb': x[3],
                    'time': time,
                    'cat': cat,
                    'com_num': int(num)
                })
            con = Context({'username': username, 'u': u, 'obj': obj_list})
            return render(req, 'center.html', con)
        else:
            return redirect('/index/')
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#4
0
def mark_read(req):
    try:
        if req.method == "POST":
            username = get_cookies(req, 'username')
            qid = req.POST['id']
            if username and user_dao.set_read(int(qid),
                                              user_dao.get_user_id(username)):
                return HttpResponse(1)
            else:
                return HttpResponse(0)
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#5
0
def avatar_change(req):
    try:
        username = get_cookies(req, 'username')
        if username:
            if req.method == "POST":
                pic = req.FILES.get("pic", None)
                path = store_pic(pic, 'avatar')
                img = user_dao.update_user_avatar(
                    user_dao.get_user_id(username), path[1:])
                response = HttpResponse(0)
                response.set_cookie("img", img)
            return response
        else:
            return user_info(req)
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#6
0
def user_info(req):
    try:
        username = get_cookies(req, 'username')
        if username:
            meta = user_dao.get_user_info2(username)
            obj_dict = {
                'id': meta['uid'],
                'ava': meta['ava'],
                'name': username,
                'desp': meta['dep']
            }
            con = Context({'username': username, 'obj': obj_dict})
            return render(req, 'info.html', con)
        else:
            return redirect('/index/')
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#7
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)
示例#8
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)
示例#9
0
def login(req, url):
    try:
        # response = redirect(url)
        response = HttpResponse("<script>window.history.back(-1);</script>")
        # 判断是否有Cookies存在,有则清空
        if get_cookies(req, 'username') is not None:
            response.delete_cookie('username')
        # 接收Post信息并判断是否可以登陆
        if req.method == 'POST':
            uf = UserForm(req.POST)
            if uf.is_valid():
                # 获得表单数据
                username = uf.cleaned_data['username']
                password = uf.cleaned_data['password']
                # 查询判断
                my_user = user_dao.get_users(username)
                if my_user:
                    db_pwd = user_dao.get_user(username).u_password
                    if check_password(password, db_pwd):
                        # 比较成功
                        # 将username写入浏览器cookie,失效时间为3600 * 3
                        response.set_cookie('username', rc4encode(username),
                                            10800)
                        user_dao.add_credit(user_dao.get_user_id(username), 5)
                        return response
                # 不可以登陆则自动注册
                # pbkdf2_sha256加密算法
                str_pwd = make_password(password, 'pbkdf2_sha256')
                # 添加到数据库
                user_dao.new_user(username, str_pwd)
                # 将username写入浏览器cookie,失效时间为3600 * 3
                response.set_cookie('username', rc4encode(username), 10800)
                return response
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        # print response, url
        return response
示例#10
0
def fetch_user_info(req):
    try:
        username = get_cookies(req, 'username')
        if username:
            desp = req.POST['description']
            pwd = req.POST['password']
            pwd2 = req.POST['password2']
            # print(desp, pwd, pwd2)
            if pwd == pwd2:
                p = make_password(pwd, 'pbkdf2_sha256')
                d = user_dao.update_user_info(user_dao.get_user_id(username),
                                              desp, p)
                # print(d)
                return HttpResponse(d)
            meta = user_dao.get_user_info2(username)
            return HttpResponse(meta['dep'])
        else:
            return redirect('/index/')
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#11
0
def user_post_json(req, cat, page):
    try:
        username = get_cookies(req, 'username')
        if username:
            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
            return JsonResponse(list_obs, safe=False)
        else:
            return redirect('/index/')
    except Exception as e:
        print(e)
        return render(req, 'error.html')
    else:
        pass
示例#12
0
def get_username(req):
    username = get_cookies(req, 'username')
    if username is not None:
        uid = user_dao.get_user_id(username)
        return HttpResponse(uid)
    return HttpResponse(0)