Example #1
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)
Example #2
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)