First attempt
This commit is contained in:
commit
89677fbeee
22 changed files with 3461 additions and 0 deletions
45
voc/room.py
Normal file
45
voc/room.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from dataclasses import dataclass, fields
|
||||
|
||||
try:
|
||||
from voc.event import Schedule
|
||||
from voc.tools import gen_uuid, normalise_string
|
||||
except:
|
||||
from event import Schedule
|
||||
from tools import gen_uuid, normalise_string
|
||||
|
||||
@dataclass
|
||||
class Room:
|
||||
guid: str = None
|
||||
name: str = None
|
||||
stream: str = None
|
||||
description: str = None
|
||||
capacity: int = None
|
||||
location: str = None
|
||||
|
||||
_parent: Schedule = None
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict):
|
||||
assert isinstance(data, dict), 'Data must be a dictionary.'
|
||||
|
||||
fieldSet = {f.name for f in fields(cls) if f.init}
|
||||
filteredData = {k: v for k, v in data.items() if k in fieldSet}
|
||||
|
||||
return cls(**filteredData)
|
||||
|
||||
def graphql(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'guid': self.guid or gen_uuid(self.name),
|
||||
'description': self.description,
|
||||
# 'stream_id': room.stream,
|
||||
'slug': normalise_string(self.name.lower()),
|
||||
'meta': {'location': self.location},
|
||||
}
|
||||
|
||||
# @name.setter
|
||||
def update_name(self, new_name: str, update_parent=True):
|
||||
if self._parent and update_parent:
|
||||
self._parent.rename_rooms({self.name: new_name})
|
||||
|
||||
self.name = new_name
|
||||
Loading…
Add table
Add a link
Reference in a new issue