Skip to content

Commit b2a38f4

Browse files
committed
v0.19.0: Remove deprecated features with data migrations
- Migration 0040: Migrate show_if_field/show_if_value to conditional_rules, clear orphan flat approval_groups, clear escalation fields, mark auto_created stages as real, clear old visual_workflow_data format - Migration 0041: Drop 12 deprecated fields (approval_groups M2M, approval_logic, requires_manager_approval, manager_can_override_group, escalation_field, escalation_threshold, escalation_groups M2M, enable_db_updates, db_update_mappings, show_if_field, show_if_value, auto_created) - Remove ~160 lines of legacy flat workflow engine code - Remove approval_config node type from visual builder - Remove escalation UI from workflow settings panel - Update sync_api to gracefully discard legacy keys on import - Clean up admin, forms, views, tasks, utils, management commands
1 parent ce06f37 commit b2a38f4

16 files changed

Lines changed: 370 additions & 684 deletions

django_forms_workflows/admin.py

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class FormFieldInline(admin.StackedInline):
8484
"Conditional display",
8585
{
8686
"classes": ("collapse",),
87-
"fields": (("show_if_field", "show_if_value"),),
87+
"fields": ("conditional_rules",),
8888
},
8989
),
9090
(
@@ -275,16 +275,10 @@ class WorkflowDefinitionInline(admin.StackedInline):
275275
extra = 0
276276
fields = [
277277
"requires_approval",
278-
("approval_groups", "approval_logic"),
279-
"requires_manager_approval",
280-
("escalation_field", "escalation_threshold", "escalation_groups"),
281278
("notify_on_submission", "notify_on_approval", "notify_on_rejection"),
282279
"additional_notify_emails",
283-
"enable_db_updates",
284-
"db_update_mappings",
285280
("allow_bulk_export", "allow_bulk_pdf_export"),
286281
]
287-
filter_horizontal = ["approval_groups", "escalation_groups"]
288282

289283

290284
@admin.register(FormDefinition)
@@ -497,8 +491,7 @@ def clone_forms(self, request, queryset):
497491
max_length=field.max_length,
498492
regex_validation=field.regex_validation,
499493
regex_error_message=field.regex_error_message,
500-
show_if_field=field.show_if_field,
501-
show_if_value=field.show_if_value,
494+
conditional_rules=field.conditional_rules,
502495
allowed_extensions=field.allowed_extensions,
503496
max_file_size_mb=field.max_file_size_mb,
504497
)
@@ -937,48 +930,25 @@ class WorkflowDefinitionAdmin(admin.ModelAdmin):
937930
list_display = (
938931
"form_definition",
939932
"requires_approval",
940-
"approval_logic",
941-
"requires_manager_approval",
942933
"allow_bulk_export",
943934
"allow_bulk_pdf_export",
944935
)
945936
list_filter = (
946937
"requires_approval",
947-
"approval_logic",
948-
"requires_manager_approval",
949938
"allow_bulk_export",
950939
"allow_bulk_pdf_export",
951940
)
952941
search_fields = ("form_definition__name",)
953-
filter_horizontal = ("approval_groups", "escalation_groups")
954942
fieldsets = (
955943
(
956944
None,
957945
{
958946
"fields": (
959947
"form_definition",
960-
("requires_approval", "approval_logic"),
961-
"approval_groups",
948+
"requires_approval",
962949
)
963950
},
964951
),
965-
(
966-
"Manager approval",
967-
{
968-
"classes": ("collapse",),
969-
"fields": ("requires_manager_approval", "manager_can_override_group"),
970-
},
971-
),
972-
(
973-
"Conditional escalation",
974-
{
975-
"classes": ("collapse",),
976-
"fields": (
977-
("escalation_field", "escalation_threshold"),
978-
"escalation_groups",
979-
),
980-
},
981-
),
982952
(
983953
"Timeouts",
984954
{
@@ -1023,13 +993,6 @@ class WorkflowDefinitionAdmin(admin.ModelAdmin):
1023993
),
1024994
},
1025995
),
1026-
(
1027-
"Post-approval DB updates",
1028-
{
1029-
"classes": ("collapse",),
1030-
"fields": ("enable_db_updates", "db_update_mappings"),
1031-
},
1032-
),
1033996
(
1034997
"Bulk Export",
1035998
{

django_forms_workflows/form_builder_views.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ def form_builder_clone(request, form_id):
133133
max_length=field.max_length,
134134
regex_validation=field.regex_validation,
135135
regex_error_message=field.regex_error_message,
136-
show_if_field=field.show_if_field,
137-
show_if_value=field.show_if_value,
136+
conditional_rules=field.conditional_rules,
138137
allowed_extensions=field.allowed_extensions,
139138
max_file_size_mb=field.max_file_size_mb,
140139
)
@@ -229,8 +228,7 @@ def form_builder_load(request, form_id):
229228
"regex_error_message": field.regex_error_message or "",
230229
},
231230
"conditional": {
232-
"show_if_field": field.show_if_field,
233-
"show_if_value": field.show_if_value or "",
231+
"conditional_rules": field.conditional_rules or [],
234232
},
235233
"workflow_stage_id": field.workflow_stage_id,
236234
}
@@ -377,17 +375,15 @@ def form_builder_save(request):
377375

378376
# Add conditional properties
379377
conditional = field_data.get("conditional", {})
380-
field_props.update(
381-
{
382-
"show_if_field": conditional.get("show_if_field", ""),
383-
"show_if_value": conditional.get("show_if_value", ""),
384-
}
378+
conditional_rules = conditional.get(
379+
"conditional_rules",
380+
field_data.get("conditional_rules"),
385381
)
386382

387383
# Add client-side enhancement properties
388384
field_props.update(
389385
{
390-
"conditional_rules": field_data.get("conditional_rules"),
386+
"conditional_rules": conditional_rules,
391387
"validation_rules": field_data.get("validation_rules"),
392388
"field_dependencies": field_data.get("field_dependencies"),
393389
"step_number": field_data.get("step_number"),
@@ -530,10 +526,10 @@ def form_builder_preview(request):
530526
if validation.get("max_length") is not None:
531527
field_kwargs["max_length"] = validation.get("max_length")
532528

533-
# Only set show_if_field if it has a value (SlugField doesn't accept empty string)
534-
if conditional.get("show_if_field"):
535-
field_kwargs["show_if_field"] = conditional.get("show_if_field")
536-
field_kwargs["show_if_value"] = conditional.get("show_if_value", "")
529+
# Conditional rules
530+
cond_rules = conditional.get("conditional_rules")
531+
if cond_rules:
532+
field_kwargs["conditional_rules"] = cond_rules
537533

538534
FormField.objects.create(**field_kwargs)
539535

django_forms_workflows/forms.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -482,25 +482,8 @@ def get_enhancements_config(self):
482482

483483
# Collect conditional rules from all fields
484484
for field in self.form_definition.fields.all():
485-
# Legacy simple conditional logic
486-
if field.show_if_field and field.show_if_value:
487-
config["conditionalRules"].append(
488-
{
489-
"targetField": field.field_name,
490-
"action": "show",
491-
"operator": "AND",
492-
"conditions": [
493-
{
494-
"field": field.show_if_field,
495-
"operator": "equals",
496-
"value": field.show_if_value,
497-
}
498-
],
499-
}
500-
)
501-
502-
# Advanced conditional rules
503-
if hasattr(field, "conditional_rules") and field.conditional_rules:
485+
# Conditional rules
486+
if field.conditional_rules:
504487
if isinstance(field.conditional_rules, str):
505488
try:
506489
rules = json.loads(field.conditional_rules)

django_forms_workflows/management/commands/create_default_templates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handle(self, *args, **options):
5252
"regex_validation": "",
5353
"regex_error_message": "",
5454
},
55-
"conditional": {"show_if_field": "", "show_if_value": ""},
55+
"conditional": {},
5656
},
5757
{
5858
"order": 2,
@@ -75,7 +75,7 @@ def handle(self, *args, **options):
7575
"regex_validation": "",
7676
"regex_error_message": "",
7777
},
78-
"conditional": {"show_if_field": "", "show_if_value": ""},
78+
"conditional": {},
7979
},
8080
{
8181
"order": 3,
@@ -98,7 +98,7 @@ def handle(self, *args, **options):
9898
"regex_validation": "",
9999
"regex_error_message": "",
100100
},
101-
"conditional": {"show_if_field": "", "show_if_value": ""},
101+
"conditional": {},
102102
},
103103
{
104104
"order": 4,
@@ -121,7 +121,7 @@ def handle(self, *args, **options):
121121
"regex_validation": "",
122122
"regex_error_message": "",
123123
},
124-
"conditional": {"show_if_field": "", "show_if_value": ""},
124+
"conditional": {},
125125
},
126126
],
127127
},

django_forms_workflows/management/commands/seed_farm_demo.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from decimal import Decimal
32

43
from django.contrib.auth.models import Group, User
54
from django.core.management.base import BaseCommand
@@ -180,16 +179,20 @@ def handle(self, *args, **options):
180179
)
181180
# Ensure associations and settings
182181
wf1.requires_approval = True
183-
wf1.approval_logic = "any"
184182
wf1.approval_deadline_days = 7
185183
wf1.send_reminder_after_days = 3
186-
wf1.escalation_field = "cost_estimate"
187-
wf1.escalation_threshold = Decimal("1000.00")
188184
wf1.save()
189-
wf1.approval_groups.set(
185+
# Create a stage for approval
186+
from django_forms_workflows.models import WorkflowStage
187+
188+
stage1, _ = WorkflowStage.objects.get_or_create(
189+
workflow=wf1,
190+
order=1,
191+
defaults={"name": "Review", "approval_logic": "any"},
192+
)
193+
stage1.approval_groups.set(
190194
[groups["Barn Managers"], groups["Equipment Operators"]]
191195
)
192-
wf1.escalation_groups.set([groups["Farm Owners"]])
193196
self.stdout.write(
194197
self.style.SUCCESS("Configured workflow for Equipment Repair Request")
195198
)
@@ -243,17 +246,20 @@ def handle(self, *args, **options):
243246
form_definition=fd2,
244247
defaults={
245248
"requires_approval": True,
246-
"approval_logic": "all",
247249
"approval_deadline_days": 5,
248250
"send_reminder_after_days": 2,
249251
},
250252
)
251253
wf2.requires_approval = True
252-
wf2.approval_logic = "all"
253254
wf2.approval_deadline_days = 5
254255
wf2.send_reminder_after_days = 2
255256
wf2.save()
256-
wf2.approval_groups.set([groups["Field Crew"], groups["Barn Managers"]])
257+
stage2, _ = WorkflowStage.objects.get_or_create(
258+
workflow=wf2,
259+
order=1,
260+
defaults={"name": "Review", "approval_logic": "all"},
261+
)
262+
stage2.approval_groups.set([groups["Field Crew"], groups["Barn Managers"]])
257263
self.stdout.write(
258264
self.style.SUCCESS("Configured workflow for Barn Maintenance Request")
259265
)

0 commit comments

Comments
 (0)