예제 #1
0
파일: reply.py 프로젝트: ywmmmw/collipa
 def save(self, user, topic, reply=None):
     data = self.data
     content = str(data.get('content'))
     data.update({
         'user_id': user.id,
         'topic_id': topic.id,
         'content': strip_xss_tags(content)
     })
     if reply:
         category = 'edit'
         pre_content = reply.content
         cur_content = data.get('content')
         changed = 0
         if pre_content != cur_content:
             diff_content = ghdiff.diff(pre_content, cur_content, css=None)
             changed = 1
         if changed == 1:
             reply.content = cur_content
             History(user_id=user.id,
                     content=diff_content,
                     reply_id=reply.id).save()
         else:
             return reply
     else:
         category = 'create'
         reply = Reply(**data)
     return reply.save(category=category)
예제 #2
0
파일: topic.py 프로젝트: zky001/collipa
    def save(self, user, topic=None):
        data = self.data

        node_name = data.pop('node_name', None)
        if not node_name:
            logging.info('no node_name in form data, data: %s', data)

        if not self.node:
            self.node = Node.get(name=node_name)

        if not self.node:
            logging.info('node is None in form instance, self: %s', self)

        content = unicode(data.get('content'))
        data.update({
            'user_id': user.id,
            'node_id': self.node.id,
            'content': strip_xss_tags(content)
        })
        if topic:
            category = 'edit'
            pre_node_id = topic.node_id
            pre_title = topic.title
            pre_content = topic.content
            cur_node_id = data.get('node_id')
            cur_title = data.get('title')
            cur_content = data.get('content')
            changed = 0
            if pre_node_id != cur_node_id:
                topic.node.topic_count -= 1
                self.node.topic_count += 1
                diff_content = '主题节点从' + '<a class="node" href="' +\
                    topic.node.url + '">' + topic.node.name +\
                    '</a>移动到<a class="node" href="' + self.node.url + '">' +\
                    self.node.name + '</a>'
                changed = 1
            if pre_title != cur_title or pre_content != cur_content:
                content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content
                content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content
                diff_content = ghdiff.diff(content1, content2, css=None)
                changed = 1
            if changed == 1:
                topic.node_id = cur_node_id
                topic.title = cur_title
                topic.content = cur_content
                History(user_id=user.id,
                        content=diff_content,
                        topic_id=topic.id).save()
            else:
                return topic
        else:
            category = 'create'
            topic = Topic(**data)
        return topic.save(category=category)
예제 #3
0
    def save(self, user, topic=None):
        data = self.data

        node_name = data.pop('node_name', None)
        if not node_name:
            logging.info('no node_name in form data, data: %s', data)

        if not self.node:
            self.node = Node.get(name=node_name)

        if not self.node:
            logging.info('node is None in form instance, self: %s', self)

        content = str(data.get('content'))
        data.update({'user_id': user.id, 'node_id': self.node.id,
                     'content': strip_xss_tags(content)})
        if topic:
            category = 'edit'
            pre_node_id = topic.node_id
            pre_title = topic.title
            pre_content = topic.content
            cur_node_id = data.get('node_id')
            cur_title = data.get('title')
            cur_content = data.get('content')
            changed = 0
            if pre_node_id != cur_node_id:
                topic.node.topic_count -= 1
                self.node.topic_count += 1
                diff_content = '主题节点从' + '<a class="node" href="' +\
                    topic.node.url + '">' + topic.node.name +\
                    '</a>移动到<a class="node" href="' + self.node.url + '">' +\
                    self.node.name + '</a>'
                changed = 1
            if pre_title != cur_title or pre_content != cur_content:
                content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content
                content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content
                diff_content = ghdiff.diff(content1, content2, css=None)
                changed = 1
            if changed == 1:
                topic.node_id = cur_node_id
                topic.title = cur_title
                topic.content = cur_content
                History(user_id=user.id, content=diff_content,
                        topic_id=topic.id).save()
            else:
                return topic
        else:
            category = 'create'
            topic = Topic(**data)
        return topic.save(category=category)
예제 #4
0
 def save(self, user, topic, reply=None):
     data = self.data
     content = str(data.get('content'))
     data.update({'user_id': user.id, 'topic_id': topic.id,
                  'content': strip_xss_tags(content)})
     if reply:
         category = 'edit'
         pre_content = reply.content
         cur_content = data.get('content')
         changed = 0
         if pre_content != cur_content:
             diff_content = ghdiff.diff(pre_content, cur_content, css=None)
             changed = 1
         if changed == 1:
             reply.content = cur_content
             History(user_id=user.id, content=diff_content,
                     reply_id=reply.id).save()
         else:
             return reply
     else:
         category = 'create'
         reply = Reply(**data)
     return reply.save(category=category)