Hi Jonathan, I've found a use for the versioned extension already in my project, neatly solved a problem that I didn't know how to get around (by accident!)
So far I've not used it anger, but preliminary testing seems good :) Thanks, Matt On Aug 3, 11:42 pm, Jonathan LaCour <[EMAIL PROTECTED]> wrote: > Greetings Elixir users! > > A little treat for your weekend: I just committed two new elixir > extensions! > > The first, elixir.ext.encrypted, provides automatic encryption using > blowfish encryption for any unicode field in your elixir entities. It > requires the excellent PyCrypto (http://www.amk.ca/python/code/crypto). > > The second, elixir.ext.versioned, provides a fairly complete > implementation of versioning for your entities - as you update > instances, the history of that instance is tracked, with version numbers > and timestamps, including the ability to look at old versions, compare > versions, and revert to previous versions. > > Here is a short example of both extensions in use, along with an example > of the new event code that we integrated into Elixir earlier in the > week: > > from elixir import * > from elixir.events import before_update > from elixir.ext.versionedimport acts_as_versioned, after_revert > from elixir.ext.encrypted import acts_as_encrypted > > class Person(Entity): > has_field('name', Unicode) > has_field('email', Unicode) > has_field('password', Unicode) > > has_many('articles', of_kind='Article', inverse='author') > acts_as_encrypted(for_fields=['password'], > with_secret='s3cr1t') > > class Article(Entity): > has_field('title', Unicode, primary_key=True) > has_field('description', Unicode) > has_field('content', Unicode) > > belongs_to('author', of_kind='Person', inverse='articles') > acts_as_versioned() > > @after_update > def article_updated(self): > ''' > Called after update, where you can access the new version > number through self.version, and the timestamp through > self.timestamp. > ''' > print '-' * 80 > print 'Article updated at', self.timestamp > print ' new version is ->', self.version > > @after_revert > def article_reverted(self): > ''' > Called after the instance is reverted > ''' > print '-' * 80 > print 'Article reverted!' > print '-' * 80 > > if __name__ == '__main__': > metadata.bind = 'sqlite:///' > metadata.create_all() > > jonathan = Person( > name='Jonathan', > email='[EMAIL PROTECTED]' > ) > blog_post = Article( > title='Some Blog Post', > description='A blog post on some subject', > content='Draft content for blog post', > author=jonathan > ) > objectstore.flush(); objectstore.clear() > > blog_post = Article.get('Some Blog Post') > blog_post.content = 'Updated content for blog post' > objectstore.flush(); objectstore.clear() > > blog_post = Article.get('Some Blog Post') > blog_post.content = 'Even more updated post' > objectstore.flush(); objectstore.clear() > > blog_post = Article.get('Some Blog Post') > for previous_version in blog_post.versions: > print '-' * 80 > print previous_version.version > print previous_version.timestamp > print blog_post.compare_with(previous_version) > print '-' * 80 > > assert blog_post.version == 3 > > blog_post.revert() > objectstore.flush(); objectstore.clear() > > blog_post = Article.get('Some Blog Post') > assert blog_post.version == 2 > assert blog_post.content == 'Updated content for blog post' > > I would love to get some feedback on these extensions, along with any > suggestions on how I might make them better. Have a great weekend! > > -- > Jonathan LaCourhttp://cleverdevil.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "SQLElixir" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlelixir?hl=en -~----------~----~----~----~------~----~------~--~---
