-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hardens editable_future_graph against nodegroup changes #11570
- Loading branch information
Showing
2 changed files
with
107 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from arches.app.models import models | ||
|
||
|
||
def update_editable_future_nodegroups(editable_future_nodegroups): | ||
""" | ||
Update the nodegroups in the source_graph to match those in the | ||
editable_future_graph. | ||
""" | ||
|
||
def _update_source_nodegroup_hierarchy(nodegroup): | ||
if not nodegroup: | ||
return None | ||
|
||
node = models.Node.objects.get(pk=nodegroup.pk) | ||
if node.source_identifier_id: | ||
source_nodegroup = models.NodeGroup.objects.get( | ||
pk=node.source_identifier_id | ||
) | ||
|
||
source_nodegroup.cardinality = nodegroup.cardinality | ||
source_nodegroup.legacygroupid = nodegroup.legacygroupid | ||
|
||
if nodegroup.parentnodegroup_id: | ||
nodegroup_parent_node = models.Node.objects.get( | ||
pk=nodegroup.parentnodegroup_id | ||
) | ||
|
||
if nodegroup_parent_node.source_identifier_id: | ||
source_nodegroup.parentnodegroup_id = ( | ||
nodegroup_parent_node.source_identifier_id | ||
) | ||
|
||
source_nodegroup.save() | ||
|
||
if nodegroup.parentnodegroup: | ||
_update_source_nodegroup_hierarchy(nodegroup=nodegroup.parentnodegroup) | ||
|
||
# creates `NodeGroup`s for source_nodegroups_nodes whose editable_future_node has been used to create a new card | ||
for editable_future_node in models.Node.objects.filter( | ||
nodegroup__in=editable_future_nodegroups | ||
): | ||
if ( | ||
editable_future_node.source_identifier | ||
and editable_future_node.pk == editable_future_node.nodegroup_id | ||
and editable_future_node.source_identifier.pk | ||
!= editable_future_node.source_identifier.nodegroup_id | ||
): | ||
models.NodeGroup.objects.create( | ||
nodegroupid=editable_future_node.source_identifier.pk, | ||
cardinality=editable_future_node.nodegroup.cardinality, | ||
) | ||
|
||
for editable_future_nodegroup in editable_future_nodegroups: | ||
_update_source_nodegroup_hierarchy(editable_future_nodegroup) |