コード例 #1
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
コード例 #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
コード例 #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)
コード例 #4
0
ファイル: User.py プロジェクト: arapat/huanmi
 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
コード例 #5
0
ファイル: Campaign.py プロジェクト: arapat/huanmi
 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
コード例 #6
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
コード例 #7
0
ファイル: user.py プロジェクト: lrcry/ExpertMind
 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
コード例 #8
0
ファイル: tag.py プロジェクト: solki/ExpertMind-v1
 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
コード例 #9
0
ファイル: user.py プロジェクト: solki/ExpertMind-v1
 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
コード例 #10
0
ファイル: vote.py プロジェクト: solki/ExpertMind-v1
 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
コード例 #11
0
ファイル: nodes.py プロジェクト: lrcry/ExpertMind
    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
コード例 #12
0
ファイル: events.py プロジェクト: lrcry/ExpertMind
    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
コード例 #13
0
ファイル: vote.py プロジェクト: lrcry/ExpertMind
 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