Skip to content

Commit

Permalink
Added a more explicit import error for when the encrypted fields are …
Browse files Browse the repository at this point in the history
…imported and keyczar is not installed.
  • Loading branch information
SeanOC authored and trbs committed Jan 18, 2010
1 parent 3c31e91 commit 57e9ce9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions django_extensions/db/fields/encrypted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
from django.core.exceptions import ImproperlyConfigured
from django import forms
from django.conf import settings
from keyczar import keyczar

try:
from keyczar import keyczar
except ImportError:
raise ImportError('Using an encrypted field requires the Keyczar module. You can obtain Keyczar from http://www.keyczar.org/.')

class BaseEncryptedField(models.Field):
prefix = 'enc_str:::'
def __init__(self, *args, **kwargs):
if not hasattr(settings, 'ENCRYPTED_FIELD_KEY_DIR'):
raise ImproperlyConfigured('You must set settings.ENCRYPTED_FIELD_KEY_DIR to your Keyczar keys directory.')
self.crypt = keyczar.Crypter.Read(settings.ENCRYPTED_FIELD_KEY_DIR)
if not hasattr(settings, 'ENCRYPTED_FIELD_KEYS_DIR'):
raise ImproperlyConfigured('You must set settings.ENCRYPTED_FIELD_KEYS_DIR to your Keyczar keys directory.')
self.crypt = keyczar.Crypter.Read(settings.ENCRYPTED_FIELD_KEYS_DIR)
super(BaseEncryptedField, self).__init__(*args, **kwargs)

def to_python(self, value):
Expand Down

0 comments on commit 57e9ce9

Please sign in to comment.