edupsyadmin 10.2.0__tar.gz → 10.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/PKG-INFO +2 -2
  2. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/pyproject.toml +2 -3
  3. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/pyproject.toml.orig +3 -3
  4. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/__version__.py +1 -1
  5. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/fill_form.py +1 -1
  6. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/lgvt.py +2 -2
  7. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/setup_demo.py +16 -8
  8. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/new_client.py +128 -91
  9. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/config.py +7 -5
  10. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/editconfig_app.py +3 -13
  11. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/fill_form_app.py +1 -1
  12. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/fill_form_widget.py +1 -1
  13. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/README.md +0 -0
  14. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/__init__.py +0 -0
  15. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/__main__.py +0 -0
  16. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/README +0 -0
  17. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/env.py +0 -0
  18. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/script.py.mako +0 -0
  19. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_02_21_0453-4087c43f0c7c_initial_migration.py +0 -0
  20. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_03_02_1222-635a9d68fbe8_add_case_active_column_to_clients.py +0 -0
  21. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_03_13_0545-ea4c3f900604_encrypt_class_columns.py +0 -0
  22. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_03_13_0620-515a72d06f10_encrypt_derived_dates.py +0 -0
  23. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_03_16_0900-d7e8f9a0b1c2_add_metadata_table.py +0 -0
  24. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_03_23_1030-e2b4c6d8f0a1_encrypt_sensitive_text_fields.py +0 -0
  25. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_04_10_1200-f3a5b7c9d1e2_set_encrypted_text_fields_non_nullable.py +0 -0
  26. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_06_12_0509-0f1497df963e_add_class_int_override.py +0 -0
  27. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic/versions/2026_09_09_1057-91edbee23274_add_record_academic_year.py +0 -0
  28. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/alembic.ini +0 -0
  29. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/__init__.py +0 -0
  30. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/cft_report.py +0 -0
  31. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/client_view.py +0 -0
  32. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/display_client_details.py +0 -0
  33. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/exceptions.py +0 -0
  34. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/flatten_pdf.py +0 -0
  35. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/flattening/__init__.py +0 -0
  36. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/flattening/api.py +0 -0
  37. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/flattening/base.py +0 -0
  38. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/flattening/pypdf_backend.py +0 -0
  39. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/managers.py +0 -0
  40. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/migration.py +0 -0
  41. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/migration_fs.py +0 -0
  42. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/reports.py +0 -0
  43. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/taetigkeitsbericht_from_db.py +0 -0
  44. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/api/types.py +0 -0
  45. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/__init__.py +0 -0
  46. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/__main__.py +0 -0
  47. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/check_shredding.py +0 -0
  48. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/copy_client.py +0 -0
  49. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/create_documentation.py +0 -0
  50. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/delete_client.py +0 -0
  51. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/edit_config.py +0 -0
  52. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/flatten_pdfs.py +0 -0
  53. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/get_clients.py +0 -0
  54. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/info.py +0 -0
  55. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/mk_report.py +0 -0
  56. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/rotate_key.py +0 -0
  57. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/set_client.py +0 -0
  58. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/setup_demo.py +0 -0
  59. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/taetigkeitsbericht.py +0 -0
  60. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/commands/tui.py +0 -0
  61. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/cli/utils.py +0 -0
  62. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/__init__.py +0 -0
  63. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/encrypt.py +0 -0
  64. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/enums.py +0 -0
  65. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/logger.py +0 -0
  66. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/core/paths.py +0 -0
  67. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/Faecher_BfsEV.txt +0 -0
  68. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/Faecher_BfsKi.txt +0 -0
  69. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/Faecher_Faks.txt +0 -0
  70. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/LiberationSans-Bold.ttf +0 -0
  71. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/LiberationSans-Regular.ttf +0 -0
  72. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/OFL.txt +0 -0
  73. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/sampleconfig.yml +0 -0
  74. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/data/taetigkeitsbericht_categories.csv +0 -0
  75. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/db/__init__.py +0 -0
  76. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/db/clients.py +0 -0
  77. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/db/column_types.py +0 -0
  78. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/db/converters.py +0 -0
  79. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/info.py +0 -0
  80. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/py.typed +0 -0
  81. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/__init__.py +0 -0
  82. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/clients_overview.py +0 -0
  83. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/clients_overview_app.py +0 -0
  84. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/dialogs.py +0 -0
  85. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/edit_client.py +0 -0
  86. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/edit_client_app.py +0 -0
  87. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/editconfig.py +0 -0
  88. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/editconfig.tcss +0 -0
  89. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/edupsyadmintui.py +0 -0
  90. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/edupsyadmintui.tcss +0 -0
  91. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/tui/suggesters.py +0 -0
  92. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/__init__.py +0 -0
  93. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/academic_year.py +0 -0
  94. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/convert_measures.py +0 -0
  95. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/datediff.py +0 -0
  96. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/int_from_str.py +0 -0
  97. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/path_utils.py +0 -0
  98. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/python_type.py +0 -0
  99. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/rounding.py +0 -0
  100. {edupsyadmin-10.2.0 → edupsyadmin-10.2.2}/src/edupsyadmin/utils/taetigkeitsbericht_check_key.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edupsyadmin
3
- Version: 10.2.0
3
+ Version: 10.2.2
4
4
  Summary: edupsyadmin provides tools to help school psychologists with their documentation
5
5
  Author: Lukas Liebermann
6
6
  License: MIT
@@ -10,11 +10,11 @@ Requires-Dist: alembic>=1.18
10
10
  Requires-Dist: cryptography>=50
11
11
  Requires-Dist: keyring>=25.7
12
12
  Requires-Dist: platformdirs>=4.10
13
+ Requires-Dist: py-yaml12>=0.2
13
14
  Requires-Dist: pydantic>=2.13
14
15
  Requires-Dist: pypdf>=6.21
15
16
  Requires-Dist: python-dateutil>=2.9
16
17
  Requires-Dist: python-liquid>=2
17
- Requires-Dist: pyyaml>=6.0.3
18
18
  Requires-Dist: rich>=15
19
19
  Requires-Dist: sqlalchemy>=2.1
20
20
  Requires-Dist: textual>=8.2
@@ -4,7 +4,7 @@ requires = ["uv-build>=0.13.6,<0.14"]
4
4
 
5
5
  [project]
6
6
  name = "edupsyadmin"
7
- version = "10.2.0"
7
+ version = "10.2.2"
8
8
  description = "edupsyadmin provides tools to help school psychologists with their documentation"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.15"
@@ -17,11 +17,11 @@ dependencies = [
17
17
  "cryptography>=50",
18
18
  "keyring>=25.7",
19
19
  "platformdirs>=4.10",
20
+ "py-yaml12>=0.2",
20
21
  "pydantic>=2.13",
21
22
  "pypdf>=6.21",
22
23
  "python-dateutil>=2.9",
23
24
  "python-liquid>=2",
24
- "pyyaml>=6.0.3",
25
25
  "rich>=15",
26
26
  "sqlalchemy>=2.1",
27
27
  "textual>=8.2",
@@ -68,7 +68,6 @@ dev = [
68
68
  "ty>=0.0.40",
69
69
  "types-greenlet>=3.1.0.20241221",
70
70
  "types-python-dateutil>=2.9.0.20241206",
71
- "types-pyyaml>=6.0.12.20241221",
72
71
  ]
73
72
 
74
73
  [tool.uv]
@@ -4,7 +4,7 @@ requires = [ "uv-build>=0.13.6,<0.14" ]
4
4
 
5
5
  [project]
6
6
  name = "edupsyadmin"
7
- version = "10.2.0"
7
+ version = "10.2.2"
8
8
  description = "edupsyadmin provides tools to help school psychologists with their documentation"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -19,11 +19,11 @@ dependencies = [
19
19
  "cryptography>=50",
20
20
  "keyring>=25.7",
21
21
  "platformdirs>=4.10",
22
+ "py-yaml12>=0.2",
22
23
  "pydantic>=2.13",
23
24
  "pypdf>=6.21",
24
25
  "python-dateutil>=2.9",
25
26
  "python-liquid>=2",
26
- "pyyaml>=6.0.3",
27
27
  "rich>=15",
28
28
  "sqlalchemy>=2.1",
29
29
  "textual>=8.2",
@@ -58,12 +58,12 @@ dev = [
58
58
  "ty>=0.0.40",
59
59
  "types-greenlet>=3.1.0.20241221",
60
60
  "types-python-dateutil>=2.9.0.20241206",
61
- "types-pyyaml>=6.0.12.20241221",
62
61
  ]
63
62
 
64
63
  [tool.uv]
65
64
  exclude-newer = "3d"
66
65
  # TODO: remove this workaround when pyyaml wheels for 3.15 are released
66
+ # This line is still necessary for commitizen which depends on pyyaml
67
67
  extra-build-variables.pyyaml = { PYYAML_FORCE_LIBYAML = "0" }
68
68
 
69
69
  [tool.ruff]
@@ -18,4 +18,4 @@ and backwards compatibility is not guaranteed for minor versions.
18
18
 
19
19
  __all__ = ["__version__"]
20
20
 
21
- __version__ = "10.2.0"
21
+ __version__ = "10.2.2"
@@ -243,7 +243,7 @@ def write_form_md(fn: Path, out_fn: Path, data: Mapping[str, Any]) -> None:
243
243
  raise
244
244
 
245
245
  try:
246
- msg = template.render(**data)
246
+ msg = template.render(data)
247
247
  except LiquidError as e:
248
248
  e.add_note(
249
249
  "The template could be parsed, but there was an issue with "
@@ -407,10 +407,10 @@ def mk_report(
407
407
  incorrect_answ=incorrect_answ,
408
408
  num_processed=num_processed,
409
409
  words_after_last_item=words_after_last_item,
410
- lv_pr_korr=round_half_up(lv_pr_korr, 2), # round for printing
410
+ lv_pr_korr=lv_pr_korr,
411
411
  lgs_pr_korr=lgs_pr_korr,
412
412
  lg_pr=lg_pr,
413
- lv_rw_korr=lv_rw_korr,
413
+ lv_rw_korr=round_half_up(lv_rw_korr, 2), # round for printing
414
414
  lgs_rw_korr=lgs_rw_korr,
415
415
  )
416
416
 
@@ -1,7 +1,7 @@
1
1
  import importlib.resources
2
2
  from pathlib import Path
3
3
 
4
- import yaml
4
+ from yaml12 import read_yaml, write_yaml
5
5
 
6
6
  from edupsyadmin.api.managers import ClientsManager
7
7
  from edupsyadmin.api.migration import upgrade_db
@@ -32,16 +32,24 @@ def setup_demo() -> None:
32
32
  demo_salt_path.unlink(missing_ok=True)
33
33
 
34
34
  # Load default config and customize for demo
35
- template_path = importlib.resources.files("edupsyadmin.data") / "sampleconfig.yml"
36
- with template_path.open("r", encoding="utf-8") as f:
37
- demo_config = yaml.safe_load(f)
35
+ template_resource = (
36
+ importlib.resources.files("edupsyadmin.data") / "sampleconfig.yml"
37
+ )
38
+ with importlib.resources.as_file(template_resource) as template_path:
39
+ demo_config = read_yaml(template_path)
40
+
41
+ if not isinstance(demo_config, dict):
42
+ raise TypeError("sampleconfig.yml must contain a mapping.")
43
+
44
+ core = demo_config.get("core")
45
+ if not isinstance(core, dict):
46
+ raise TypeError("sampleconfig.yml missing core section.")
38
47
 
39
48
  # Customize for demo
40
- demo_config["core"]["app_uid"] = demo_app_uid
41
- demo_config["core"]["app_username"] = demo_username
49
+ core["app_uid"] = demo_app_uid
50
+ core["app_username"] = demo_username
42
51
 
43
- with demo_config_path.open("w", encoding="utf-8") as f:
44
- yaml.dump(demo_config, f)
52
+ write_yaml(demo_config, demo_config_path)
45
53
 
46
54
  # Load the new demo config
47
55
  config.load(demo_config_path)
@@ -1,9 +1,7 @@
1
1
  import os
2
2
  import textwrap
3
3
  from argparse import ArgumentParser, Namespace
4
- from datetime import datetime
5
4
  from inspect import signature
6
- from typing import TYPE_CHECKING, Any
7
5
 
8
6
  from sqlalchemy import inspect as sa_inspect
9
7
  lazy import pandas as pd
@@ -12,10 +10,6 @@ from edupsyadmin.core.config import config
12
10
  from edupsyadmin.core.logger import logger
13
11
  from edupsyadmin.db import clients
14
12
  from edupsyadmin.utils.path_utils import normalize_path
15
-
16
- if TYPE_CHECKING:
17
- from edupsyadmin.api.managers import ClientsManager
18
-
19
13
  lazy from edupsyadmin.api.managers import ClientsManager
20
14
  lazy from edupsyadmin.tui.edit_client_app import EditClientApp
21
15
 
@@ -36,29 +30,10 @@ COMMAND_EPILOG = textwrap.dedent(
36
30
  --names "Client1Name" "Client2Name" --school MySchool --keep-file
37
31
  """,
38
32
  )
33
+ _CITY_COLUMNS = frozenset({"postCode", "city"})
39
34
 
40
35
 
41
- def _enter_client_csv(
42
- clients_manager: ClientsManager,
43
- csv_path: str | os.PathLike[str],
44
- school: str | None,
45
- name: list[str],
46
- import_config_name: str | None = None,
47
- ) -> int:
48
- """
49
- Read client(s) from a csv file and add them to the database.
50
-
51
- :param clients_manager: a ClientsManager instance used to add the client to the db
52
- :param csv_path: path to a csv file
53
- :param school: short name of the school as set in the config file
54
- :param name: name(s) of the client(s) as specified in the "name" column of the csv
55
- :param import_config_name: name of the csv import configuration from the config
56
- :raises ValueError: if the import config is unknown, the lookup column is
57
- missing, a name is not found, or no school/name is available
58
- :return: client_id of the last client that was created
59
- """
60
- client_cls = clients.Client
61
-
36
+ def _get_import_config(import_config_name: str | None) -> tuple[str, dict[str, str]]:
62
37
  if import_config_name:
63
38
  try:
64
39
  import_conf = config.csv_import[import_config_name]
@@ -86,6 +61,22 @@ def _enter_client_csv(
86
61
  "address.phone": "telephone2_encr",
87
62
  "address.email": "email_encr",
88
63
  }
64
+ return separator, column_mapping
65
+
66
+
67
+ def _allowed_client_keys() -> set[str]:
68
+ client_cls = clients.Client
69
+ valid_keys = {c.key for c in sa_inspect(client_cls).column_attrs}
70
+ valid_init_keys = set(signature(client_cls.__init__).parameters)
71
+ return valid_keys | valid_init_keys
72
+
73
+
74
+ def _read_clients_csv(
75
+ csv_path: str | os.PathLike[str],
76
+ import_config_name: str | None,
77
+ ) -> tuple[str, pd.DataFrame]:
78
+ """Read a client csv and apply the column mapping."""
79
+ separator, column_mapping = _get_import_config(import_config_name)
89
80
 
90
81
  # keep_default_na: Empty cells become "" (the defaults used by
91
82
  # Client.__init__), and values like "NA" or "Null" stay strings.
@@ -107,15 +98,6 @@ def _enter_client_csv(
107
98
 
108
99
  df = raw_df.rename(columns=column_mapping)
109
100
 
110
- # Telephone numbers must be strings so that they can be encrypted.
111
- for phone_col in ("telephone1_encr", "telephone2_encr"):
112
- if phone_col in df.columns:
113
- df[phone_col] = df[phone_col].fillna("").astype(str)
114
- else:
115
- logger.warning(
116
- "No column was mapped to '%s'; it will be left empty.", phone_col
117
- )
118
-
119
101
  # The 'name' column is used for lookup; it may itself have been renamed.
120
102
  lookup_col = "name" if "name" in df.columns else column_mapping.get("name", "name")
121
103
  if lookup_col not in df.columns:
@@ -124,24 +106,14 @@ def _enter_client_csv(
124
106
  f"the column mapping. Available columns: {list(df.columns)}",
125
107
  )
126
108
 
127
- # Use the first school from the config if none was passed.
128
- if school is None:
129
- try:
130
- school = next(iter(config.school))
131
- except StopIteration:
132
- raise ValueError(
133
- "No school passed and none defined in the config."
134
- ) from None
109
+ allowed_keys = _allowed_client_keys()
135
110
 
136
- # Only keep keys that the Client model accepts.
137
- valid_keys = {c.key for c in sa_inspect(client_cls).column_attrs}
138
- valid_init_keys = set(signature(client_cls.__init__).parameters)
139
- allowed_keys = valid_keys | valid_init_keys
140
- # postCode/city are merged into city_encr below, so they are valid targets.
111
+ # postCode/city (_CITY_COLUMNS) are merged into city_encr later, so
112
+ # they are valid targets.
141
113
  unknown_targets = sorted(
142
114
  target
143
115
  for target in set(column_mapping.values())
144
- if target not in allowed_keys and target not in {"postCode", "city"}
116
+ if target not in allowed_keys and target not in _CITY_COLUMNS
145
117
  )
146
118
  if unknown_targets:
147
119
  logger.debug(
@@ -149,53 +121,118 @@ def _enter_client_csv(
149
121
  unknown_targets,
150
122
  )
151
123
 
152
- client_id: int | None = None
153
- for this_name in name:
154
- client_series = df[df[lookup_col] == this_name]
124
+ keep = allowed_keys | _CITY_COLUMNS | {lookup_col}
125
+ return lookup_col, df[[col for col in df.columns if col in keep]]
155
126
 
156
- if client_series.empty:
157
- raise ValueError(
158
- f"The name '{this_name}' was not found in column '{lookup_col}' "
159
- f"of the CSV file '{csv_path}'.",
160
- )
161
127
 
162
- client_data = client_series.iloc[0].to_dict()
128
+ def _resolve_school(school: str | None) -> str:
129
+ """Return the specified school or the first one defined in the config."""
130
+ if school is not None:
131
+ return school
132
+ try:
133
+ return next(iter(config.school))
134
+ except StopIteration:
135
+ raise ValueError("No school passed and none defined in the config.") from None
163
136
 
164
- # Combine address fields if they exist
165
- if "postCode" in client_data and "city" in client_data:
166
- client_data["city_encr"] = (
167
- str(client_data.pop("postCode", ""))
168
- + " "
169
- + str(client_data.pop("city", ""))
170
- )
171
137
 
172
- # Handle date formatting
173
- for date_col in ("entry_date_encr", "birthday_encr"):
174
- if date_col in client_data and isinstance(client_data[date_col], str):
175
- try:
176
- client_data[date_col] = datetime.strptime(
177
- client_data[date_col],
178
- "%d.%m.%Y",
179
- ).date()
180
- except ValueError:
181
- logger.error(
182
- "Could not parse date '%s' for column '%s'. "
183
- "Please ensure the format is DD.MM.YYYY.",
184
- client_data[date_col],
185
- date_col,
186
- )
187
- client_data[date_col] = None
188
-
189
- client_data["school"] = school
190
-
191
- final_client_data: dict[str, Any] = {
192
- str(k): v for k, v in client_data.items() if k in allowed_keys
193
- }
194
- client_id = clients_manager.add_client(**final_client_data)
138
+ def _enter_client_csv(
139
+ clients_manager: ClientsManager,
140
+ csv_path: str | os.PathLike[str],
141
+ school: str | None,
142
+ name: list[str],
143
+ import_config_name: str | None = None,
144
+ ) -> list[int]:
145
+ """
146
+ Read client(s) from a csv file and add them to the database.
195
147
 
196
- if client_id is None:
148
+ :param clients_manager: a ClientsManager instance used to add the client to the db
149
+ :param csv_path: path to a csv file
150
+ :param school: short name of the school as set in the config file
151
+ :param name: name(s) of the client(s) as specified in the "name" column of the csv
152
+ :param import_config_name: name of the csv import configuration from the config
153
+ :raises ValueError: if the import config is unknown, the lookup column is
154
+ missing, a name is not found, or no school/name is available
155
+ :return: list of client_ids that were created
156
+ """
157
+ if not name:
197
158
  raise ValueError("No client names were given; nothing was added.")
198
- return client_id
159
+
160
+ lookup_col, df = _read_clients_csv(csv_path, import_config_name)
161
+
162
+ # Telephone numbers must be strings so that they can be encrypted.
163
+ for phone_col in ("telephone1_encr", "telephone2_encr"):
164
+ if phone_col in df.columns:
165
+ df[phone_col] = df[phone_col].fillna("").astype(str)
166
+ else:
167
+ logger.warning(
168
+ "No column was mapped to '%s'; it will be left empty.", phone_col
169
+ )
170
+
171
+ school_name = _resolve_school(school)
172
+
173
+ # Resolve every name first so a typo in the last name does not leave
174
+ # the earlier clients half-imported.
175
+ available = set(df[lookup_col])
176
+ missing = [this_name for this_name in name if this_name not in available]
177
+ if missing:
178
+ raise ValueError(
179
+ f"The name(s) {missing} were not found in column '{lookup_col}' "
180
+ f"of the CSV file '{csv_path}'.",
181
+ )
182
+
183
+ # drop_duplicates keeps the first match per name;
184
+ # .loc[name] returns the rows in the order the names were given.
185
+ selected = (
186
+ df.drop_duplicates(subset=lookup_col)
187
+ .set_index(lookup_col, drop=False)
188
+ .loc[name]
189
+ )
190
+ records = _preprocess_client_csv_data(selected, school_name).to_dict(
191
+ orient="records"
192
+ )
193
+ return [
194
+ clients_manager.add_client(**{str(k): v for k, v in record.items()})
195
+ for record in records
196
+ ]
197
+
198
+
199
+ def _preprocess_client_csv_data(df: pd.DataFrame, school: str) -> pd.DataFrame:
200
+ """Prepare the selected csv rows for ``ClientsManager.add_client``.
201
+
202
+ Merges ``postCode`` and ``city`` into ``city_encr``, parses dates
203
+ (``DD.MM.YYYY``, unparsable values become None), sets the school and drops
204
+ all columns that are not ``Client`` fields.
205
+
206
+ :param df: the selected rows of the csv dataframe
207
+ :param school: short name of the school
208
+ :return: dataframe whose columns are valid ``add_client`` keyword arguments
209
+ """
210
+ df = df.copy()
211
+
212
+ # Combine address fields if they exist
213
+ if {"postCode", "city"} <= set(df.columns):
214
+ df["city_encr"] = df.pop("postCode") + " " + df.pop("city")
215
+
216
+ # Handle date formatting
217
+ for date_col in ("entry_date_encr", "birthday_encr"):
218
+ if date_col not in df.columns:
219
+ continue
220
+ parsed = pd.to_datetime(df[date_col], format="%d.%m.%Y", errors="coerce")
221
+ failed = parsed.isna()
222
+ for bad_value in df.loc[failed, date_col]:
223
+ if bad_value:
224
+ logger.error(
225
+ "Could not parse date '%s' for column '%s'. "
226
+ "Please ensure the format is DD.MM.YYYY.",
227
+ bad_value,
228
+ date_col,
229
+ )
230
+ df[date_col] = parsed.dt.date.where(~failed, None)
231
+
232
+ df["school"] = school
233
+
234
+ allowed_keys = _allowed_client_keys()
235
+ return df[[col for col in df.columns if col in allowed_keys]]
199
236
 
200
237
 
201
238
  def add_arguments(parser: ArgumentParser) -> None:
@@ -9,8 +9,8 @@ values.
9
9
  from pathlib import Path
10
10
  from typing import Any
11
11
 
12
- import yaml
13
12
  from pydantic import BaseModel, Field
13
+ from yaml12 import read_yaml
14
14
 
15
15
  from edupsyadmin.core.logger import logger
16
16
 
@@ -93,14 +93,16 @@ class Settings:
93
93
 
94
94
  The file is read and validated against the Pydantic models.
95
95
  """
96
- with path.open("r", encoding="UTF-8") as stream:
97
- logger.debug(f"reading config data from '{path}'")
98
- data = yaml.safe_load(stream)
96
+ logger.debug(f"reading config data from '{path}'")
97
+ data = read_yaml(path)
99
98
 
100
99
  if not data:
101
100
  raise ValueError("Configuration could not be loaded or is empty.")
102
101
 
103
- self._instance = AppConfig(**data)
102
+ if not isinstance(data, dict):
103
+ raise TypeError("Configuration is not a mapping.")
104
+
105
+ self._instance = AppConfig.model_validate(data)
104
106
 
105
107
  def __getattr__(self, name: str) -> Any:
106
108
  """Delegate attribute access to the loaded AppConfig instance."""
@@ -2,7 +2,6 @@ from collections.abc import Iterable
2
2
  from pathlib import Path
3
3
  from typing import Any, ClassVar, Final
4
4
 
5
- import yaml
6
5
  from pydantic import ValidationError
7
6
  from pydantic_core import ErrorDetails
8
7
  from rich.markup import escape
@@ -15,6 +14,7 @@ from textual.message import Message
15
14
  from textual.widget import Widget
16
15
  from textual.widgets import Button, Footer, Header, Input, RichLog, Select, Static
17
16
  from textual.worker import get_current_worker
17
+ from yaml12 import write_yaml
18
18
 
19
19
  from edupsyadmin.core.config import (
20
20
  AppConfig,
@@ -84,16 +84,6 @@ FIELD_LABELS: Final[dict[str, str]] = {
84
84
  }
85
85
 
86
86
 
87
- def save_config(config_dict: dict[str, Any], file_path: Path) -> None:
88
- """Save the configuration dictionary back to the YAML file.
89
-
90
- :param config_dict: The configuration to write.
91
- :param file_path: Target YAML file.
92
- """
93
- with file_path.open("w", encoding="utf-8") as f:
94
- yaml.safe_dump(config_dict, f, default_flow_style=False, allow_unicode=True)
95
-
96
-
97
87
  def normalize_config_value(value: Any) -> Any:
98
88
  """Strip strings recursively and drop empty list items and empty dict keys.
99
89
 
@@ -1024,9 +1014,9 @@ class ConfigEditorApp(App[None]):
1024
1014
  @work(thread=True)
1025
1015
  def _save_config_worker(self, config_dict: dict[str, Any], file_path: Path) -> None:
1026
1016
  try:
1027
- save_config(config_dict, file_path)
1017
+ write_yaml(config_dict, file_path)
1028
1018
  self.post_message(ConfigSaved())
1029
- except Exception as e: # noqa: BLE001
1019
+ except (OSError, TypeError, ValueError) as e:
1030
1020
  self.log(f"Error saving config: {e}")
1031
1021
  self.call_from_thread(
1032
1022
  self._fail,
@@ -50,7 +50,7 @@ class FillFormApp(App[None]):
50
50
  try:
51
51
  clients_data[client_id] = self.clients_manager.get_client_view(
52
52
  client_id,
53
- ).model_dump()
53
+ )
54
54
  except ClientNotFoundError:
55
55
  failed_ids.append(client_id)
56
56
 
@@ -306,6 +306,6 @@ class FillFormScreen(Screen):
306
306
  for client_id in self.client_ids:
307
307
  clients_data[client_id] = self.clients_manager.get_client_view(
308
308
  client_id,
309
- ).model_dump()
309
+ )
310
310
 
311
311
  self.query_one(FillForm).display_client_info(clients_data)
File without changes