Kompletter Rewrite
This commit is contained in:
31
models/category.py
Normal file
31
models/category.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from typing import List, Set
|
||||
|
||||
|
||||
class CategoryManager:
|
||||
def __init__(self):
|
||||
self._categories: Set[str] = set()
|
||||
|
||||
@property
|
||||
def categories(self) -> List[str]:
|
||||
return sorted(list(self._categories))
|
||||
|
||||
def add_category(self, category: str) -> bool:
|
||||
if not category or category in self._categories:
|
||||
return False
|
||||
self._categories.add(category)
|
||||
return True
|
||||
|
||||
def remove_category(self, category: str) -> bool:
|
||||
if category not in self._categories:
|
||||
return False
|
||||
self._categories.remove(category)
|
||||
return True
|
||||
|
||||
def has_category(self, category: str) -> bool:
|
||||
return category in self._categories
|
||||
|
||||
def load_from_data(self, categories: List[str]):
|
||||
self._categories = set(categories)
|
||||
|
||||
def to_list(self) -> List[str]:
|
||||
return self.categories
|
||||
Reference in New Issue
Block a user