Kompletter Rewrite
This commit is contained in:
0
models/__init__.py
Normal file
0
models/__init__.py
Normal file
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
|
||||
39
models/program.py
Normal file
39
models/program.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class Program:
|
||||
name: str
|
||||
path: str
|
||||
category: Optional[str] = None
|
||||
requires_admin: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
if not self.name:
|
||||
raise ValueError("Program name cannot be empty")
|
||||
if not self.path:
|
||||
raise ValueError("Program path cannot be empty")
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
result = {
|
||||
"Name": self.name,
|
||||
"Pfad": self.path
|
||||
}
|
||||
if self.category:
|
||||
result["Kategorie"] = self.category
|
||||
if self.requires_admin:
|
||||
result["Adminrechte"] = True
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> 'Program':
|
||||
return cls(
|
||||
name=data["Name"],
|
||||
path=data["Pfad"],
|
||||
category=data.get("Kategorie"),
|
||||
requires_admin=data.get("Adminrechte", False)
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} ({self.category or 'Ohne Kategorie'})"
|
||||
Reference in New Issue
Block a user