Example #1
0
    def post(self, argument):
        if argument == '1':
            data_json = json.loads(self.get_argument('data'))
            code = data_json.get('code')
            if self.session['email_random'] == code:

                # 新增到User表
                user_data = {
                    "UserName": self.session['nickname'],
                    "UserEmail": self.session['bind_email'],
                    "UserLastVisitIP": self.request.remote_ip
                }
                user_obj = Users(**user_data)
                session.add(user_obj)
                session.commit()
                # 添加到映射表
                data = {
                    "OpenID": self.session['openid'],
                    "UserID": str(user_obj.UserID)
                }
                session.add(LoginMap(**data))
                self.session.set('index_user', user_obj)
                session.commit()
                session.close()
                print "user_data", user_data
                # self.session['index_user'] = user_data
                self.write_json("验证成功", code=1)
            else:
                self.write_json("验证失败", code=0)
Example #2
0
 def post(self):
     # 新增商品类型
     try:
         # 获取前端传来的参数
         data = json.loads(self.get_argument('data'))
         session.add(ProductType(**data))
         session.commit()
         self.write_json("success", code=1)
     except:
         # 事务
         session.rollback()
         self.write_json("failed", code=0)
     finally:
         session.close()
Example #3
0
 def post(self):
     # 新增用户
     try:
         # 获取前端传来的参数
         data = json.loads(self.get_argument('data'))
         # 保存访问IP
         data['UserLastVisitIP'] = self.request.remote_ip
         # 密码加密
         data['UserPwd'] = sec_pass(data['UserPwd'])
         session.add(Users(**data))
         session.commit()
         self.write_json("success", code=1)
     except:
         # 事务
         session.rollback()
         self.write_json("failed", code=0)
     finally:
         session.close()
Example #4
0
    def post(self):
        pid = self.get_argument('pid')
        try:
            complete_file_path = None
            file_name = None
            return_save_file_path = os.path.join('images',
                                                 'upload')  # 要保存到数据库的地址
            save_file_path = os.path.join('static', return_save_file_path)
            if self.get_argument('image_type') == '1':
                # 小图地址字段
                image_type = 'ProductSmallPicture'
                # 上传到哪儿
                upload_type = 'SmallPictureUpType'
            else:
                # 大图地址字段
                image_type = 'ProductBigPictureProductBigPicture'
                # 上传到哪儿
                upload_type = 'BigPictureUpType'

            if self.get_argument('save_type') == '2' or self.get_argument(
                    'save_type') == '3':
                # 七牛云、又拍云
                save_file_path = os.path.join('static', return_save_file_path)

            # 将文件先保存到本地
            file_metas = self.request.files["file"]  # 获取上传文件信息
            for meta in file_metas:  # 循环文件信息
                file_name = meta['filename']  # 获取文件的名称
                # 拼接完整目录
                complete_file_path = os.path.join(save_file_path, file_name)
                with open(complete_file_path,
                          'wb') as up:  # os拼接文件保存路径,以字节码模式打开
                    up.write(meta['body'])  # 将文件写入到保存路径目录

            # 要保存到数据库的文件名
            return_save_file_path = file_name

            # 是否上传七牛云
            if self.get_argument('save_type') == '2':
                # 上传
                obj = up_qiniu.QINIU()
                # 返回七牛地址
                return_save_file_path = obj.upload(complete_file_path,
                                                   file_name)

            # 是否上传又拍云
            if self.get_argument('save_type') == '3':
                pass
                # 上传
                # 返回七牛地址
                # return_save_file_path

            # 入库
            session.query(Product).filter(Product.ProductID == pid).update({
                image_type:
                return_save_file_path,
                upload_type:
                int(self.get_argument('save_type'))
            })
            session.commit()
            session.close()
            self.write_json("success", code=1)
        except Exception, e:
            print e
            self.write_json("failed", code=0)
Example #5
0
                data['IsHot'] = False
            if data['IsNew'] == '1':
                data['IsNew'] = True
            else:
                data['IsNew'] = False
            pro = Product(**data)
            session.add(pro)
            session.commit()
            self.write_json(pro.ProductID, code=1)
        except Exception, e:
            # 事务
            print e
            session.rollback()
            self.write_json("failed", code=0)
        finally:
            session.close()

    def delete(self, argument):
        try:
            noautoflushsession.query(Product).filter(
                Product.ProductID == int(argument)).delete()
            noautoflushsession.commit()
            noautoflushsession.close()
            self.write_json("success", code=1)
        except Exception, e:
            print e
            self.write_json("failed", code=0)

    def patch(self, argument):
        updata_json = json.loads(self.get_argument('data'))
        print updata_json