From b674f6bf07c2c8633143a8ffd1825067113fa7d4 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Thu, 14 Nov 2024 08:48:20 -0500 Subject: [PATCH] Rename to "grouping_node" --- arches/app/models/graph.py | 14 +++++++------- .../migrations/11613_add_node_constraints.py | 6 +++--- ...oup_root.py => 11613_node_grouping_node.py} | 16 ++++++++-------- ...13_node_nodegroup_root_matches_nodegroup.py | 4 ++-- arches/app/models/models.py | 18 +++++++++--------- tests/models/graph_tests.py | 6 +++--- tests/models/resource_test.py | 4 ++-- tests/models/tile_model_tests.py | 2 +- tests/views/graph_manager_tests.py | 2 +- 9 files changed, 36 insertions(+), 36 deletions(-) rename arches/app/models/migrations/{11613_node_nodegroup_root.py => 11613_node_grouping_node.py} (76%) diff --git a/arches/app/models/graph.py b/arches/app/models/graph.py index e8196b4b08..b308970458 100644 --- a/arches/app/models/graph.py +++ b/arches/app/models/graph.py @@ -349,7 +349,7 @@ def add_node(self, node, nodegroups=None): node.ontologyclass = nodeobj.get("ontologyclass", "") node.datatype = nodeobj.get("datatype", "") node.nodegroup_id = nodeobj.get("nodegroup_id", "") - node.nodegroup_root_id = nodeobj.get("nodegroup_root_id", node.nodegroup_id) + node.grouping_node_id = nodeobj.get("grouping_node_id", node.nodegroup_id) node.config = nodeobj.get("config", None) node.issearchable = nodeobj.get("issearchable", True) node.isrequired = nodeobj.get("isrequired", False) @@ -373,7 +373,7 @@ def add_node(self, node, nodegroups=None): node.nodegroup = self.get_or_create_nodegroup( nodegroupid=node.nodegroup_id ) - node.nodegroup_root_id = node.nodegroup_id + node.grouping_node_id = node.nodegroup_id if nodegroups is not None and str(node.nodegroup_id) in nodegroups: node.nodegroup.cardinality = nodegroups[str(node.nodegroup_id)][ "cardinality" @@ -386,7 +386,7 @@ def add_node(self, node, nodegroups=None): ]["parentnodegroup_id"] else: node.nodegroup = None - node.nodegroup_root = None + node.grouping_node = None node.graph = self @@ -616,7 +616,7 @@ def save(self, validate=True, nodeid=None): if nodeid is not None: node = self.nodes[nodeid] - node.nodegroup_root_id = node.nodegroup_id + node.grouping_node_id = node.nodegroup_id branch_publication_id = node.sourcebranchpublication_id self.update_es_node_mapping(node, datatype_factory, se) self.create_node_alias(node) @@ -645,7 +645,7 @@ def save(self, validate=True, nodeid=None): else: for node in self.nodes.values(): - node.nodegroup_root_id = node.nodegroup_id + node.grouping_node_id = node.nodegroup_id self.update_es_node_mapping(node, datatype_factory, se) node.save() @@ -2647,7 +2647,7 @@ def _update_source_nodegroup_hierarchy(nodegroup): "graph_id", "nodeid", "nodegroup_id", - "nodegroup_root_id", + "grouping_node_id", "source_identifier_id", "is_collector", ]: @@ -2661,7 +2661,7 @@ def _update_source_nodegroup_hierarchy(nodegroup): source_node.nodegroup_id = ( future_node_nodegroup_node.source_identifier_id ) - source_node.nodegroup_root_id = ( + source_node.grouping_node_id = ( future_card_nodegroup_node.source_identifier_id ) diff --git a/arches/app/models/migrations/11613_add_node_constraints.py b/arches/app/models/migrations/11613_add_node_constraints.py index 95ea029422..925f9fe69f 100644 --- a/arches/app/models/migrations/11613_add_node_constraints.py +++ b/arches/app/models/migrations/11613_add_node_constraints.py @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ("models", "11613_node_nodegroup_root"), + ("models", "11613_node_grouping_node"), ] operations = [ @@ -24,10 +24,10 @@ class Migration(migrations.Migration): constraint=models.CheckConstraint( condition=models.Q( ("istopnode", True), - ("nodegroup_root__isnull", False), + ("grouping_node__isnull", False), _connector="OR", ), - name="has_nodegroup_root_or_istopnode", + name="has_grouping_node_or_istopnode", ), ), ] diff --git a/arches/app/models/migrations/11613_node_nodegroup_root.py b/arches/app/models/migrations/11613_node_grouping_node.py similarity index 76% rename from arches/app/models/migrations/11613_node_nodegroup_root.py rename to arches/app/models/migrations/11613_node_grouping_node.py index 0c911ab1ad..5393f51286 100644 --- a/arches/app/models/migrations/11613_node_nodegroup_root.py +++ b/arches/app/models/migrations/11613_node_grouping_node.py @@ -10,33 +10,33 @@ class Migration(migrations.Migration): ("models", "10437_node_alias_not_null"), ] - def set_nodegroup_root(apps, schema_editor): + def set_grouping_node(apps, schema_editor): Node = apps.get_model("models", "Node") all_but_top_nodes = Node.objects.exclude(istopnode=True) for node in all_but_top_nodes: assert node.nodegroup_id is not None, f"Missing nodegroup for {node!r}" - node.nodegroup_root_id = node.nodegroup_id - Node.objects.bulk_update(all_but_top_nodes, ["nodegroup_root_id"]) + node.grouping_node_id = node.nodegroup_id + Node.objects.bulk_update(all_but_top_nodes, ["grouping_node_id"]) PublishedGraph = apps.get_model("models", "PublishedGraph") published_graphs = PublishedGraph.objects.all() for published_graph in published_graphs: for node_dict in published_graph.serialized_graph["nodes"]: - node_dict["nodegroup_root_id"] = node_dict["nodegroup_id"] + node_dict["grouping_node_id"] = node_dict["nodegroup_id"] PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"]) - def remove_nodegroup_root(apps, schema_editor): + def remove_grouping_node(apps, schema_editor): PublishedGraph = apps.get_model("models", "PublishedGraph") published_graphs = PublishedGraph.objects.all() for published_graph in published_graphs: for node_dict in published_graph.serialized_graph["nodes"]: - node_dict.pop("nodegroup_root_id", None) + node_dict.pop("grouping_node_id", None) PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"]) operations = [ migrations.AddField( model_name="node", - name="nodegroup_root", + name="grouping_node", field=models.ForeignKey( blank=True, null=True, @@ -46,5 +46,5 @@ def remove_nodegroup_root(apps, schema_editor): to="models.node", ), ), - migrations.RunPython(set_nodegroup_root, remove_nodegroup_root), + migrations.RunPython(set_grouping_node, remove_grouping_node), ] diff --git a/arches/app/models/migrations/11613_node_nodegroup_root_matches_nodegroup.py b/arches/app/models/migrations/11613_node_nodegroup_root_matches_nodegroup.py index 13b9beccce..209d26089b 100644 --- a/arches/app/models/migrations/11613_node_nodegroup_root_matches_nodegroup.py +++ b/arches/app/models/migrations/11613_node_nodegroup_root_matches_nodegroup.py @@ -13,8 +13,8 @@ class Migration(migrations.Migration): migrations.AddConstraint( model_name="node", constraint=models.CheckConstraint( - condition=models.Q(("nodegroup_root_id", models.F("nodegroup_id"))), - name="nodegroup_root_matches_nodegroup", + condition=models.Q(("grouping_node_id", models.F("nodegroup_id"))), + name="grouping_node_matches_nodegroup", ), ), ] diff --git a/arches/app/models/models.py b/arches/app/models/models.py index 95bd01b2be..5c7a243ec0 100644 --- a/arches/app/models/models.py +++ b/arches/app/models/models.py @@ -798,7 +798,7 @@ def __init__(self, *args, **kwargs): graph = models.ForeignKey( GraphModel, db_column="graphid", blank=True, null=True, on_delete=models.CASCADE ) - nodegroup_root = models.ForeignKey( + grouping_node = models.ForeignKey( "self", blank=True, null=True, @@ -915,15 +915,15 @@ def __init__(self, *args, **kwargs): def clean(self): if not self.alias: Graph.objects.get(pk=self.graph_id).create_node_alias(self) - if not self.nodegroup_root_id: - self.nodegroup_root_id = self.nodegroup_id + if not self.grouping_node_id: + self.grouping_node_id = self.nodegroup_id def save(self, **kwargs): - if not self.alias or not self.nodegroup_root_id: + if not self.alias or not self.grouping_node_id: self.clean() add_to_update_fields(kwargs, "alias") add_to_update_fields(kwargs, "hascustomalias") - add_to_update_fields(kwargs, "nodegroup_root_id") + add_to_update_fields(kwargs, "grouping_node_id") if self.pk == self.source_identifier_id: self.source_identifier_id = None add_to_update_fields(kwargs, "source_identifier_id") @@ -944,12 +944,12 @@ class Meta: name="has_nodegroup_or_istopnode", ), models.CheckConstraint( - condition=Q(istopnode=True) | Q(nodegroup_root__isnull=False), - name="has_nodegroup_root_or_istopnode", + condition=Q(istopnode=True) | Q(grouping_node__isnull=False), + name="has_grouping_node_or_istopnode", ), models.CheckConstraint( - condition=Q(nodegroup_root_id=models.F("nodegroup_id")), - name="nodegroup_root_matches_nodegroup", + condition=Q(grouping_node_id=models.F("nodegroup_id")), + name="grouping_node_matches_nodegroup", ), ] diff --git a/tests/models/graph_tests.py b/tests/models/graph_tests.py index 50edebead5..4aa2f8a331 100644 --- a/tests/models/graph_tests.py +++ b/tests/models/graph_tests.py @@ -119,7 +119,7 @@ def setUpTestData(cls): "istopnode": True, "name": "Node", "nodegroup_id": "20000000-0000-0000-0000-100000000001", - "nodegroup_root_id": "20000000-0000-0000-0000-100000000001", + "grouping_node_id": "20000000-0000-0000-0000-100000000001", "nodeid": "20000000-0000-0000-0000-100000000001", "ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E1_CRM_Entity", }, @@ -133,7 +133,7 @@ def setUpTestData(cls): "istopnode": False, "name": "Node Type", "nodegroup_id": "20000000-0000-0000-0000-100000000001", - "nodegroup_root_id": "20000000-0000-0000-0000-100000000001", + "grouping_node_id": "20000000-0000-0000-0000-100000000001", "nodeid": "20000000-0000-0000-0000-100000000002", "ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E55_Type", }, @@ -1281,7 +1281,7 @@ def test_update_empty_graph_from_editable_future_graph(self): if key not in [ "graph_id", "nodegroup_id", - "nodegroup_root_id", + "grouping_node_id", "nodeid", "source_identifier_id", ]: diff --git a/tests/models/resource_test.py b/tests/models/resource_test.py index 91efc12b50..0ff76e7cb8 100644 --- a/tests/models/resource_test.py +++ b/tests/models/resource_test.py @@ -492,7 +492,7 @@ def test_self_referring_resource_instance_descriptor(self): pk=nodegroup.pk, graph=graph, nodegroup=nodegroup, - nodegroup_root_id=nodegroup.pk, + grouping_node_id=nodegroup.pk, name="String Node", datatype="string", istopnode=False, @@ -500,7 +500,7 @@ def test_self_referring_resource_instance_descriptor(self): resource_instance_node = models.Node.objects.create( graph=graph, nodegroup=nodegroup, - nodegroup_root_id=nodegroup.pk, + grouping_node_id=nodegroup.pk, name="Resource Node", datatype="resource-instance", istopnode=False, diff --git a/tests/models/tile_model_tests.py b/tests/models/tile_model_tests.py index a972b9cdab..5e518cb7df 100644 --- a/tests/models/tile_model_tests.py +++ b/tests/models/tile_model_tests.py @@ -737,7 +737,7 @@ def test_check_for_missing_nodes(self): name="Required file list", datatype="file-list", nodegroup=node_group, - nodegroup_root_id=node_group.pk, + grouping_node_id=node_group.pk, isrequired=True, istopnode=False, ) diff --git a/tests/views/graph_manager_tests.py b/tests/views/graph_manager_tests.py index 7d8a659326..569b0c976f 100644 --- a/tests/views/graph_manager_tests.py +++ b/tests/views/graph_manager_tests.py @@ -138,7 +138,7 @@ def setUpTestData(cls): "istopnode": False, "name": "Node Type", "nodegroup_id": "20000000-0000-0000-0000-100000000001", - "nodegroup_root_id": "20000000-0000-0000-0000-100000000001", + "grouping_node_id": "20000000-0000-0000-0000-100000000001", "nodeid": "20000000-0000-0000-0000-100000000002", "ontologyclass": "http://www.cidoc-crm.org/cidoc-crm/E55_Type", },