This commit is contained in:
Ross
2025-12-09 12:07:26 +00:00
parent eb95f5fa6d
commit c63d4d1585
5 changed files with 105 additions and 5 deletions
+20 -4
View File
@@ -32,10 +32,26 @@ class RotaSchedule(models.Model):
Returns the RotaBuilder instance.
"""
try:
from rota_generator.shifts import RotaBuilder, SingleShift
except Exception:
raise RuntimeError("Unable to import rota_generator.shifts; ensure the rota package is importable")
# Try importing the project's rota generator implementation. Some setups
# provide the implementation as `rota_generator.shifts` (script/package),
# while others provide it as `rota.shifts` (library folder). Try both
# so the Django app works in either layout.
RotaBuilder = None
SingleShift = None
import importlib
for mod_name in ("rota_generator.shifts", "rota.shifts"):
try:
mod = importlib.import_module(mod_name)
RotaBuilder = getattr(mod, "RotaBuilder")
SingleShift = getattr(mod, "SingleShift")
break
except Exception:
continue
if RotaBuilder is None or SingleShift is None:
raise RuntimeError(
"Unable to import rota generator (tried 'rota_generator.shifts' and 'rota.shifts'); "
"ensure the rota package is importable and contains RotaBuilder/SingleShift"
)
# compute weeks_to_rota (integer number of weeks)
delta = self.end_date - self.start_date