예제 #1
0
    def post(self, *args, **kwargs):
        ret = {'result': 'ok', 'status': True, 'code': 200}
        user = self.session_obj['user']
        database_util = Db_Util()
        param = {'user_name': user}
        user_id = database_util.find_user_id(**param)

        # 如果没有登录,返回nuid,前台提示‘请登录’,跳转到登录页面
        if user_id == 0:
            ret = {'result': 'nuid', 'status': True, 'code': 200}
        else:
            # 获取到house_id,user_comments
            house_id = self.get_body_argument('renting_id')
            user_comments = self.get_body_arguments('comment')

            params = {
                'user_id': user_id,
                'house_id': house_id,
                'user_comments': user_comments
            }
            result = database_util.insert_comment(**params)

            print('插入数据库返回的结果:', result)  # 0  1

            if result == 1:
                database_util.conn.commit()
                ret = {'result': 'ok', 'status': True, 'code': 200}
            else:
                database_util.conn.rollback()
                ret = {'result': 'fail', 'status': True, 'code': 200}
        database_util.conn.close()
        self.write(json_encode(ret))  # 展示到前台


# =============================================================hxx
예제 #2
0
    def get(self, *args, **kwargs):
        house_id = self.get_argument('id', '')
        if house_id:
            database_util = Db_Util()
            result = database_util.find_rent_house(house_id)
            data = [
                'renting_id', 'land_lord_id', 'city', 'region',
                'renting_title', 'renting_pictrue', 'door_model',
                'renting_area', 'renting_floor', 'renting_address',
                'rent_type', 'renting_orientation', 'near_subway',
                'has_elevator', 'renting_price', 'house_type',
                'renting_fitment', 'release_time', 'renting_detail',
                'is_check', 'user_name', 'user_phone'
            ]

            dic = dict(zip(data, result[0]))
            if self.session_obj['is_login']:
                username = self.session_obj['user']
                database_util.insert_history_info(username, house_id)
                if result:
                    database_util.conn.commit()
                else:
                    database_util.conn.rollback()
            self.render('../template/rent_info.html', result=dic)
        else:
            self.render('../template/rent.html')
예제 #3
0
    def post(self, *args, **kwargs):
        '''
        处理请求,如果获取的是 1 ,则修改数据库对应的字段为 0 ,否则改为 1
        :param args:
        :param kwargs: is_block, admin_id
        :return: json 数据
        :author: Yanfuzi
        '''
        ret = {'result': 'ok', 'status': True, 'code': 200}
        isBlock = self.get_body_argument('is_block')
        adminId = self.get_body_argument('admin_id')
        if isBlock == '0':
            isBlock = '1'
        else:
            isBlock = '0'
        database_util = Db_Util()
        result = database_util.update_admin_block(is_block=isBlock,
                                                  admin_id=adminId)
        # result is 1, commit to db
        if result:
            database_util.conn.commit()
            ret = {'result': 'ok', 'status': True, 'code': 200}
        # result is 0(result not is 1) ,rollback
        else:
            database_util.conn.rollback()
            ret = {'result': 'fail', 'status': True, 'code': 200}

        database_util.conn.close()
        self.write(json_encode(ret))
예제 #4
0
 def get(self, *args, **kwargs):
     if self.session_obj['is_login'] != 1:
         self.redirect(r'/login')
     else:
         user_name = self.session_obj['user']
         print(user_name)
         database_util = Db_Util()
         data = {'user_name': user_name}
         result = database_util.find_user_manage(**data)
         print('result:', result)  # 调试用的
         # 优化把返回None的值替换
         Name = [
             'user_gender', 'user_address', 'user_phone', 'user_head_img',
             'user_land_lord'
         ]
         Persion = []
         for i in result[0][5:]:
             if i == None:
                 i = ' '
                 Persion.append(i)
             else:
                 Persion.append(i)
         data = dict(zip(Name, Persion))
         # print(Persion)      #调试
         # data = {
         #     'user_gender': result[0][5],
         #     'user_address':result[0][6],
         #     'user_phone':result[0][7],
         #     'user_head_img':result[0][8],
         #     'user_land_lord':result[0][9]
         # }
         self.render(r'..\template\user_manage.html', userManage=data)
예제 #5
0
 def get(self, *args, **kwargs):
     # 已经登陆的状态
     if self.session_obj['admin_is_login'] == 1:
         admin_name = self.session_obj['adminName']
         # self.redirect('/admin/user')
         # self.render('../template/admin_pages/index.html', adminName=admin_name)
         # 登录跳转的url
         database_util = Db_Util()
         # check = (0,)
         params = {'is_check': 0}
         result = database_util.find_house(**params)
         if result:
             # renting_id = result['renting_id']
             # user_name = result['user_name']
             # user_email = result['user_email']
             # release_time = result['release_time']
             # admin_name = self.session_obj['adminName']
             self.render(r'../template/admin_pages/index.html',
                         resultViews=result)
         else:
             self.render(r'../template/admin_pages/index.html',
                         resultViews='0')
     # 还没有登陆
     else:
         self.redirect(r'/admin/login')
예제 #6
0
 def post(self, *args, **kwargs):
     '''
     ajax请求,将要删除的id穿过来,进行处理,再返回给客户端json格式的数据
     :param args:
     :param kwargs:
     :return: json
     :author: Yanfuzi
     '''
     ret = {'result': 'ok', 'status': True, 'code': 200}
     # 接收的是一个列表
     renting_id = self.get_body_argument('renting_id')
     # print(renting_id)
     database_util = Db_Util()
     param = {'renting_id': renting_id}
     result = database_util.delete_house(**param)
     # 返回结果  1 (None) 或  0
     if result == 1:
         database_util.conn.commit()
         ret = {'result': 'ok', 'status': True, 'code': 200, 'msg': '删除成功'}
     else:
         database_util.conn.rollback()
         ret = {
             'result': 'fail',
             'status': True,
             'code': 200,
             'msg': '删除失败'
         }
     database_util.close_conn()
     self.write(json_encode(ret))
예제 #7
0
 def post(self, *args, **kwargs):
     if self.session_obj['is_login']:
         user = self.session_obj['user']  # 用户名
         db_util = Db_Util()  # 数据库
         user_comment_id = self.get_body_arguments('user_comment_id')
         data = {'user_comment_id': user_comment_id}
         result = db_util.del_comments(**data)
         # print('result:', result)  #  1  0
         if result:
             db_util.conn.commit()
             ret = {
                 'result': 'ok',
                 'status': True,
                 'code': 200,
                 'user': user
             }
         else:
             db_util.conn.rollback()
             ret = {
                 'result': 'fail',
                 'status': True,
                 'code': 200,
                 'user': user
             }
         db_util.conn.close()
         self.write(json_encode(ret))
     else:
         self.render(r'..\template\login.html')
예제 #8
0
    def post(self, *args, **kwargs):
        ret = {'result': 'ok', 'status': True, 'code': 200}
        renting_id = self.get_body_argument('renting_id')
        # print('ajsx传递过来的值', renting_id)

        # 要修改的字段,值
        param1 = {'is_check': '1'}

        # 作为条件的字段,值
        param2 = {'renting_id': renting_id}

        params = {'param1': param1, 'param2': param2}

        database_util = Db_Util()
        result = database_util.update_house(**params)
        # print('admin:', result)
        if result == 1:
            database_util.conn.commit()
            ret = {'result': 'ok', 'status': True, 'code': 200}
        else:
            database_util.conn.rollback()

            ret = {'result': 'fail', 'status': True, 'code': 200}
        database_util.close_conn()
        self.write(json_encode(ret))
예제 #9
0
    def post(self, *args, **kwargs):
        user_name = self.get_body_argument('userName')  #彭修改过
        password = self.get_body_argument('userPwd')  #彭修改过

        # 查询数据库
        database_util = Db_Util()
        params = {
            'user_name': user_name,
            'user_pwd': md5(password)
        }  #彭修改过,查询数据库用户信息
        #key的值要和数据库中的字段一样
        result = database_util.find_user(**params)
        if result:  #如果为True执行以下代码
            self.session_obj['is_login'] = 1  # 1登录0未登录
            self.session_obj['user'] = user_name
            # -------------------------------------------------------------------------------------------
            ret = {
                "result": 'ok',
                'user': self.session_obj['user'],
                'status': True,
                'code': 200
            }
        else:
            ret = {"result": 'fail', 'status': True, 'code': 200}

        self.write(json_encode(ret))
        database_util.close_conn()
예제 #10
0
    def post(self, *args, **kwargs):
        ret = {"result": 'ok', 'status': True, 'code': 200}
        # if self.session_obj['is_login']:      #判断用户是否登录
        if self.session_obj['is_login']:
            user = self.session_obj['user']
            print(user, __class__, '253hang ')
            gender = self.get_body_argument('gender')
            zhiye = self.get_body_argument('zhiye')
            phone = self.get_body_argument('phone')
            barthday = self.get_body_argument('birthday')
            Quyu = self.get_body_argument('Quyu')
            # print(gender,zhiye,phone,barthday,Quyu)
            databases_util = Db_Util()
            params = {
                'user_gender': gender,
                'user_address': zhiye,
                'user_phone': phone,
                'user_head_img': barthday,
                'is_land_lord': Quyu
            }
            print(params, __class__, '267行')
            # -------------------------------------------------------------
            result = databases_util.update_user_info(user, **params)
            print(result)
            if result == 1:
                databases_util.conn.commit()  #提交到数据库执行
                ret = {"result": 'ok', 'status': True, 'code': 200}
            else:
                databases_util.conn.rollback()  #回滚
                ret = {"result": 'no', 'status': True, 'code': 200}

            databases_util.close_conn()  #关闭数据库连接
            self.write(json_encode(ret))  # 向前台返回ajax数据
        else:
            self.render(r'..\template\login.html')  #如果用户没有登陆则跳转到登陆注册页面
예제 #11
0
 def get(self, *args, **kwargs):
     params = {
         'ajk_renting_region': '朝阳',
         'ajk_renting_price': '2000-3000',
         'ajk_renting_door_model': '3室1厅',
         'ajk_renting_rent_type': '合租'
     }
     db_util = Db_Util()
     result = db_util.find_third_rent_info(**params)
     self.render(r'..\template\third_rent.html', result=result)
예제 #12
0
 def get(self, *args, **kwargs):
     params = {
         'region': '朝阳',
         'renting_price': '1500以下',
         'door_model': '1室1厅',
         'rent_type': '整租'
     }
     db_util = Db_Util()
     result = db_util.find_rent_info(**params)
     self.render(r'..\template\rent.html', result=result)
예제 #13
0
 def get(self, *args, **kwargs):
     if self.session_obj['is_login']:  # 判断是否登录
         user = self.session_obj['user']  # 用户名
         db_util = Db_Util()  # 数据库
         result = db_util.find_comments(user)
         print(result)
         self.render(r'..\template\user_comment.html',
                     result=result,
                     user=user)
     else:
         self.render(r'..\template\login.html')
예제 #14
0
 def get(self, *args, **kwargs):
     if self.session_obj['admin_is_login'] == 1:
         renting_id = self.get_arguments('id')
         database_util = Db_Util()
         data = {'renting_id': renting_id}
         result = database_util.find_house(**data)
         # print('Manage:', result)  # 列表中嵌套着字典
         self.render(r'..\template\admin_pages\houseApplyCheck.html',
                     houseManage=result[0])
     else:
         self.render(r'..\template\error_pages\404.html')
예제 #15
0
 def get(self, *args, **kwargs):
     if self.session_obj['is_login']:
         user = self.session_obj['user']
         db_util = Db_Util()
         result = db_util.find_history_info(user)
         db_util.conn.close()
         self.render(r'..\template\user_history.html',
                     result=result,
                     user=user)
     else:
         self.render(r'..\template\login.html')
예제 #16
0
 def get(self, *args, **kwargs):
     database_util = Db_Util()  # 实例化对象,操作数库
     result_comment = database_util.find_comment()  # 操作数据库的方法,返回结果
     if result_comment:
         # 如果返回结果,则跳转到房源信息展示列表,并把返回结果传过去
         self.render(r'../template/admin_pages/commentList.html',
                     result_comment=result_comment)
     else:
         # 还没写完
         self.render(r'../template/admin_pages/commentList.html',
                     result_comment='0')
예제 #17
0
 def get(self, *args, **kwargs):
     database_util = Db_Util()  # 实例化对象,操作数库
     result_advice = database_util.find_advice()  # 操作数据库的方法,返回结果
     # print("result_advice:"+result_advice)
     if result_advice:
         # 如果返回结果,则跳转到房源信息展示列表,并把返回结果传过去
         self.render(r'../template/admin_pages/adviceList.html',
                     result_advice=result_advice)
     else:
         # 还没写完
         self.render(r'../template/admin_pages/adviceList.html',
                     result_advice='0')
예제 #18
0
 def get(self, *args, **kwargs):
     if self.session_obj['is_login']:
         username = self.session_obj['user']
         database_util = Db_Util()  # 实例化对象,操作数库
         result_info = database_util.find_user_info(
             username)  # 操作数据库的方法,返回结果
         if result_info:
             self.render(r'..\template\user_info.html',
                         result_info=result_info)
         else:
             self.render(r'..\template\user_info.html', result_info='0')
     else:
         self.render(r'..\template\login.html')
예제 #19
0
    def post(self, *args, **kwargs):
        ret = {"result": 'ok', 'status': True, 'code': 200}
        user_id = self.get_body_argument('user_id')
        user_name = self.get_body_argument('user_name')
        renting_title = self.get_body_argument('renting_title')
        region = self.get_body_argument('region')
        door_model = self.get_body_argument('door_model')
        renting_price = self.get_body_argument('renting_price')
        renting_area = self.get_body_argument('renting_area')

        city = self.get_body_argument('city')
        renting_floor = self.get_body_argument('renting_floor')
        renting_address = self.get_body_argument('renting_address')
        rent_type = self.get_body_argument('rent_type')
        renting_orientation = self.get_body_argument('renting_orientation')
        near_subway = self.get_body_argument('near_subway')
        house_type = self.get_body_argument('house_type')
        renting_fitment = self.get_body_argument('renting_fitment')
        renting_detail = self.get_body_argument('renting_detail')

        params = {
            'user_id': user_id,
            'user_name': user_name,
            'renting_title': renting_title,
            'region': region,
            'city': city,
            'renting_floor': renting_floor,
            'renting_address': renting_address,
            'rent_type': rent_type,
            'renting_orientation': renting_orientation,
            'near_subway': near_subway,
            'house_type': house_type,
            'renting_fitment': renting_fitment,
            'renting_detail': renting_detail,
            'door_model': door_model,
            'renting_price': renting_price,
            'renting_area': renting_area
        }

        database_util = Db_Util()
        result = database_util.insert_house(**params)
        print('返回的result', result)
        if result:
            database_util.conn.commit()
            ret = {"result": 'ok', 'status': True, 'code': 200}
        else:
            database_util.conn.rollback()
            ret = {"result": 'fail', 'status': True, 'code': 200}
        database_util.conn.close()
        self.write(json_encode(ret))
예제 #20
0
    def get(self, *args, **kwargs):
        if self.session_obj['user']:
            user_name = self.session_obj['user']
            database_util = Db_Util()
            params = {'user_name': user_name}

            data = database_util.find_user_manage(**params)
            user_manage = [
                'user_id', 'user_name', 'user_pwd', 'user_email',
                'user_create_time', 'user_gender', 'user_address',
                'user_phone', 'user_head_img', 'is_land_lord'
            ]
            userManage = dict(zip(user_manage, data[0]))
            self.render(r'..\template\release.html', userManage=userManage)
        else:
            self.redirect(r'/')
예제 #21
0
 def post(self, *args, **kwargs):
     ret = {'result': 'ok', 'status': True, 'code': 200}
     # 接收的是一个列表
     user_comment_id = self.get_body_argument('user_comment_id')
     database_util = Db_Util()
     param = {'user_comment_id': user_comment_id}
     result = database_util.delete_comment(**param)
     # 删除成功返回None
     if result != 0:
         ret = {'result': 'ok', 'status': True, 'code': 200, 'msg': '删除成功'}
     else:
         ret = {
             'result': 'fail',
             'status': True,
             'code': 200,
             'msg': '删除失败'
         }
     database_util.close_conn()
     self.write(json_encode(ret))
예제 #22
0
    def post(self, *args, **kwargs):
        ret = {'result': 'ok', 'status': True, 'code': 200}
        advice_type = self.get_body_arguments('advice_type')
        advice_content = self.get_body_argument('advice_content')

        print('advice_type:', advice_type)
        print('advice_content:', advice_content)

        params = {'advice_type': advice_type, 'advice_content': advice_content}
        database_util = Db_Util()
        res = database_util.insert_advice(**params)
        # commit提交成功后返回的结果是None
        if res == 1:
            database_util.conn.commit()
            ret = {'result': 'ok', 'status': True, 'code': 200}
        else:
            database_util.conn.rollback()
            ret = {'result': 'fail', 'status': True, 'code': 200}
        database_util.conn.close()
        self.write(json_encode(ret))
예제 #23
0
 def get(self, *args, **kwargs):
     ajk_renting_region = self.get_argument('ajk_renting_region')
     ajk_renting_price = self.get_argument('ajk_renting_price')
     ajk_renting_door_model = self.get_argument('ajk_renting_door_model')
     ajk_renting_rent_type = self.get_argument('ajk_renting_rent_type')
     params = {
         'ajk_renting_region': ajk_renting_region,
         'ajk_renting_price': ajk_renting_price,
         'ajk_renting_door_model': ajk_renting_door_model,
         'ajk_renting_rent_type': ajk_renting_rent_type
     }
     db_util = Db_Util()
     result = db_util.find_third_rent_info(**params)
     ret = {
         'info': result,
         'result': 'ok',
         'status': True,
         'code': 200
     }
     self.write(json_encode(ret))
예제 #24
0
 def post(self, *args, **kwargs):
     ret = {'result': 'ok', 'status': True, 'code': 200}
     # 获取ajax传递的数据
     admin_name = self.get_body_argument('adminName')
     admin_pwd = self.get_body_argument('adminPwd')
     # 判断是否是超级管理员,超级管理员的代号为 1 ,普通管理员的代号为 0
     if admin_name == 'admin':
         is_super_num = 1
     else:
         is_super_num = 0
     # 查询数据库
     database_util = Db_Util()
     params = {
         'admin_name': admin_name,
         'admin_pwd': admin_pwd,
         'is_super': is_super_num
     }
     result = database_util.find_admin(**params)
     # 处理结果
     if result:
         if result[0][-1] == 1:
             ret = {
                 'result': 'block',
                 'status': True,
                 'code': 200,
             }
         else:
             # print('登陆验证:',result)
             self.session_obj['admin_is_login'] = 1  # 1 表示已登录,其他表示未登录
             self.session_obj['admin_name'] = admin_name  # 记录登录的用户名
             ret = {
                 'result': 'ok',
                 'admin_name': self.session_obj['admin_name'],
                 'status': True,
                 'code': 200,
             }
     else:
         ret = {'result': 'fail', 'status': True, 'code': 200}  # 登陆失败
         # self.redirect(r'/reg?fail')
     database_util.close_conn()
     self.write(json_encode(ret))  # 向前台返回ajax数据
예제 #25
0
    def post(self, *args, **kwargs):
        user_name = self.get_body_argument('userName')
        user_pwd = self.get_body_argument('userPwd')
        email = self.get_body_argument('email')
        database_util = Db_Util()
        params = {'user_name': user_name}
        users = database_util.find_user(**params)  # 在数据库中查找存在的用户名
        if users:

            ret = {"result": 'exits', 'status': True, 'code': 200}

        else:
            params = {
                'user_name': user_name,
                'user_pwd': user_pwd,
                'user_email': email,
            }
            result = database_util.save_user(**params)
            if result == 1:
                database_util.conn.commit()  #提交到数据库执行
                ret = {"result": 'ok', 'status': True, 'code': 200}
                # self.redirect('/index')
            else:
                database_util.conn.rollback()
                ret = {"result": 'fail', 'status': True, 'code': 200}  # 注册失败
                # self.redirect(r'/reg?fail')
        database_util.close_conn()
        self.write(json_encode(ret))  # 向前台返回ajax数据
예제 #26
0
 def get(self, *args, **kwargs):
     '''
     跳转到房源管理列表界面,显示的是已经发布的房源信息
     直接跳转页面属于默认的get请求方式,需要展示相关的信息,
         如:房源编号,房源标题,发布者信息,发布时间等,管理员可以对房源信息
         进行修改和删除,但是不可以更改关于发布人的信息及发布时间
     :param args:
     :param kwargs:
     :return:
     '''
     if self.session_obj['admin_is_login']:
         database_util = Db_Util()  # 实例化对象,操作数库
         params = {'is_check': 1}  # 已经发布的字段值为 1
         result = database_util.find_house(**params)  # 操作数据库的方法,返回结果
         if result:
             # 如果返回结果,则跳转到房源信息展示列表,并把返回结果传过去
             self.render(r'../template/admin_pages/houseList.html',
                         result=result)
         else:
             self.render(r'../template/admin_pages/houseList.html',
                         result='0')
     else:
         self.redirect(r'/admin/login')
예제 #27
0
    def post(self, *args, **kwargs):
        '''
        点击保存后的处理
        :param args: none
        :param kwargs: 传过来的data字典
        :return:json格式的数据
        :author: Yanfuzi
        '''
        ret = {'result': 'ok', 'status': True, 'code': 200}

        renting_id = self.get_body_argument('renting_id')
        renting_title = self.get_body_argument('renting_title')
        region = self.get_argument('region')
        print('region', region)
        renting_detail = self.get_body_argument('renting_detail')

        # 要修改的字段,值
        param1 = {
            'renting_title': renting_title,
            'region': region,
            'renting_detail': renting_detail
        }
        # 当作条件
        param2 = {'renting_id': renting_id}

        params = {'param1': param1, 'param2': param2}

        database_util = Db_Util()
        result = database_util.update_house(**params)
        if result == 1:
            database_util.conn.commit()
            ret = {'result': 'ok', 'status': True, 'code': 200}
        else:
            database_util.conn.rollback()
            ret = {'result': 'fail', 'status': True, 'code': 200}
        database_util.conn.close()
        self.write(json_encode(ret))
예제 #28
0
 def post(self, *args, **kwargs):
     '''
     接收搜索内容,调用搜索函数,将函数返回的结果进行处理,返回json给前台页面
     :param args:
     :param kwargs:
     :return:
     :author: Yanfuzi
     '''
     ret = {'result': 'ok', 'status': True, 'code': 200}
     searchInput = self.get_body_argument('searchInput')
     database_util = Db_Util()
     param = {'searchInput': searchInput}
     searchResult = database_util.searchHouse(**param)
     if searchResult:
         ret = {
             'result': 'ok',
             'status': True,
             'code': 200,
             'searchResult': searchResult
         }
     else:
         ret = {'result': 'fail', 'status': True, 'code': 200}
     database_util.close_conn()
     self.write(json_encode(ret))
예제 #29
0
    def get(self, *args, **kwargs):
        '''
        跳转到编辑的页面的处理
        :param args:
        :param kwargs:  房源id
        :return: 该id对应的房源信息
        :author: Yanfuzi
        '''
        # 如果没有登陆
        if self.session_obj['admin_is_login'] == 0:
            self.redirect(r'/admin/login')
        else:
            # 如果想要直接跳转到编辑界面,返回到houseList.html
            # if kwargs == {}:
            #     self.redirect(r'/admin/houseEdit')
            # else:

            # 获取要编辑的房源id
            id = self.get_argument('id')
            # 根据id获取数据库的内容,将对应的房源信息发送给前台
            database_util = Db_Util()
            params = {'renting_id': id}
            result = database_util.find_house(**params)
            if result:
                renting_id = result[0]['renting_id']
                renting_title = result[0]['renting_title']
                region = result[0]['region']
                user_name = result[0]['user_name']
                user_email = result[0]['user_email']
                release_time = result[0]['release_time']
                renting_detail = result[0]['renting_detail']

                self.render(r'../template/admin_pages/houseEdit.html',
                            result=locals())
            else:
                print('没有查到任何信息 ')
예제 #30
0
 def get(self, *args, **kwargs):
     '''
     显示管理员账号
     :param args:
     :param kwargs:
     :return:
     :author: Yanfuzi
     '''
     if self.session_obj['admin_name'] == 'admin':
         L = []
         database_util = Db_Util()
         params = {'is_super': 0}
         result = database_util.find_admin(**params)
         data = [
             'adminId', 'adminName', 'adminPwd', 'addTime', 'isSuper',
             'isBlock'
         ]
         for tup in result:
             d = dict(zip(data, tup))
             L.append(d)
         # print(L)
         self.render(r'../template/admin_pages/adminList.html', result=L)
     else:
         self.render(r'../template/error_pages/404.html')