From 6326590cb48b4406cc199e091aa7af6459fb24ed Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Thu, 28 Mar 2019 15:27:43 -0700 Subject: [PATCH 1/3] Fixes issue with only one constraint getting returned. re 4375 --- arches/app/models/card.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arches/app/models/card.py b/arches/app/models/card.py index 3cfb43793e5..90572ccb330 100644 --- a/arches/app/models/card.py +++ b/arches/app/models/card.py @@ -36,12 +36,12 @@ def update_constraints(self, constraints): def add_nodeconstraints(nodeids, constraint_model): for nodeid in nodeids: - print('adding nodes', nodeid) node_constraint = models.ConstraintXNode() node_constraint.node = models.Node.objects.get(pk=nodeid) node_constraint.constraint = constraint_model node_constraint.save() + constraint_models = [] for constraint in constraints: constraintid = constraint.get('constraintid', None) unique_to_all = constraint.get('uniquetoallinstances', False) @@ -69,7 +69,8 @@ def add_nodeconstraints(nodeids, constraint_model): constraint_model.save() except ObjectDoesNotExist as e: print e - self.constraints = constraint_model + constraint_models.append(constraint_model) + self.constraints = constraint_models def __init__(self, *args, **kwargs): """ From a153f9bfd251f348f4a520cd93ac1cdfc8fbad0b Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Thu, 28 Mar 2019 15:28:37 -0700 Subject: [PATCH 2/3] Imports card constraints when importing a graph, re #4375 --- arches/app/models/graph.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arches/app/models/graph.py b/arches/app/models/graph.py index 49cc2c768a9..5c3fd3010a7 100644 --- a/arches/app/models/graph.py +++ b/arches/app/models/graph.py @@ -63,6 +63,8 @@ def __init__(self, *args, **kwargs): self.widgets = {} self._nodegroups_to_delete = [] self._functions = [] + self._card_constraints = [] + self._constraints_x_nodes = [] if args: if isinstance(args[0], dict): @@ -236,6 +238,20 @@ def add_edge(self, edge): self.edges[edge.pk] = edge return edge + def add_card_contraint(self, constraint, card): + unique_to_all = constraint.get('uniquetoallinstances', False) + constraint_model = models.ConstraintModel() + constraint_model.constraintid = constraint.get('constraintid', None) + constraint_model.uniquetoallinstances = constraint.get('uniquetoallinstances', False) + constraint_model.card = card + self._card_constraints.append(constraint_model) + for nodeid in constraint.get('nodes', []): + constraint_x_node = { + 'constraint': constraint_model, + 'node': nodeid + } + self._constraints_x_nodes.append(constraint_x_node) + def add_card(self, card): """ Adds a card to this graph @@ -260,6 +276,9 @@ def add_card(self, card): card.component_id = cardobj.get('component_id', uuid.UUID('f05e4d3a-53c1-11e8-b0ea-784f435179ea')) card.nodegroup_id = uuid.UUID(str(cardobj.get('nodegroup_id', ''))) card.nodegroup = self.get_or_create_nodegroup(nodegroupid=card.nodegroup_id) + constraints = cardobj.get('constraints', '') + for constraint in constraints: + self.add_card_contraint(constraint, card) card.graph = self @@ -340,6 +359,15 @@ def save(self, validate=True): for card in self.cards.itervalues(): card.save() + for constraint in self._card_constraints: + constraint.save() + + for constraint_x_node in self._constraints_x_nodes: + node_constraint = models.ConstraintXNode() + node_constraint.node = models.Node.objects.get(pk=constraint_x_node['node']) + node_constraint.constraint = constraint_x_node['constraint'] + node_constraint.save() + for widget in self.widgets.itervalues(): widget.save() @@ -1162,6 +1190,8 @@ def get_cards(self): card.description = self.nodes[card.nodegroup_id].description card_dict = JSONSerializer().serializeToPython(card) card_dict['is_editable'] = is_editable + card_constraints = card.constraintmodel_set.all() + card_dict['constraints'] = JSONSerializer().serializeToPython(card_constraints) cards.append(card_dict) return cards From 2bff017113a31c204e38cb552dfb9ae440020bad Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Thu, 28 Mar 2019 15:28:58 -0700 Subject: [PATCH 3/3] Temporary fix for duplicated url namespace. --- arches/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arches/urls.py b/arches/urls.py index 557a42ac7a8..54cdf430a3c 100644 --- a/arches/urls.py +++ b/arches/urls.py @@ -148,7 +148,7 @@ url(r'^rdm/concepts/(?P%s|())$' % uuid_regex, api.Concepts.as_view(), name='concepts'), url(r'^plugins/(?P%s)$' % uuid_regex, PluginView.as_view(), name='plugins'), url(r'^plugins/(?P[-\w]+)$', PluginView.as_view(), name='plugins'), - url(r'^cards/(?P%s|())$' % uuid_regex, api.Card.as_view(), name='card'), + url(r'^cards/(?P%s|())$' % uuid_regex, api.Card.as_view(), name='api_card'), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),