first commit
This commit is contained in:
commit
e6c52820cd
227 changed files with 16156 additions and 0 deletions
67
modules/projects/project.py
Normal file
67
modules/projects/project.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
def _slugify(value: str) -> str:
|
||||
value = value.strip().lower()
|
||||
value = re.sub(r'[^a-z0-9\-_\s]+', '', value)
|
||||
value = re.sub(r'[\s]+', '-', value)
|
||||
return value
|
||||
|
||||
|
||||
class Project:
|
||||
def __init__(
|
||||
self,
|
||||
client_id: str,
|
||||
name: str,
|
||||
status: str = 'Nouveau',
|
||||
start_date: Optional[str] = None,
|
||||
end_date: Optional[str] = None,
|
||||
description: str = '',
|
||||
budget: Optional[float] = None,
|
||||
id: Optional[str] = None,
|
||||
created_at: Optional[str] = None,
|
||||
updated_at: Optional[str] = None
|
||||
):
|
||||
self.client_id = client_id
|
||||
self.name = name
|
||||
self.status = status
|
||||
self.start_date = start_date
|
||||
self.end_date = end_date
|
||||
self.description = description
|
||||
self.budget = budget
|
||||
self.id = id or f"{_slugify(name)}-{uuid.uuid4().hex[:8]}"
|
||||
now_iso = datetime.utcnow().isoformat()
|
||||
self.created_at = created_at or now_iso
|
||||
self.updated_at = updated_at or now_iso
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"id": self.id,
|
||||
"client_id": self.client_id,
|
||||
"name": self.name,
|
||||
"status": self.status,
|
||||
"start_date": self.start_date,
|
||||
"end_date": self.end_date,
|
||||
"description": self.description,
|
||||
"budget": self.budget,
|
||||
"created_at": self.created_at,
|
||||
"updated_at": self.updated_at,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data: Dict[str, Any]) -> 'Project':
|
||||
return Project(
|
||||
client_id=data.get("client_id"),
|
||||
name=data.get("name", ""),
|
||||
status=data.get("status", "Nouveau"),
|
||||
start_date=data.get("start_date"),
|
||||
end_date=data.get("end_date"),
|
||||
description=data.get("description", ""),
|
||||
budget=data.get("budget"),
|
||||
id=data.get("id"),
|
||||
created_at=data.get("created_at"),
|
||||
updated_at=data.get("updated_at"),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue