2023-11-03 00:13:54 +00:00
|
|
|
from .kimaiapi import (
|
2023-11-01 21:11:21 +00:00
|
|
|
KimaiAPI,
|
|
|
|
Customer as KimaiAPICustomer,
|
|
|
|
Project as KimaiAPIProject,
|
|
|
|
Activity as KimaiAPIActivity,
|
2024-12-07 15:08:20 +00:00
|
|
|
Tag as KimaiAPITag,
|
2023-11-01 21:11:21 +00:00
|
|
|
)
|
|
|
|
from .db import (
|
2024-12-07 15:08:20 +00:00
|
|
|
KimaiTag,
|
2023-11-01 21:11:21 +00:00
|
|
|
db,
|
|
|
|
KimaiProject,
|
|
|
|
KimaiCustomer,
|
|
|
|
KimaiActivity,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def sync() -> None:
|
|
|
|
api = KimaiAPI()
|
|
|
|
|
|
|
|
KimaiCustomer.delete().execute()
|
|
|
|
KimaiProject.delete().execute()
|
|
|
|
KimaiActivity.delete().execute()
|
2024-12-07 15:08:20 +00:00
|
|
|
KimaiTag.delete().execute()
|
2023-11-01 21:11:21 +00:00
|
|
|
|
|
|
|
customers = KimaiAPICustomer.list(api)
|
|
|
|
with db.atomic():
|
|
|
|
KimaiCustomer.insert_many(
|
2023-11-03 23:42:11 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": customer.id,
|
|
|
|
"name": customer.name,
|
|
|
|
"visible": customer.visible,
|
|
|
|
}
|
|
|
|
for customer in customers
|
|
|
|
]
|
2023-11-01 21:11:21 +00:00
|
|
|
).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,
|
2023-11-03 23:42:11 +00:00
|
|
|
"visible": project.visible,
|
2023-11-01 21:11:21 +00:00
|
|
|
}
|
|
|
|
for project in projects
|
|
|
|
]
|
|
|
|
).execute()
|
|
|
|
|
|
|
|
activities = KimaiAPIActivity.list(api)
|
|
|
|
with db.atomic():
|
|
|
|
KimaiActivity.insert_many(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": activity.id,
|
|
|
|
"name": activity.name,
|
2023-11-03 23:42:11 +00:00
|
|
|
"project_id": (activity.project.id if activity.project else None),
|
|
|
|
"visible": activity.visible,
|
2023-11-01 21:11:21 +00:00
|
|
|
}
|
|
|
|
for activity in activities
|
|
|
|
]
|
|
|
|
).execute()
|
2024-12-07 15:08:20 +00:00
|
|
|
|
|
|
|
tags = KimaiAPITag.list(api)
|
|
|
|
with db.atomic():
|
|
|
|
KimaiTag.insert_many(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": tag.id,
|
|
|
|
"name": tag.name,
|
|
|
|
"visible": tag.visible,
|
|
|
|
}
|
|
|
|
for tag in tags
|
|
|
|
]
|
|
|
|
).execute()
|