|
| 1 | +from project.topic import Topic |
| 2 | +from project.category import Category |
| 3 | +from project.document import Document |
| 4 | + |
| 5 | + |
| 6 | +class Storage: |
| 7 | + |
| 8 | + def __init__(self): |
| 9 | + self.categories = [] |
| 10 | + self.topics = [] |
| 11 | + self.documents = [] |
| 12 | + |
| 13 | + def add_category(self, category: Category): |
| 14 | + if category not in self.categories: |
| 15 | + self.categories.append(category) |
| 16 | + |
| 17 | + def add_topic(self, topic: Topic): |
| 18 | + if topic not in self.topics: |
| 19 | + self.topics.append(topic) |
| 20 | + |
| 21 | + def add_document(self, document: Document): |
| 22 | + if document not in self.documents: |
| 23 | + self.documents.append(document) |
| 24 | + |
| 25 | + def edit_category(self, category_id, new_name): |
| 26 | + category = [x for x in self.categories if x.id == category_id][0] |
| 27 | + category.edit(new_name) |
| 28 | + |
| 29 | + def edit_topic(self, topic_id, new_topic, new_storage_folder): |
| 30 | + topic = [x for x in self.topics if x.id == topic_id][0] |
| 31 | + topic.edit(new_topic, new_storage_folder) |
| 32 | + |
| 33 | + def edit_document(self, document_id, new_file_name): |
| 34 | + document = [x for x in self.documents if x.id == document_id][0] |
| 35 | + document.edit(new_file_name) |
| 36 | + |
| 37 | + def delete_category(self, category_id): |
| 38 | + self.categories = [x for x in self.categories if x.id != category_id] |
| 39 | + |
| 40 | + def delete_topic(self, topic_id): |
| 41 | + self.topics = [x for x in self.topics if x.id != topic_id] |
| 42 | + |
| 43 | + def delete_document(self, document_id): |
| 44 | + self.documents.remove(self.get_document(document_id)) |
| 45 | + |
| 46 | + def get_document(self, document_id): |
| 47 | + return [x for x in self.documents if x.id == document_id][0] |
| 48 | + |
| 49 | + def __repr__(self): |
| 50 | + return '\n'.join([str(doc) for doc in self.documents]) |
| 51 | + |
0 commit comments