Repository navigation
Expand file tree
/
Copy pathconfig_handler.py
More file actions
120 lines (102 loc) · 3.83 KB
/
Copy pathconfig_handler.py
File metadata and controls
120 lines (102 loc) · 3.83 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import json
import sqlite3
from pathlib import Path
CONFIG_PATH = Path(__file__).parent / "config.json"
DEFAULTS = {
"system_name": "案件管理システム",
"theme_id": "default",
"db_dir": str(Path.home() / "Public"),
"db_file": "app.db",
"db_backend": "sqlite",
"logo_path": "",
"notification": "none",
"auto_sort_on_status_change": True,
"show_co": True,
"use_ai_summary": True,
}
def load() -> dict:
if not CONFIG_PATH.exists():
return DEFAULTS.copy()
with open(CONFIG_PATH, encoding="utf-8") as f:
data = json.load(f)
cfg = {**DEFAULTS, **data}
return cfg
def save(cfg: dict):
# 旧キーを残さない
clean = {k: v for k, v in cfg.items() if k in {
"system_name", "theme_id", "db_dir", "db_file", "db_backend",
"logo_path", "notification", "auto_sort_on_status_change", "show_co", "use_ai_summary",
}}
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
json.dump(clean, f, ensure_ascii=False, indent=2)
def get_data_path() -> Path:
cfg = load()
return Path(cfg["db_dir"]) / cfg["db_file"]
def is_sqlite() -> bool:
return get_data_path().suffix == ".db"
def list_db_files(db_dir: str, backend: str) -> list[str]:
d = Path(db_dir)
if not d.is_dir():
return []
ext = ".db" if backend == "sqlite" else ".xlsx"
return sorted(p.name for p in d.iterdir() if p.suffix == ext and p.is_file())
def create_new_db(db_dir: str, filename: str, backend: str) -> Path:
d = Path(db_dir)
d.mkdir(parents=True, exist_ok=True)
path = d / filename
if backend == "sqlite":
con = sqlite3.connect(str(path))
con.execute("""
CREATE TABLE IF NOT EXISTS engagements (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uketsuke_no TEXT UNIQUE NOT NULL,
uketsuke_date TEXT DEFAULT '',
irai_sha TEXT DEFAULT '',
kaisha_mei TEXT DEFAULT '',
renraku_saki TEXT DEFAULT '',
toiawase TEXT DEFAULT '',
co TEXT DEFAULT 'W',
renraku_date TEXT DEFAULT '',
phase TEXT DEFAULT 'inquiry',
status TEXT DEFAULT '対応中',
end_state TEXT DEFAULT '',
anken_no TEXT DEFAULT '',
anken_mei TEXT DEFAULT '',
irai_date TEXT DEFAULT '',
kingaku TEXT DEFAULT '',
juchu_date TEXT DEFAULT '',
kakunin_date TEXT DEFAULT '',
nouki TEXT DEFAULT '',
sagyou_kanryo TEXT DEFAULT '',
nyukin TEXT DEFAULT '',
botsu_riyu TEXT DEFAULT '',
revision_count INTEGER DEFAULT 0,
memo TEXT DEFAULT '',
created_at TEXT DEFAULT ''
)""")
con.commit()
con.close()
else:
import openpyxl
wb = openpyxl.Workbook()
ws1 = wb.active
ws1.title = "受付管理"
ws1.append(["受付No", "受付日", "依頼者", "会社名", "連絡先",
"問い合わせ", "Co", "次回連絡日", "ステータス", "進捗メモ"])
ws2 = wb.create_sheet("案件管理")
ws2.append(["管理番号", "受付No", "依頼日", "案件名", "金額",
"受注日", "納期", "作業完了日", "入金", "ステータス",
"確認日", "修正回数"])
wb.save(str(path))
return path
def get_themes() -> list:
themes_path = Path(__file__).parent / "themes.json"
with open(themes_path, encoding="utf-8") as f:
return json.load(f)
def get_current_theme() -> dict:
cfg = load()
theme_id = cfg.get("theme_id", "default")
for t in get_themes():
if t["id"] == theme_id:
return t
return get_themes()[0]