warchron_app/src/warchron/model/campaign.py

62 lines
1.6 KiB
Python
Raw Normal View History

2026-01-19 18:55:07 +01:00
from uuid import uuid4
from datetime import datetime
from warchron.model.round import Round
class Campaign:
def __init__(self, name):
self.id = str(uuid4())
self.name = name
self.month = datetime.now().month
self.entrants = {}
2026-01-21 07:43:04 +01:00
self.rounds = []
2026-01-19 18:55:07 +01:00
self.is_over = False
def set_id(self, new_id):
self.id = new_id
def set_name(self, new_name):
self.name = new_name
def set_month(self, new_month):
self.month = new_month
def set_state(self, new_state):
self.is_over = new_state
def toDict(self):
return {
"id" : self.id,
"name" : self.name,
"month" : self.month,
2026-01-21 08:31:48 +01:00
# "entrants" : self.entrants,
"rounds": [rnd.toDict() for rnd in self.rounds],
2026-01-19 18:55:07 +01:00
"is_over": self.is_over
}
@staticmethod
2026-01-21 08:31:48 +01:00
def fromDict(data: dict):
camp = Campaign(name=data["name"])
camp.set_id(data["id"])
camp.set_month(data["month"])
# camp.entrants = data.get("entrants", {})
for rnd_data in data.get("rounds", []):
camp.rounds.append(Round.fromDict(rnd_data))
camp.set_state(data.get("is_over", False))
return camp
2026-01-21 07:43:04 +01:00
def add_round(self, number: int) -> Round:
round = Round()
self.rounds.append(round)
return round
def get_round(self, round_id) -> Round:
return self.rounds[round_id]
def get_all_rounds(self) -> list[Round]:
return list(self.rounds)
def add_round(self) -> Round:
round = Round()
self.rounds.append(round)
return round