예제 #1
0
파일: models.py 프로젝트: jobscry/vz-wiki
def comparison_calculate_diff(sender, instance, created, **kwargs):
    if created:
        from utils.diff_match_patch import diff_match_patch
        diff = diff_match_patch()
        diff_array = diff.diff_main(instance.rev1.body, instance.rev2.body)
        diff.diff_cleanupSemantic(diff_array)
        instance.diff_text = diff.diff_prettyHtml(diff_array)
        instance.save()
예제 #2
0
 def get_diff(self):
     text2 = self.object.content
     if self.object.get_pre_revision():
         text1 = self.object.get_pre_revision().content
     else:
         text1 = ""
     func = diff_match_patch.diff_match_patch()
     diff = func.diff_main(text1, text2)
     func.diff_cleanupSemantic(diff)
     htmldiff = func.diff_prettyHtml(diff)
     return htmldiff
예제 #3
0
 def cal_add_delete_chars(self):
     if self.revision_number == 1:
         text1 = ""
     else:
         text1 = self.get_pre_revision().content
     text2 = self.content
     func = diff_match_patch.diff_match_patch()
     diff = func.diff_main(text1, text2)
     added = 0
     deleted = 0
     for (sign, frag) in diff:
         if sign == 1:
             added += len(frag)
         elif sign == -1:
             deleted += len(frag)
     self.added_chars = added
     self.deleted_chars = deleted
     self.total_chars = len(text2)
예제 #4
0
 def cal_add_delete_chars(self):
     if self.revision_number == 1:
         text1 = ""
     else:
         text1 = self.get_pre_revision().content
     text2 = self.content 
     func = diff_match_patch.diff_match_patch()
     diff = func.diff_main(text1, text2)
     added = 0
     deleted = 0
     for (sign, frag) in diff:
         if sign == 1:
             added += len(frag)
         elif sign == -1:
             deleted += len(frag)
     self.added_chars = added
     self.deleted_chars = deleted
     self.total_chars = len(text2)
예제 #5
0
def diff(t1, t2):
    dmp = diff_match_patch()
    patch = dmp.patch_make(t1, t2)
    return dmp.patch_toText(patch)
예제 #6
0
 def show_diff(self):
     dmp = diff_match_patch()
     return dmp.diff_prettyHtml(self.diff)
예제 #7
0
 def revert(self):
     dmp = diff_match_patch()
     patch = dmp.patch_fromText(self.diff)
     self.translation.suggestion = dmp.patch_apply(patch, self.translation.suggest)[0]
     self.translation.put()
예제 #8
0
def show_text_diff(text1, text2):
    func = diff_match_patch.diff_match_patch()
    diff = func.diff_main(text1, text2)
    func.diff_cleanupSemantic(diff)
    htmldiff = func.diff_prettyHtml(diff)
    return htmldiff
예제 #9
0
def show_text_diff(text1,text2):
        func = diff_match_patch.diff_match_patch()
        diff = func.diff_main(text1, text2)
        func.diff_cleanupSemantic(diff)
        htmldiff = func.diff_prettyHtml(diff)
        return htmldiff