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
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
def ban_rem(self, msg, status, args): """ Remove a username from banlist """ # Parse author and check if it's moderator authorUsername = msg.Sender.Handle author = self.getUser(authorUsername) if not self.isMod(author): msg.Chat.SendMessage(settings.MESSAGES['no_perms'] % (msg.Sender.FullName)) return False # Parse key user = args[1] # @TODO: Maybe check if the user really exists? For now I don't think its necessary. # Save on database as a patch to "banned" value patch = Patch() patch.add("banned", False) response = client.patch('users', user, patch) # make sure the request succeeded try: response.raise_for_status() msg.Chat.SendMessage(settings.MESSAGES['unban_success'] % (user)) except: msg.Chat.SendMessage(settings.MESSAGES['unban_fail']) pass
def set_song_fingerprinted(self, sid): """ Set the fingerprinted flag to TRUE (1) once a song has been completely fingerprinted in the database. """ patch = Patch() patch.add("fingerprinted", True) client.patch(SONGS_TABLENAME, sid, patch)
def update(self, key, value, isList = False, _force = False): if key in CONSTANT: raise ConstantUpdatesForbidden() patch = Patch() if isList or type(self._user.get(key, None)) == list: value = self._user.get(key, []) + [value] patch.add(key, value) response = self._client.patch(PRODUCT, self._user['id'], patch) response.raise_for_status() self._user[key] = value
def update(self, key, value, isList = False, _force = False): if self._campaign['user'] != self._user: raise UserNotMatch() if key in CONSTANT and not _force: raise ConstantUpdatesForbidden() patch = Patch() if isList or type(self._campaign.get(key, None)) == list \ or key in LIST_ATTR: value = self._campaign.get(key, []) + [value] patch.add(key, value) response = self._client.patch(PRODUCT, self._campaign['id'], patch) response.raise_for_status() self._campaign[key] = value
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
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
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
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
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
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
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
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
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