88import logging
99
1010from django .contrib .admin .views .decorators import staff_member_required
11- from django .contrib .auth .decorators import login_required
1211from django .contrib .auth .models import Group
1312from django .db import transaction
1413from django .http import JsonResponse
1514from django .shortcuts import get_object_or_404 , render
1615from django .views .decorators .http import require_GET , require_POST
1716
18- from .models import FormDefinition , WorkflowDefinition , PostSubmissionAction
17+ from .models import FormDefinition , PostSubmissionAction , WorkflowDefinition
1918
2019logger = logging .getLogger (__name__ )
2120
@@ -169,12 +168,11 @@ def convert_workflow_to_visual(workflow, form_definition):
169168 node_id_counter = 1
170169
171170 # Layout configuration for better spacing
172- HORIZONTAL_SPACING = 280 # Increased from 200 for better readability
173- VERTICAL_SPACING = 150
174- START_X = 120
175- START_Y = 200
176- current_x = START_X
177- current_y = START_Y
171+ horizontal_spacing = 280 # Increased from 200 for better readability
172+ start_x = 120
173+ start_y = 200
174+ current_x = start_x
175+ current_y = start_y
178176
179177 # Start node (always present)
180178 start_node = {
@@ -187,7 +185,7 @@ def convert_workflow_to_visual(workflow, form_definition):
187185 nodes .append (start_node )
188186 last_node_id = start_node ["id" ]
189187 node_id_counter += 1
190- current_x += HORIZONTAL_SPACING
188+ current_x += horizontal_spacing
191189
192190 # Form submission node (always present - represents the actual form)
193191 form_fields = list (form_definition .fields .all ().order_by ("order" ))
@@ -235,7 +233,7 @@ def convert_workflow_to_visual(workflow, form_definition):
235233 )
236234 last_node_id = form_node ["id" ]
237235 node_id_counter += 1
238- current_x += HORIZONTAL_SPACING
236+ current_x += horizontal_spacing
239237
240238 # Approval configuration node (always present - shows approval requirements)
241239 approval_groups = list (workflow .approval_groups .all ())
@@ -270,7 +268,7 @@ def convert_workflow_to_visual(workflow, form_definition):
270268 )
271269 last_node_id = approval_config_node ["id" ]
272270 node_id_counter += 1
273- current_x += HORIZONTAL_SPACING
271+ current_x += horizontal_spacing
274272
275273 # Manager approval node (if enabled)
276274 if workflow .requires_manager_approval :
@@ -293,13 +291,13 @@ def convert_workflow_to_visual(workflow, form_definition):
293291 )
294292 last_node_id = manager_node ["id" ]
295293 node_id_counter += 1
296- current_x += HORIZONTAL_SPACING
294+ current_x += horizontal_spacing
297295
298296 # Group approval nodes (already fetched above)
299297 if approval_groups :
300298 if workflow .approval_logic == "sequence" :
301299 # Sequential nodes - horizontal flow
302- for i , group in enumerate ( approval_groups ) :
300+ for group in approval_groups :
303301 group_node = {
304302 "id" : f"node_{ node_id_counter } " ,
305303 "type" : "approval" ,
@@ -321,7 +319,7 @@ def convert_workflow_to_visual(workflow, form_definition):
321319 )
322320 last_node_id = group_node ["id" ]
323321 node_id_counter += 1
324- current_x += HORIZONTAL_SPACING
322+ current_x += horizontal_spacing
325323 else :
326324 # Parallel nodes (all/any)
327325 parallel_node = {
@@ -345,13 +343,13 @@ def convert_workflow_to_visual(workflow, form_definition):
345343 )
346344 last_node_id = parallel_node ["id" ]
347345 node_id_counter += 1
348- current_x += HORIZONTAL_SPACING
346+ current_x += horizontal_spacing
349347
350348 # Post-submission actions
351349 actions = form_definition .post_actions .filter (is_active = True ).order_by ("order" )
352350
353351 # Actions continue on the same horizontal line for a cleaner flow
354- for i , action in enumerate ( actions ) :
352+ for action in actions :
355353 # Determine node type based on action type
356354 node_type = "email" if action .action_type == "email" else "action"
357355
@@ -418,7 +416,7 @@ def convert_workflow_to_visual(workflow, form_definition):
418416 )
419417 last_node_id = action_node ["id" ]
420418 node_id_counter += 1
421- current_x += HORIZONTAL_SPACING
419+ current_x += horizontal_spacing
422420
423421 # End node
424422 end_node = {
@@ -448,10 +446,8 @@ def convert_visual_to_workflow(workflow_data, form_definition):
448446 """
449447 Convert visual workflow format to WorkflowDefinition model.
450448 """
451- from .models import PostSubmissionAction
452449
453450 nodes = workflow_data .get ("nodes" , [])
454- connections = workflow_data .get ("connections" , [])
455451
456452 # Extract workflow configuration from nodes
457453 requires_approval = False
0 commit comments