Exemplo n.º 1
0
 def text_at_revision(self, revision):
     """Returns the text as it was at the specified revision."""
     if revision.article != self:
         raise RelationshipMismatch()
     d = diff_match_patch()
     rewound = self.text
     for r in self.revisions.filter(date__gte=revision.date):
         rewound = d.patch_apply(d.patch_fromText(r.delta), rewound)[0]
     return rewound
Exemplo n.º 2
0
 def revise_text(self, revised_text, reviser=None):
     if reviser is None:
         try:
             reviser = self.authors_in_order().all()[0]
         except IndexError:
             # TODO: better error handling when there's no authors
             reviser = None
     d = diff_match_patch()
     patch = d.patch_toText(d.patch_make(revised_text, self.text))
     
     ArticleRevision.objects.create(article=self, delta=patch, reviser=reviser)
     self.text = revised_text
     self.save()