Priority Helpers¶
nautobot_contract_models.priority
¶
Renewal-action priority rubric — one source of truth.
Phase 12 introduces this. Until now, the "should the operator panic"
logic lived only in :func:RenewalCheckJob.run, which mapped it to
logger.warning vs logger.info. The Phase 12 dashboard surface
needs the same rubric to drive cell colors, sort order, and badges —
duplicating the conditional in a template guarantees drift.
The rubric, in priority order:
- URGENT —
auto_renew=TrueAND inside the notice window. Operator MUST act or the contract auto-renews on terms they didn't re-negotiate. - WARNING — within 7 days of
end_date. Imminent renewal regardless of notice arrangements; action overdue. - WARNING — inside the notice window but NOT auto-renewing. Notice deadline matters; lapse means contract terminates rather than locks in, but operators usually want to act either way.
- INFO — in the configured upcoming-renewals window but outside urgency bands above. Heads-up only.
Anything outside the upcoming-renewals window doesn't appear in the priority surface at all (it's "not actionable yet").
The string values ("urgent", "warning", "info") are stable
over time — templates and tests can match them directly. Ordering is
URGENT > WARNING > INFO for sort purposes (use :data:PRIORITY_RANK).
action_priority(contract, *, on_date=None, imminent_threshold_days=7)
¶
Return "urgent" | "warning" | "info" based on contract dates.
Returns None for contracts that don't have an end_date —
callers can filter those out before sorting.
imminent_threshold_days mirrors the rubric in
:class:RenewalCheckJob (default 7). Operators with different
operational tempos can pass a different threshold; the dashboard
panel uses the default.
Source code in src/nautobot_contract_models/priority.py
contracts_needing_action(*, window_days=60, on_date=None)
¶
Return contracts within window_days of expiry, sorted by urgency.
Each result is a (contract, priority) tuple. Sort order is
URGENT first, then WARNING, then INFO; within each band, soonest
end_date first. Already-expired contracts are excluded — operators
can't act on something that already lapsed.
The dashboard panel and the action-required list view both consume this. Keeping it here means future tweaks (different sort, new priority bands) land in one place.