.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user