Spaces:
Sleeping
Sleeping
File size: 1,416 Bytes
cb7ff7d 88f9105 cb7ff7d 88f9105 cb7ff7d 88f9105 cb7ff7d 88f9105 cb7ff7d 88f9105 cb7ff7d 6508ff2 cb7ff7d 6508ff2 cb7ff7d |
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 |
import json
from streamlit_local_storage import LocalStorage
from local_storage.entities import SavedDetails, PersonalDetails, LocationDetails, ContractorDetails
from enums import DetailsType
def get_detail(key: str):
for detail_type in DetailsType.values():
detail = LocalStorage(key=detail_type.name).getItem(detail_type.name).get(key)
if detail:
if detail_type.value == DetailsType.PERSONAL_DETAILS.value:
return PersonalDetails(**detail)
elif detail_type.value == DetailsType.LOCATION_DETAILS.value:
return LocationDetails(**detail)
elif detail_type.value == DetailsType.CONTRACTOR_DETAILS.value:
return ContractorDetails(**detail)
return None
return None
def save_details(details: SavedDetails, key: str):
if isinstance(details, PersonalDetails):
type_ = DetailsType.PERSONAL_DETAILS
elif isinstance(details, LocationDetails):
type_ = DetailsType.LOCATION_DETAILS
elif isinstance(details, ContractorDetails):
type_ = DetailsType.CONTRACTOR_DETAILS
else:
raise ValueError("Unexpected type: {}", type(details))
existing_data = (ls.getItem(type_.name) or {})
existing_data[key] = details.to_json()
ls.setItem(type_.name, existing_data, type_.name)
def get_details(type_: DetailsType):
return ls.getItem(type_.name) or {}
|