コード例 #1
0
ファイル: admin_role.py プロジェクト: leeyisoft/py_admin
    def insert(param):
        """插入

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in AdminRole.__table__.columns.items()]
        param = {k:v for k,v in param.items() if k in columns}
        if 'created_at' in columns:
            param['created_at'] = utime.timestamp(3)
        try:
            obj = AdminRole(**param)
            AdminRole.session.add(obj)
            AdminRole.session.commit()
            return True
        except Exception as e:
            AdminRole.session.rollback()
            SysLogger.error(e)
            raise JsonError('insert error')
コード例 #2
0
 def upload(current_uid, ip, action, imgfile, path):
     action_set = (
         'adad',
         'article/thumb',
         'article/regulation',
         'article/news',
         'avatar',
         'friendlink',
         'goods/thumb',
         'product',
     )
     if action not in action_set:
         raise JsonError('不支持的action')
     resp_data = []
     for img in imgfile:
         # 对文件进行重命名
         file_ext = FileUtil.file_ext(img['filename'])
         path = '%s/' % path
         file_md5 = func.md5(img['body'])
         save_name = f'{file_md5}.{file_ext}'
         try:
             param = Uploader.upload_img(file_md5, img, save_name, path, {
                 'user_id': current_uid,
                 'ip': ip,
             })
             resp_data.append(param)
         except Exception as e:
             if settings.debug:
                 raise e
             SysLogger.error(e)
             raise JsonError('上传失败')
     return resp_data
コード例 #3
0
ファイル: admin_role.py プロジェクト: leeyisoft/py_admin
    def update(id, param):
        """更新记录

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in AdminRole.__table__.columns.items()]
        param = {k:v for k,v in param.items() if k in columns}
        if 'updated_at' in columns:
            param['updated_at'] = utime.timestamp(3)

        if not id:
            raise JsonError('ID 不能为空')

        try:
            AdminRole.Update.filter(AdminRole.id == id).update(param)
            AdminRole.session.commit()
            return True
        except Exception as e:
            AdminRole.session.rollback()
            SysLogger.error(e)
            raise JsonError('update error')
コード例 #4
0
ファイル: advertising.py プロジェクト: leeyisoft/py_admin
    def insert(param):
        """插入

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Advertising.__table__.columns.items()]
        param = {k:v for k,v in param.items() if k in columns}
        if 'created_at' in columns:
            param['created_at'] = utime.timestamp(3)

        description = param.get('description', '')
        if len(description) > 255:
            raise JsonError('Data too long for \'description\'')

        if 'start_at' in param.keys():
            param['start_at'] = param['start_at'] if param['start_at'].isnumeric() else 0
        if 'end_at' in param.keys():
            param['end_at'] = param['end_at'] if param['end_at'].isnumeric() else 0
        try:
            obj = Advertising(**param)
            Advertising.session.add(obj)
            Advertising.session.commit()
            return True
        except Exception as e:
            Advertising.session.rollback()
            SysLogger.error(e)
            raise JsonError('insert error')
コード例 #5
0
    def update(key, param):
        """更新记录

        [description]

        Arguments:
            key string -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Config.__table__.columns.items()]
        param = {k: v for k, v in param.items() if k in columns}
        if 'updated_at' in columns:
            param['updated_at'] = utime.timestamp(3)

        if not key:
            raise JsonError('key 不能为空')

        try:
            Config.Update.filter(Config.key == key).update(param)
            Config.session.commit()
            return True
        except Exception as e:
            Config.session.rollback()
            SysLogger.error(e)
            raise JsonError('update error')
コード例 #6
0
    def update(id, param):
        """更新记录

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Goods.__table__.columns.items()]
        param = {k: v for k, v in param.items() if k in columns}
        if 'updated_at' in columns:
            param['updated_at'] = utime.timestamp(3)

        if not id:
            raise JsonError('ID 不能为空')

        if 'thumb' in param.keys():
            try:
                param['thumb'] = json_decode(param['thumb'])
            except Exception as e:
                param['thumb'] = {}
        try:
            Goods.Update.filter(Goods.id == id).update(param)
            Goods.session.commit()
            return True
        except Exception as e:
            Goods.session.rollback()
            SysLogger.error(e)
            raise JsonError('update error')
コード例 #7
0
    def insert(param):
        """插入

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Goods.__table__.columns.items()]
        param = {k: v for k, v in param.items() if k in columns}
        if 'created_at' in columns:
            param['created_at'] = utime.timestamp(3)

        if 'thumb' in param.keys():
            try:
                param['thumb'] = json_decode(param['thumb'])
            except Exception as e:
                param['thumb'] = {}
                raise e
        else:
            param['thumb'] = {}

        try:
            obj = Goods(**param)
            Goods.session.add(obj)
            Goods.session.commit()
            return True
        except Exception as e:
            Goods.session.rollback()
            SysLogger.error(e)
            raise JsonError('insert error')
コード例 #8
0
ファイル: article.py プロジェクト: leeyisoft/py_admin
    def insert(param):
        """插入

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Article.__table__.columns.items()]
        param = {k: v for k, v in param.items() if k in columns}
        if 'created_at' in columns:
            param['created_at'] = utime.timestamp(3)

        category_id = param.get('category_id', 0)
        if not category_id:
            raise JsonError('文章分类缺失')

        description = param.get('description', '')
        if len(description) > 255:
            raise JsonError('Data too long for \'description\'')

        try:
            obj = Article(**param)
            Article.session.add(obj)
            Article.session.commit()
            return True
        except Exception as e:
            Article.session.rollback()
            SysLogger.error(e)
            raise JsonError('insert error')
コード例 #9
0
ファイル: advertising.py プロジェクト: leeyisoft/py_admin
    def update(id, param):
        """更新记录

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Advertising.__table__.columns.items()]
        param = {k:v for k,v in param.items() if k in columns}

        if 'updated_at' in columns:
            param['updated_at'] = utime.timestamp(3)

        if 'start_at' in param.keys():
            param['start_at'] = param['start_at'] if param['start_at'].isnumeric() else 0
        if 'end_at' in param.keys():
            param['end_at'] = param['end_at'] if param['end_at'].isnumeric() else 0

        description = param.get('description', '')
        if len(description) > 255:
            raise JsonError('Data too long for \'description\'')
        if not id:
            raise JsonError('ID 不能为空')

        try:
            Advertising.Update.filter(Advertising.id == id).update(param)
            Advertising.session.commit()
            return True
        except Exception as e:
            Advertising.session.rollback()
            SysLogger.error(e)
            raise JsonError('update error')
コード例 #10
0
ファイル: article.py プロジェクト: leeyisoft/py_admin
    def update(id, param):
        """更新记录

        [description]

        Arguments:
            id int -- 主键
            param dict -- [description]

        return:
            True | JsonError
        """
        columns = [i for (i, _) in Article.__table__.columns.items()]
        param = {k: v for k, v in param.items() if k in columns}
        if 'updated_at' in columns:
            param['updated_at'] = utime.timestamp(3)

        description = param.get('description', '')
        if len(description) > 255:
            raise JsonError('Data too long for \'description\'')

        if not id:
            raise JsonError('ID 不能为空')

        status = param.get('status', None)
        category_id = param.get('category_id', 0)
        if not category_id:
            raise JsonError('文章分类缺失')

        try:
            Article.Update.filter(Article.id == id).update(param)
            Article.session.commit()
            return True
        except Exception as e:
            Article.session.rollback()
            SysLogger.error(e)
            raise JsonError('update error')