Advertisement
horozov86

Document_Management_Class_Storage

Jul 10th, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. class Storage:
  2.     def __init__(self):
  3.         self.categories = []
  4.         self.topics = []
  5.         self.documents = []
  6.        
  7.     def add_category(self, category: Category):
  8.         if category in self.categories:
  9.             return
  10.         self.categories.append(category)
  11.        
  12.        
  13.     def add_topic(self, topic:Topic):
  14.         if topic in self.topics:
  15.             return
  16.         self.topics.append(topic)
  17.        
  18.        
  19.     def add_document(self, document: Document):
  20.         if document in self.documents:
  21.             return
  22.         self.documents.append(document)
  23.        
  24.    
  25.     def edit_category(self, category_id, new_name):
  26.         category = self.__find_my_id(self.categories, category_id)
  27.         category.edit(new_name)
  28.        
  29.     def edit_topic(self, topic_id: int, new_topic: str, new_storage_folder: str):
  30.         topic = self.__find_my_id(self.topics, topic_id)
  31.         topic.edit(new_topic, new_storage_folder)
  32.        
  33.     def edit_document(self, document_id: int, new_file_name: str):
  34.         document = self.__find_my_id(self.documents, document_id)
  35.         document.edit(new_file_name)
  36.        
  37.     def delete_category(self, category_id):
  38.         category = self.__find_my_id(self.categories, category_id)
  39.         self.categories.remove(category)
  40.        
  41.     def delete_topic(self, topic_id):
  42.         topic = self.__find_my_id(self.topics, topic_id)
  43.         self.topics.remove(topic)
  44.        
  45.     def delete_document(self, document_id):
  46.         document = self.__find_my_id(self.documents, document_id)
  47.         self.topics.remove(document)
  48.        
  49.     def get_document(self, ):
  50.         return self.__find_my_id(self.document, document_id)
  51.        
  52.     def __repr__(self):
  53.         return "\n".join([repr(x) for x in self.documents])
  54.    
  55.    
  56.    
  57.     def __find_my_id(self, entities, entity_id):
  58.         for entity in entities:
  59.             if entity.id = entity_id:
  60.                 return entity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement