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()
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
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)
def diff(t1, t2): dmp = diff_match_patch() patch = dmp.patch_make(t1, t2) return dmp.patch_toText(patch)
def show_diff(self): dmp = diff_match_patch() return dmp.diff_prettyHtml(self.diff)
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()
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
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