MCPcopy Create free account
hub / github.com/carlio/django-flows / position_instance_for

Method position_instance_for

flows/handler.py:422–462  ·  view source on GitHub ↗
(self, component_class_or_name)

Source from the content-addressed store, hash-verified

420 return '%(root)s%(url)s' % { 'root': config.FLOWS_SITE_ROOT, 'url': url }
421
422 def position_instance_for(self, component_class_or_name):
423 # figure out where we're being sent to
424 FC = get_by_class_or_name(component_class_or_name)
425
426 # it should be a sibling of one of the current items
427 # for example, if we are in position [A,B,E]:
428 #
429 # A
430 # / | \
431 # B C D
432 # / \ | \
433 # E F G H
434 #
435 # E can send to F (its own sibling) or C (sibling of its parent)
436
437 for fci in self._flow_components[-2::-1]: # go backwards but skip the last element (the action)
438 if FC in fci.action_set:
439 # we found the relevant action set, which means we know the root
440 # part of the tree, and now we can construct the rest
441 idx = self._flow_components.index(fci)
442 break
443 else:
444 raise ValueError('Could not figure out how to redirect to %s' % FC)
445
446 # so the new tree is from the root to the parent of the one we just found,
447 # coupled with the initial subtree from the component we're tring to redirect
448 # to
449 tree_root = self._position.flow_component_classes[:idx+1]
450
451 # figure out the action tree for the new first component - either
452 # we have been given an action, in which case it's just one single
453 # item, or we have been given a scaffold, in which case there could
454 # be a list of [scaffold, scaffold..., action]
455 new_subtree = FC.get_initial_action_tree()
456
457 # we use our current tree and replace the current leaf with this new
458 # subtree to get the new position
459 new_position = PossibleFlowPosition(self._app_namespace, self._flow_namespace, tree_root + new_subtree)
460
461 # now create an instance of the position with the current state
462 return new_position.create_instance(self._state, self.state_store, self._url_args, self._url_kwargs)
463
464 def handle(self, request, *args, **kwargs):
465 # first validate that we can actually run by checking for

Callers 2

handleMethod · 0.95
link_toMethod · 0.80

Calls 5

create_instanceMethod · 0.95
get_by_class_or_nameFunction · 0.90
indexMethod · 0.80

Tested by

no test coverage detected