Skip to content

Commit c4e082f

Browse files
committed
style: ruff format admin, tasks, views, workflow_engine
1 parent dfb098f commit c4e082f

4 files changed

Lines changed: 37 additions & 18 deletions

File tree

django_forms_workflows/admin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ class PrefillSourceAdmin(admin.ModelAdmin):
151151
class FormCategoryAdmin(admin.ModelAdmin):
152152
"""Admin interface for FormCategory grouping primitives."""
153153

154-
list_display = ["name", "parent", "slug", "order", "is_collapsed_by_default", "icon"]
154+
list_display = [
155+
"name",
156+
"parent",
157+
"slug",
158+
"order",
159+
"is_collapsed_by_default",
160+
"icon",
161+
]
155162
list_editable = ["order", "is_collapsed_by_default"]
156163
list_filter = ["parent"]
157164
prepopulated_fields = {"slug": ("name",)}

django_forms_workflows/tasks.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def _send_html_email(
101101
# Notification Batching Helpers
102102
# ---------------------------------------------------------------------------
103103

104+
104105
def _compute_scheduled_for(workflow, submission=None):
105106
"""
106107
Return a timezone-aware datetime indicating when the next batch for the
@@ -150,9 +151,7 @@ def _at_time(base_dt):
150151
if date_str:
151152
try:
152153
parsed = datetime.fromisoformat(str(date_str)).date()
153-
candidate = timezone.make_aware(
154-
datetime.combine(parsed, raw_time)
155-
)
154+
candidate = timezone.make_aware(datetime.combine(parsed, raw_time))
156155
if candidate > now:
157156
return candidate
158157
except (ValueError, TypeError):
@@ -573,6 +572,7 @@ def send_escalation_notification(task_id: int, to_email: str | None = None) -> N
573572
# Batched Notification Dispatch
574573
# ---------------------------------------------------------------------------
575574

575+
576576
@shared_task(name="django_forms_workflows.send_batched_notifications")
577577
def send_batched_notifications() -> str:
578578
"""
@@ -600,7 +600,11 @@ def send_batched_notifications() -> str:
600600
groups[key].append(pn)
601601

602602
sent_count = 0
603-
for (recipient_email, notification_type, _workflow_id), notifications in groups.items():
603+
for (
604+
recipient_email,
605+
notification_type,
606+
_workflow_id,
607+
), notifications in groups.items():
604608
try:
605609
if notification_type == "submission_received":
606610
_dispatch_submission_digest(recipient_email, notifications)

django_forms_workflows/views.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def _get_accessible_category_pks(user):
5151
cat_by_pk = {cat.pk: cat for cat in all_cats}
5252
# Map each category to its set of required group IDs
5353
cat_groups = {
54-
cat.pk: set(cat.allowed_groups.values_list("id", flat=True))
55-
for cat in all_cats
54+
cat.pk: set(cat.allowed_groups.values_list("id", flat=True)) for cat in all_cats
5655
}
5756

5857
_cache = {} # pk -> bool
@@ -109,7 +108,7 @@ def _build_grouped_forms(forms):
109108
"name",
110109
).select_related("category")
111110

112-
forms_by_cat = {} # cat_pk -> [FormDefinition]
111+
forms_by_cat = {} # cat_pk -> [FormDefinition]
113112
uncategorised = []
114113

115114
for form in ordered:
@@ -123,10 +122,9 @@ def _build_grouped_forms(forms):
123122

124123
# ---- 2. Load all categories and build parent → children map --------
125124
all_cats = {
126-
cat.pk: cat
127-
for cat in FormCategory.objects.all().order_by("order", "name")
125+
cat.pk: cat for cat in FormCategory.objects.all().order_by("order", "name")
128126
}
129-
children_by_parent = {} # parent_pk | None -> [FormCategory]
127+
children_by_parent = {} # parent_pk | None -> [FormCategory]
130128
for cat in all_cats.values():
131129
children_by_parent.setdefault(cat.parent_id, []).append(cat)
132130

@@ -1129,9 +1127,7 @@ def submission_pdf(request, submission_id):
11291127
submission.submitter == request.user
11301128
or request.user.is_superuser
11311129
or user_can_approve(request.user, submission)
1132-
or request.user.groups.filter(
1133-
id__in=form_def.admin_groups.all()
1134-
).exists()
1130+
or request.user.groups.filter(id__in=form_def.admin_groups.all()).exists()
11351131
)
11361132
if not can_view:
11371133
return HttpResponseForbidden(

django_forms_workflows/workflow_engine.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@
5151

5252
def _notify_submission_created(submission: FormSubmission) -> None:
5353
workflow = getattr(submission.form_definition, "workflow", None)
54-
cadence = getattr(workflow, "notification_cadence", "immediate") if workflow else "immediate"
54+
cadence = (
55+
getattr(workflow, "notification_cadence", "immediate")
56+
if workflow
57+
else "immediate"
58+
)
5559

5660
if cadence != "immediate" and workflow is not None:
5761
try:
5862
from .tasks import _queue_submission_notifications
5963

6064
_queue_submission_notifications(submission, workflow)
6165
except Exception:
62-
logger.warning("Failed to queue batched submission notification; falling back to immediate")
66+
logger.warning(
67+
"Failed to queue batched submission notification; falling back to immediate"
68+
)
6369
_notify_submission_created_immediate(submission)
6470
return
6571

@@ -77,15 +83,21 @@ def _notify_submission_created_immediate(submission: FormSubmission) -> None:
7783

7884
def _notify_task_request(task: ApprovalTask) -> None:
7985
workflow = getattr(task.submission.form_definition, "workflow", None)
80-
cadence = getattr(workflow, "notification_cadence", "immediate") if workflow else "immediate"
86+
cadence = (
87+
getattr(workflow, "notification_cadence", "immediate")
88+
if workflow
89+
else "immediate"
90+
)
8191

8292
if cadence != "immediate" and workflow is not None:
8393
try:
8494
from .tasks import _queue_approval_request_notifications
8595

8696
_queue_approval_request_notifications(task, workflow)
8797
except Exception:
88-
logger.warning("Failed to queue batched approval request; falling back to immediate")
98+
logger.warning(
99+
"Failed to queue batched approval request; falling back to immediate"
100+
)
89101
_notify_task_request_immediate(task)
90102
return
91103

0 commit comments

Comments
 (0)