Ejemplo n.º 1
0
def _get_version_diffs_for_obj(obj, limit):
    version_list = revisions.get_for_object(obj)
    fields = [field for field in obj._meta.fields]
    version_diffs, last_edited = [], None
    if len(version_list) > 1:
        last_edited = version_list[0].revision.date_created
        old_versions = version_list[1:limit + 1]
        for iversion, version in enumerate(old_versions):
            newer_version = version_list[iversion]
            diff_dict = {}
            for field in fields:
                if generate_patch(version, newer_version, field.name):
                    # If versions differ, generate a pretty html diff
                    diff_html = generate_patch_html(
                        version, newer_version, field.name)
                    diff_dict[field.name] = (
                        version.field_dict[field.name],
                        newer_version.field_dict[field.name],
                        diff_html,
                    )
            version_diffs.append({
                'diff_dict': diff_dict,
                'user': newer_version.revision.user,
                'date': newer_version.revision.date_created,
            })
    return version_diffs, last_edited
Ejemplo n.º 2
0
 def testCanGeneratePatch(self):
     """Tests that text and HTML patches can be generated."""
     version_0 = Version.objects.get_for_object(self.site)[0]
     version_1 = Version.objects.get_for_object(self.site)[1]
     self.assertEqual(generate_patch(version_0, version_1, "domain"),
                      "@@ -10,9 +10,9 @@\n rev-\n-1\n+2\n .com\n")
     self.assertEqual(generate_patch_html(version_0, version_1, "domain"),
                      u'<SPAN TITLE="i=0">www.site-rev-</SPAN><DEL STYLE="background:#FFE6E6;" TITLE="i=13">1</DEL><INS STYLE="background:#E6FFE6;" TITLE="i=13">2</INS><SPAN TITLE="i=14">.com</SPAN>')
    def get_revisions(self, obj):
        reversions = list(reversion.get_for_object(obj))
        zipped_reversions = zip(reversions + [None], [None] + reversions)[1:-1]
        results = []
        for new, old in zipped_reversions:
            diff = []
            for field_name in new.field_dict.keys():
                if generate_patch(old, new, field_name):
                    diff += [(field_name, generate_patch_html(old, new, field_name))]
            results += [{
                'user': UserSerializer(new.revision.user).data,
                'revision': new.field_dict,
                'timestamp': new.revision.date_created,
                'diff': dict(diff),
            }]

        return results
Ejemplo n.º 4
0
 def testCanGeneratePatch(self):
     self.assertEqual(
         generate_patch(self.version1, self.version2, "name"),
         "@@ -17,9 +17,9 @@\n  version\n-1\n+2\n",
     )
Ejemplo n.º 5
0
 def testCanGeneratePatch(self):
     """Tests that text patches can be generated."""
     self.assertEqual(generate_patch(self.test_0, self.test_1, "name"),
                      "@@ -3,5 +3,5 @@\n st1.\n-0\n+1\n")
Ejemplo n.º 6
0
 def testCanGeneratePatch(self):
     self.assertEqual(
         generate_patch(self.version1, self.version2, "name"),
         "@@ -17,9 +17,9 @@\n  version\n-1\n+2\n",
     )
Ejemplo n.º 7
0
 def testCanGeneratePatch(self):
     """Tests that text patches can be generated."""
     self.assertEqual(generate_patch(self.test_0, self.test_1, "name"),
                      "@@ -3,5 +3,5 @@\n st1.\n-0\n+1\n")