def test_associate_revision_fields(self): """ Determines if the correct fields are being associated correctly with an edit. """ target_field = ModelField(name = 'username', mode = ModelField.TEXT, content = self.tracked_content) target_field.save() model_history = ModelHistory(object_id = self.test_user.id, content_type = ContentType.objects.get_for_model(User), created = False, data = json.dumps({'username':'******'}), user = self.test_user) final_edit = utils.associate_revision_fields(model_history) self.assertTrue(final_edit.fields) self.assertEqual(final_edit.fields[0]['name'], 'username') self.assertEqual(final_edit.fields[0]['content'], 'hanbox') target_field.delete()
def history(request, content_type, object_id): """ View for rendering a list of ModelHistory objects associated with the target object. Similar to StackOverflow's content history template. """ content_type_object = ContentType.objects.get(id=int(content_type)) node = content_type_object.model_class().objects.get(id=int(object_id)) revisions = ModelHistory.objects.filter(content_type=content_type_object, object_id=object_id).order_by( "-date_created" ) for revision in revisions: revision = associate_revision_fields(revision) revision.description = ",".join([k for k, v in json.loads(revision.data).items() if v]) view_url = reverse("content-redirect-by-id", args=[content_type, object_id]) return shortcuts.render_to_response( "django_contenthistory/contenthistory.html", {"revisions": revisions, "content_type": content_type, "object_id": object_id, "view_url": view_url}, context_instance=RequestContext(request), )