def new_file(self, file: File, course_id: int, course_fullname: str): # saves a file to index conn = sqlite3.connect(self.db_file) cursor = conn.cursor() data = {'course_id': course_id, 'course_fullname': course_fullname} data.update(file.getMap()) cursor.execute( """INSERT INTO files (course_id, course_fullname, module_id, section_name, module_name, content_filepath, content_filename, content_fileurl, content_filesize, content_timemodified, module_modname, content_type, content_isexternalfile, saved_to, time_stamp, modified, deleted, notified, hash) VALUES (:course_id, :course_fullname, :module_id, :section_name, :module_name, :content_filepath, :content_filename, :content_fileurl, :content_filesize, :content_timemodified, :module_modname, :content_type, :content_isexternalfile, :saved_to, :time_stamp, :modified, :deleted, 0, :hash); """, data) conn.commit() conn.close()
def modifie_file(self, file: File, course_id: int, course_fullname: str): conn = sqlite3.connect(self.db_file) cursor = conn.cursor() data_new = {'course_id': course_id, 'course_fullname': course_fullname} data_new.update(file.getMap()) if file.old_file is not None: # insert a new file, # but it is already notified because the same file already exists # as modified data_new.update({ 'old_file_id': file.old_file.file_id, 'modified': 0, 'moved': 0, 'deleted': 0, 'notified': 1 }) cursor.execute(File.INSERT, data_new) data_old = { 'course_id': course_id, 'course_fullname': course_fullname } data_old.update(file.old_file.getMap()) cursor.execute( """UPDATE files SET notified = 0, modified = 1, saved_to = :saved_to WHERE file_id = :file_id; """, data_old, ) else: # this should never happen, but the old file is not saved in the # file descriptor, so we need to inform about the new file # notified = 0 data_new.update({ 'modified': 0, 'deleted': 0, 'moved': 0, 'notified': 0 }) cursor.execute(File.INSERT, data_new) conn.commit() conn.close()
def delete_file(self, file: File, course_id: int, course_fullname: str): conn = sqlite3.connect(self.db_file) cursor = conn.cursor() data = {'course_id': course_id, 'course_fullname': course_fullname} data.update(file.getMap()) cursor.execute( """UPDATE files SET notified = 0, deleted = 1, time_stamp = :time_stamp WHERE file_id = :file_id; """, data) conn.commit() conn.close()
def new_file(self, file: File, course_id: int, course_fullname: str): # saves a file to index conn = sqlite3.connect(self.db_file) cursor = conn.cursor() data = {'course_id': course_id, 'course_fullname': course_fullname} data.update(file.getMap()) data.update({'modified': 0, 'deleted': 0, 'moved': 0, 'notified': 0}) cursor.execute(File.INSERT, data) conn.commit() conn.close()
def delete_file(self, file: File, course_id: int, course_fullname: str): conn = sqlite3.connect(self.db_file) cursor = conn.cursor() data = {'course_id': course_id, 'course_fullname': course_fullname} data.update(file.getMap()) cursor.execute( """UPDATE files SET notified = 0, deleted = 1, time_stamp = :time_stamp WHERE module_id = :module_id AND course_id = :course_id AND course_fullname = :course_fullname AND section_name = :section_name AND content_filepath = :content_filepath AND content_filename = :content_filename AND content_fileurl = :content_fileurl AND content_filesize = :content_filesize AND content_timemodified = :content_timemodified AND deleted = 0; """, data) conn.commit() conn.close()