def form_valid(self, form): with reversion.create_revision(): form.save() reversion.set_user(form.instance.user) print(form.instance.user) print(reversion.get_user()) form_html = render_crispy_form(form) update_url = form.instance.get_update_url() context = {'success': True, 'form_html': form_html, 'pk': form.instance.id, 'update_url': update_url} return context
def testCanAddMetaToRevision(self): # Create a revision with lots of meta data. with reversion.create_revision(): self.test11.save() reversion.set_comment("Foo bar") self.assertEqual(reversion.get_comment(), "Foo bar") reversion.set_user(self.user) self.assertEqual(reversion.get_user(), self.user) reversion.add_meta(RevisionMeta, age=5) # Test the revision data. revision = reversion.get_for_object(self.test11)[0].revision self.assertEqual(revision.user, self.user) self.assertEqual(revision.comment, "Foo bar") self.assertEqual(revision.revisionmeta.age, 5)
def form_valid(self, form): with reversion.create_revision(): form.save() reversion.set_user(form.instance.user) print(form.instance.user) print(reversion.get_user()) form_html = render_crispy_form(form) update_url = form.instance.get_update_url() context = { 'success': True, 'form_html': form_html, 'pk': form.instance.id, 'update_url': update_url } return context
def testGetUserNoBlock(self): with self.assertRaises(reversion.RevisionManagementError): reversion.get_user()
def testGetUserDefault(self): with reversion.create_revision(): self.assertEqual(reversion.get_user(), None)
def testGetUser(self): with reversion.create_revision(): reversion.set_user(self.user) self.assertEqual(reversion.get_user(), self.user)