Пример #1
0
 def create(self, nodeDisplay, nodeDescription, nodeTags, nodeParents, nodeChildren, nodeVotes, nodeStatus):
     current_time = datetime.datetime.now()
     conn = ConnectDB().connect()
     node = conn.post(
         "test_nodes",
         {
             "nodeDisplay": nodeDisplay,
             "nodeDescription": nodeDescription,
             "nodeTags": nodeTags,
             "nodeParents": nodeParents,
             "nodeChildren": nodeChildren,
             "nodeVotes": nodeVotes,  # This can be replaced by invoke methods in vote class
             "nodeStatus": str(nodeStatus),
             "nodeCreateAt": str(current_time),
         },
     )
     if nodeParents:
         pa_node = self.retrieveById(nodeParents)
         pa_nodeChildren = pa_node["nodeChildren"]
         pa_nodeChildren.append(node.key)
         patch = Patch()
         patch.replace("nodeChildren", pa_nodeChildren)
         conn.patch("test_nodes", nodeParents, patch)
     # update parentnode's nodeChildren
     return node
Пример #2
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('adds', {
         "node": self.node,
         "addAt": self.addAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('adds', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Пример #3
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('users', {
         "given_name": self.given_name,
         "surname": self.surname,
         "email": self.email
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('users', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Пример #4
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('tags', {
         "tagName": self.tagName,
         "tagDescription": self.tagDescription,
         "createdBy": self.createdBy,
         "createdAt": self.createdAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('tags', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Пример #5
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('users', {
         "username": self.username,
         "loginToken": self.loginToken,
         "email": self.email,
         "intro": self.intro,
         "registerAt": self.registerAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('users', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Пример #6
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('votes', {
         "type": self.type,
         "description": self.description,
         "voteUser": self.voteUser,
         "voteAt": self.voteAt,
         "voteOnNode": self.voteOnNode
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('votes', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Пример #7
0
    def create(self, nodeDisplay, nodeDescription, nodeTags, nodeParents,
               nodeChildren, nodeVotes, nodeStatus, userId):
        """ Create a new node
        The check of node data has been completed by service

        :param nodeDisplay: display name of a node
        :param nodeDescription: description of a node
        :param nodeTags: tags of a node
        :param nodeParents: parent node ID of this node
        :param nodeChildren: children nodes (if already has)
        :param nodeVotes: votes on node
        :param nodeStatus: status of node
        :param userId: author identification
        :return: a key of the node as an identification
        """

        current_time = datetime.datetime.now()
        conn = ConnectDB().connect()
        node = conn.post(
            'test_nodes',
            {
                "nodeDisplay": nodeDisplay,
                "nodeDescription": nodeDescription,
                "nodeTags": nodeTags,
                "nodeParents": nodeParents,
                "nodeChildren": nodeChildren,
                "nodeVotes":
                nodeVotes,  # This can be replaced by invoke methods in vote class
                "nodeStatus": str(nodeStatus),
                "nodeCreateAt": str(current_time),
                "userId": userId
            })

        patch = Patch()
        nodeKey = node.key
        patch.add("_id", node.key)

        conn.patch('test_nodes', node.key, patch)
        print 'nodeKey is ' + node.key

        return nodeKey
Пример #8
0
    def create(event):
        """
        Create a new event object
        :param event:
        :return:
        """
        print 'create'
        db_conn = ConnectDB().connect()
        current_time = datetime.datetime.now()  # create_at
        event['create_at'] = str(current_time)
        event['status'] = data_checker.EVENT_UNREAD
        event_create = db_conn.post('node_events', event)

        # append a key as ID to event
        patch = Patch()
        event_key = event_create.key
        patch.add("_id", event_key)
        db_conn.patch('node_events', event_key, patch)
        print 'event_key=' + event_key

        return event_key
Пример #9
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post(
         'votes', {
             "type": self.type,
             "description": self.description,
             "voteUser": self.voteUser,
             "voteAt": self.voteAt,
             "voteOnNode": self.voteOnNode
         })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('votes', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result