Break out sync to separate file
This commit is contained in:
@ -30,6 +30,7 @@ from .kimai import (
|
||||
Project as KimaiAPIProject,
|
||||
Activity as KimaiAPIActivity,
|
||||
)
|
||||
from .sync import sync
|
||||
|
||||
|
||||
class ListScreen(Screen):
|
||||
@ -601,47 +602,7 @@ class KimaiProjectListScreen(ListScreen):
|
||||
self.table.sort(self.sort)
|
||||
|
||||
def action_get(self) -> None:
|
||||
api = KimaiAPI()
|
||||
|
||||
KimaiCustomer.delete().execute()
|
||||
KimaiProject.delete().execute()
|
||||
KimaiActivity.delete().execute()
|
||||
|
||||
customers = KimaiAPICustomer.list(api)
|
||||
with db.atomic():
|
||||
KimaiCustomer.insert_many(
|
||||
[{"id": customer.id, "name": customer.name} for customer in customers]
|
||||
).execute()
|
||||
|
||||
projects = KimaiAPIProject.list(api)
|
||||
with db.atomic():
|
||||
KimaiProject.insert_many(
|
||||
[
|
||||
{
|
||||
"id": project.id,
|
||||
"name": project.name,
|
||||
"customer_id": project.customer.id,
|
||||
"allow_global_activities": project.allow_global_activities,
|
||||
}
|
||||
for project in projects
|
||||
]
|
||||
).execute()
|
||||
|
||||
activities = KimaiAPIActivity.list(api)
|
||||
with db.atomic():
|
||||
KimaiActivity.insert_many(
|
||||
[
|
||||
{
|
||||
"id": activity.id,
|
||||
"name": activity.name,
|
||||
"project_id": (
|
||||
activity.project and activity.project.id or None
|
||||
),
|
||||
}
|
||||
for activity in activities
|
||||
]
|
||||
).execute()
|
||||
|
||||
sync()
|
||||
self._refresh()
|
||||
|
||||
def on_mount(self) -> None:
|
||||
|
Reference in New Issue
Block a user