Beispiel #1
0
    def downvoteNode(self, node_id, user_id, comment):
        """ Voting down on a node

        :param node_id: ID of node
        :param user_id: ID of user (not required)
        :param comment: Comment on the vote
        :return: node object after voting
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', node_id)
        nodeVotes = node['nodeVotes']
        nodeStatus = int(node['nodeStatus']) - 1
        vote = {
            'userId': str(user_id),
            'type': '-1',
            'voteDate': str(datetime.datetime.now()),
            'comment': comment
        }
        assert isinstance(nodeVotes, list)
        nodeVotes.append(vote)
        patch = Patch()
        patch.replace('nodeStatus',
                      str(nodeStatus)).replace('nodeVotes', nodeVotes)
        conn.patch('test_nodes', node_id, patch)
        new_node = conn.get('test_nodes', node_id)
        return new_node
Beispiel #2
0
 def downvoteNode(self, node_id, user_id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", node_id)
     nodeVotes = node["nodeVotes"]
     nodeStatus = int(node["nodeStatus"]) - 1
     vote = {"_id": str(user_id), "type": "-1"}
     assert isinstance(nodeVotes, list)
     nodeVotes.append(vote)
     patch = Patch()
     patch.replace("nodeStatus", str(nodeStatus)).replace("nodeVotes", nodeVotes)
     conn.patch("test_nodes", node_id, patch)
     new_node = conn.get("test_nodes", "node_id")
     return new_node
Beispiel #3
0
 def retrieveChild(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     _list = node["nodeChildren"]
     if not _list:
         _list = "This node has no child"
     return _list
Beispiel #4
0
 def retrieveById(user_key):
     client = ConnectDB().connect()
     response = client.get('users', user_key)
     status = response.status_code
     if status == 200:
         return response.json
     else:
         return None
Beispiel #5
0
 def retrieveById(user_key):
     client = ConnectDB().connect()
     response = client.get('users', user_key)
     status = response.status_code
     if status == 200:
         return response.json
     else:
         return None
Beispiel #6
0
 def retrieveDescendent(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     _list = node["nodeChildren"]
     if not _list:
         _list = "This node has no child."
     for child in _list:
         findChild(child, _list, conn)
     return _list
Beispiel #7
0
    def retrieveById(self, _id):
        """ Retrieve a node by its ID

        :param _id: node ID
        :return: node object
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        print node.status_code
        return node
Beispiel #8
0
    def retrieveChild(self, _id):
        """ Retrieve all direct children nodes of this node

        :param _id: node ID
        :return: all the children nodes of this node
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        _list = node['nodeChildren']
        if not _list:
            _list = 'This node has no child'
        return _list
Beispiel #9
0
    def retrieve_by_id(_id):
        """
        Retrieve an event by its id
        :param _id: event id
        :return: event object
        """
        print 'retrieve by event id'

        db_conn = ConnectDB().connect()
        event = db_conn.get('node_events', _id)
        print event.status_code

        return event
Beispiel #10
0
    def retrieveDescendant(self, _id):
        """ Retrieve all the descendant nodes of this node

        :param _id: node ID
        :return: descendant nodes of the node
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        _list = node['nodeChildren']
        if not _list:
            _list = 'This node has no descendant node.'
        for child in _list:
            findChild(child, _list, conn)
        return _list
Beispiel #11
0
 def retrieveById(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     return node