Exemplo n.º 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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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