Chapter 12.2.2. Overriding Attribute Access

This is where the pedal really hits the metal. This is the holy grail of ORM because it enables you to massage the data before/after it gets into/out of the DB and provide useful services to the applications. Consider an account object with an encrypted credit card number field. If this object is being accessed from multiple applications, each application must know how and remember to encrypt/decrypt the credit card number on the way into and out of the DB. A better solution is to have the application provide the encryption key and have the model class do the encryption/decryption automatically upon access. In the following code, the application sets the encryption key as a regular Python class attribute ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.