def modify_course(docid, course_id): cursor = execute_modify("update document set course_id=? where id=?", ( course_id, docid, )) # row count为1表示插入成功 return True
def modify_username(user_id, user_name): if SchoolUserHelper.get_by_id(user_id) is None: return False cursor = execute_modify("update school_user set username=? where id=?", (user_name, user_id)) return cursor.rowcount == 1
def modify_name(school_id, school_name): if SchoolHelper.get_by_id(school_id) is None: return False cursor = execute_modify("update school set name=? where id=?", (school_name, school_id)) return cursor.rowcount == 1
def remove_visible_from_schooluser(school_id, doc_id): cursor = execute_modify( 'delete from user_doc where doc_id=? ' 'and user_id in (select id from school_user where school_id=?)', [ doc_id, school_id, ]) return True
def modify_name(docid, name): cursor = execute_modify("update document set description=? where id=?", ( name, docid, )) # row count为1表示插入成功 return True
def modify_username(manager_id, manager_name): if BackendHelper.get_by_id(manager_id) is None: return False cursor = execute_modify( "update backend_manager set username=? where id=?", (manager_name, manager_id)) return cursor.rowcount == 1
def delete_by_id(course_id): for doc in DocumentHelper.filter_by_course(DocumentHelper.get_all(), course_id): DocumentHelper.modify_course(doc['id'], None) cursor = execute_modify( "delete from course where id=?", (course_id,), True ) return cursor.rowcount == 1
def create_school(name): cursor = execute_modify("insert into school (name) " "values (?)", (name, )) # row count为1表示插入成功 print cursor.rowcount if cursor.rowcount != 1: return False else: return cursor.lastrowid
def create_manager(username, password, school_id): cursor = execute_modify( "insert into school_manager (username, password, school_id) " "values (?, ?, ?)", (username, password, school_id)) # row count为1表示插入成功 if cursor.rowcount != 1: return False else: return cursor.lastrowid
def delete_by_id(document_id): doc = DocumentHelper.get_by_id(document_id) if doc: cursor = execute_modify("delete from document where id=?", (document_id, ), True) try: os.remove( os.path.join(app.config['UPLOAD_FOLDER'], doc['path'])) except OSError: pass return cursor.rowcount == 1 else: print 'no doc' return False
def create_document(docfile): doc_name = docfile.filename ext = doc_name.rsplit('.', 1)[1].lower() if '.' in doc_name and ext in DOC_EXTS: new_fname = str(uuid.uuid4()) + '.' + ext address = os.path.join('docfile', new_fname) docfile.save(os.path.join(app.config['UPLOAD_FOLDER'], address)) else: return False, 'invalid extension' cursor = execute_modify( "insert into document (description, content, type) " "values (?, ?, '0')", (doc_name, address)) # row count为1表示插入成功 if cursor.rowcount != 1: return False, 'insert failed' else: return True, cursor.lastrowid
def add_visible_school(school_id, doc_id): cursor = execute_modify( 'insert into school_doc(school_id, doc_id) values(?, ?)', [school_id, doc_id]) return cursor.rowcount == 1
def delete_by_id(manager_id): cursor = execute_modify("delete from school_manager where id=?", (manager_id, ), True) return cursor.rowcount == 1
def modify_school(manager_id, school_id): cursor = execute_modify( "update school_manager set school_id=? where id=?", (school_id, manager_id)) return cursor.rowcount == 1
def modify_password(manager_id, password): cursor = execute_modify( "update school_manager set password=? where id=?", (password, manager_id)) return cursor.rowcount == 1
def remove_visible_from_school(school_id): cursor = execute_modify('delete from school_doc where school_id=?', [school_id]) return True
def add_visible_user(user_id, doc_id): cursor = execute_modify( 'insert into user_doc(user_id, doc_id) values(?, ?)', [user_id, doc_id], True) return cursor.rowcount == 1
def remove_visible_from_user(user_id): cursor = execute_modify('delete from user_doc where user_id=?', [user_id]) return True