Exemple #1
0
    def reply(self, content, **argv):
        if not self._topicID:
            return Exception('topic-not-loaded')

        if not _isSectionID(self._parentID):
            # now disable replying to a reply
            return Exception('not-allowed-replying-to-a-reply')

        topicID = _getTopicID(self._topicID, '', content)
        posttime = int(time.time())
        try:
            if argv.has_key('time'):
                posttime = int(argv['time'])
        except:
            pass

        self._sqldb.insert(
            'topics',
            {
                'tid': topicID,  # of this new reply
                'pid': self._topicID,  # to which this new reply belongs
                'title': '',
                'content': content.encode('hex'),
                'sid': self._sectionID,
                'time': posttime,
            })

        return topicID
Exemple #2
0
    def __init__(self, sqldb, sectionID=False):
        self._sqldb = sqldb

        if sectionID:
            if not _isSectionID(sectionID):
                raise Exception('not-section-id')
            self._sectionID = sectionID
Exemple #3
0
    def reply(self, content, **argv):
        if not self._topicID:
            return Exception('topic-not-loaded')

        if not _isSectionID(self._parentID):
            # now disable replying to a reply
            return Exception('not-allowed-replying-to-a-reply')

        topicID = _getTopicID(self._topicID, '', content)
        posttime = int(time.time())
        try:
            if argv.has_key('time'):
                posttime = int(argv['time'])
        except:
            pass

        self._sqldb.insert(
            'topics', 
            {
                'tid': topicID,         # of this new reply
                'pid': self._topicID,   # to which this new reply belongs
                'title': '',
                'content': content.encode('hex'),
                'sid': self._sectionID,
                'time': posttime,
            }
        )

        return topicID
Exemple #4
0
    def __init__(self, sqldb, sectionID=False):
        self._sqldb = sqldb

        if sectionID:
            if not _isSectionID(sectionID):
                raise Exception('not-section-id')
            self._sectionID = sectionID
Exemple #5
0
    def create(self, sectionName):
        if _isSectionID(sectionName):
            # a sectionName, which looks like a sectionID, is forbidden.
            return Exception('not-section-name')

        # use HEX encode, making it able to search
        sectionNameEncoded = _regulateSectionName(sectionName).encode('hex')
        sectionID = _getSectionID(sectionName)

        if False != self.existence(sectionID):
            return Exception('section-already-exists')

        self._sqldb.insert('sections', {
            'sid': sectionID,
            'name': sectionNameEncoded,
        })

        self.load(sectionID)
        return True
Exemple #6
0
    def create(self, sectionName):
        if _isSectionID(sectionName):
            # a sectionName, which looks like a sectionID, is forbidden.
            return Exception('not-section-name')

        # use HEX encode, making it able to search
        sectionNameEncoded = _regulateSectionName(sectionName).encode('hex')
        sectionID = _getSectionID(sectionName)

        if False != self.existence(sectionID):
            return Exception('section-already-exists')

        self._sqldb.insert(
            'sections',
            {
                'sid': sectionID,
                'name': sectionNameEncoded,
            }
        )

        self.load(sectionID)
        return True