file to db and db to file

This commit is contained in:
buenosairesam
2025-05-09 02:20:55 -03:00
parent 242928d502
commit f531be7158
6 changed files with 268 additions and 34 deletions

35
dmapp/dmcore/state.py Normal file
View File

@@ -0,0 +1,35 @@
from pymongo import MongoClient
client = MongoClient()
db = client.deskmeter
state = db.state
def update_current_task(task):
state.update_one(
{"_id": "current_task"},
{"$set": {"task": task}},
upsert=True,
)
def update_current_workspace(workspace):
state.update_one(
{"_id": "current_workspace"},
{"$set": {"workspace": workspace}},
upsert=True,
)
def get_current_task():
current_task = state.find_one({"_id": "current_task"})
if current_task:
return current_task.get("task")
return None
def get_current_workspace():
current_workspace = state.find_one({"_id": "current_workspace"})
if current_workspace:
return current_workspace.get("workspace")
return None