def diff(request, revision_id, other_revision_id=None):
revision = get_object_or_404(models.ArticleRevision, id=revision_id)
if not other_revision_id:
other_revision = revision.previous_revision
baseText = other_revision.content if other_revision else ""
newText = revision.content
differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)
diff = differ.compare(baseText.splitlines(1), newText.splitlines(1))
other_changes = []
if not other_revision or other_revision.title != revision.title:
other_changes.append((_('New title'), revision.title))
return dict(diff=list(diff), other_changes=other_changes)
# TODO: Throw in a class-based view
评论列表
文章目录