Example #1
0
    def add_card(self, card):
        """
        Adds a card to this graph

        Arguments:
        node -- a dictionary representing a Card instance or an actual models.CardModel instance

        """

        if not isinstance(card, models.CardModel):
            cardobj = card.copy()
            card = models.CardModel()
            card.cardid = cardobj.get('cardid', None)
            card.name = cardobj.get('name', '')
            card.description = cardobj.get('description', '')
            card.instructions = cardobj.get('instructions', '')
            card.helptext = cardobj.get('helptext', '')
            card.nodegroup_id = uuid.UUID(str(cardobj.get('nodegroup_id', '')))
            card.nodegroup = self.get_or_create_nodegroup(
                nodegroupid=card.nodegroup_id)

        card.graph = self

        if card.pk == None:
            card.pk = uuid.uuid1()

        self.cards[card.pk] = card
        return card
Example #2
0
    def update_node(self, node):
        """
        updates a node in the graph

        Arguments:
        node -- a python dictionary representing a node object to be used to update the graph

        """

        node['nodeid'] = uuid.UUID(str(node.get('nodeid')))
        old_node = self.nodes.pop(node['nodeid'])
        new_node = self.add_node(node)

        for edge_id, edge in self.edges.iteritems():
            if edge.domainnode_id == new_node.nodeid:
                edge.domainnode = new_node
            if edge.rangenode_id == new_node.nodeid:
                edge.rangenode = new_node
                if 'parentproperty' in node:
                    edge.ontologyproperty = node.get('parentproperty', None)

        self.populate_null_nodegroups()

        # new_node will always have a nodegroup id even it if was set to None becuase populate_null_nodegroups
        # will populate the nodegroup id with the parent nodegroup
        # add/remove a card if a nodegroup was added/removed
        if new_node.nodegroup_id != old_node.nodegroup_id:
            if new_node.is_collector:
                # add a card
                self.add_card(
                    models.CardModel(name=new_node.name,
                                     nodegroup=new_node.nodegroup))
            else:
                self._nodegroups_to_delete = [old_node.nodegroup]
                # remove a card
                self.cards = {
                    card_id: card
                    for card_id, card in self.cards.iteritems()
                    if card.nodegroup_id != old_node.nodegroup_id
                }

        return self
Example #3
0
    def add_card(self, card):
        """
        Adds a card to this graph

        Arguments:
        node -- a dictionary representing a Card instance or an actual models.CardModel instance

        """

        if not isinstance(card, models.CardModel):
            cardobj = card.copy()
            card = models.CardModel()
            card.cardid = cardobj.get('cardid', None)
            card.name = cardobj.get('name', '')
            card.description = cardobj.get('description', '')
            card.instructions = cardobj.get('instructions', '')
            card.helpenabled = cardobj.get('helpenabled', '')
            card.helptitle = cardobj.get('helptext', '')
            card.helptext = cardobj.get('helptext', '')
            card.active = cardobj.get('active', '')
            card.visible = cardobj.get('visible', '')
            card.sortorder = cardobj.get('sortorder', '')
            card.itemtext = cardobj.get('itemtext', '')
            card.nodegroup_id = uuid.UUID(str(cardobj.get('nodegroup_id', '')))
            card.nodegroup = self.get_or_create_nodegroup(
                nodegroupid=card.nodegroup_id)

        card.graph = self

        if card.pk == None:
            card.pk = uuid.uuid1()

        self.cards[card.pk] = card

        widgets = list(card.cardxnodexwidget_set.all())
        for widget in widgets:
            self.widgets[widget.pk] = widget

        return card