Spaces:
Sleeping
Sleeping
File size: 1,632 Bytes
54af9e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import abc
import json
from streamlit_local_storage import LocalStorage
ls: LocalStorage = LocalStorage()
class SavedDetails(abc.ABC):
def __init__(self, type_: str):
self.type_ = type_
def save_to_local_storage(self, key: str):
ls.setItem(key, json.dumps(self.__dict__))
@classmethod
def load(cls, json_data: str):
data = json.loads(json_data)
type_ = data.get("type_")
if not type_ or type_ != cls.type_:
raise ValueError(f"the expected type is {cls.type_} but is actually {type_}")
return cls.__init__(**{k: v for k, v in data if k != "type"})
class PersonalDetails(SavedDetails):
type_ = "personal_details"
def __init__(self, full_name, email, contact_number):
super().__init__(self.type_)
self.full_name = full_name
self.email = email
self.contact_number = contact_number
class LocationDetails(SavedDetails):
type_ = "location_details"
def __init__(self, owner_or_tenant: str, community: str, building: str, unit_number: str):
super().__init__(self.type_)
self.owner_or_tenant = owner_or_tenant
self.community = community
self.building = building
self.unit_number = unit_number
class ContractorDetails(SavedDetails):
type_ = "contractor_details"
def __init__(self, contractor_name:str, contractor_contact_number:str, contractor_email:str):
super().__init__(self.type_)
self.contractor_name = contractor_name
self.contractor_contact_number = contractor_contact_number
self.contractor_email = contractor_email
|