def set_star(self, file_id): """Takes unique file's _id. Sets new value to the file""" self.write_log(call_function='set_star', file_id=file_id) f_col = self.get_files_col() star = f_col.find_one({ '_id': obj_id(file_id), 'deleted': False })['star'] if star: star = False else: star = True f_col.update_one({'_id': obj_id(file_id)}, {'$set': {'star': star}})
def del_tags(self, file_id, tags: list): """Takes unique file's _id and list of tags. Deletes tags from this file""" self.write_log(call_function='del_tags', file_id=file_id, tags=tags) f_col = self.get_files_col() f_col.update_one({'_id': obj_id(file_id)}, {'$pullAll': { 'tags': tags }})
def del_fully(self, file_id): """Takes unique file's _id. Switches fully_deleted flag to Tru for this file""" self.write_log(call_function='del_fully', file_id=file_id) f_col = self.get_files_col() f_col.update_one({'_id': obj_id(file_id)}, {'$set': { 'fully_deleted': True }})
def revert_file(self, file_id): """Takes unique file's _id. Switches deleted flag to False for this file""" self.write_log(call_function='revert_file', file_id=file_id) f_col = self.get_files_col() f_col.update_one({'_id': obj_id(file_id)}, {'$set': { 'deleted': False }})
def add_tags(self, file_id, tags: list): """Takes unique file's _id and list of tags. Adds tags to this file""" self.write_log(call_function='add_tags', file_id=file_id, tags=tags) f_col = self.get_files_col() for tag in tags: f_col.update_one({'_id': obj_id(file_id)}, {'$addToSet': { 'tags': tag }})
def add_comment(self, file_id, comment: str): """Takes unique file's _id. Adds a comment to this file""" self.write_log(call_function='add_comment', file_id=file_id, comment=comment) f_col = self.get_files_col() f_col.update_one({'_id': obj_id(file_id)}, {'$set': { 'comment': comment }})
def update_user(self, user_id, login: str, pas: bytes, email: str): """Takes unique user's _id, new login, new password, new email. Updates user's data""" self.write_log(call_function="update_user", user_id=user_id, login=login, email=email) u_col = self.get_users_col() u_col.update_one( {'_id': obj_id(user_id)}, {'$set': { 'login': login, 'pas': pas, 'email': email }})
def update_file(self, file_id, name: str, size: int, comment, tags: list): """Takes unique file's _id, new file name, new size, new comment, new list of tags. Updates file's data""" self.write_log(call_function='update_file', file_id=file_id, name=name, size=size, comment=comment, tags=tags) f_col = self.get_files_col() f_col.update_one({'_id': obj_id(file_id)}, { '$set': { 'name': name, 'size': size, 'comment': comment, 'tags': tags } })
def del_user(self, user_id=None, login=None): """Takes unique user's _id or user's login. Switches deleted flag to Tru for this user""" self.write_log(call_function="del_user", user_id=user_id, login=login) u_col = self.get_users_col() if user_id or login: u_col.update_one( {'$or': [{ '_id': obj_id(user_id) }, { 'login': login }]}, {'$set': { 'deleted': True }}) else: self.write_log( call_function="remake_files", exception= 'Could not delete user. Did you forget to enter user\'s _id or user\'s login?' ) raise Exception( 'Could not delete user. Did you forget to enter user\'s _id or user\'s login?' )
def get_file(self, file_id, deleted=False): """Takes unique file's _id. Returns file information of this file""" self.write_log(call_function='get_file', file_id=file_id) f_col = self.get_files_col() return f_col.find_one({'_id': obj_id(file_id), 'deleted': deleted})