Skip to content

Commit

Permalink
Prefix django fields
Browse files Browse the repository at this point in the history
This way they won't override something in already in custom data
with the same name. Some small code cleanups
  • Loading branch information
denibertovic committed Oct 9, 2014
1 parent b3eedd6 commit 37ff75b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions django_stormpath/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,26 @@ class Meta:

objects = StormpathUserManager()

DJANGO_PREFIX = 'spDjango_'

def _mirror_data_from_db_user(self, account, data):
for field in self.EXCLUDE_FIELDS:
try:
if field in data:
del data[field]
except KeyError:
pass
try:
if data['password'] is None:
del data['password']
except KeyError:
pass

if 'password' in data:
del data['password']

account.status = account.STATUS_DISABLED if data['is_active'] is False else account.STATUS_ENABLED

if 'is_active' in data:
del data['is_active']

for key in data:
if key in self.STORMPATH_BASE_FIELDS:
account[key] = data[key]
else:
account.custom_data[key] = data[key]

account.status = account.STATUS_DISABLED if data['is_active'] is False else account.STATUS_ENABLED
account.custom_data[self.DJANGO_PREFIX + key] = data[key]

return account

Expand All @@ -110,7 +112,7 @@ def _mirror_data_from_stormpath_account(self, account):
if field != 'password':
self.__setattr__(field, account[field])
for key in account.custom_data.keys():
self.__setattr__(key, account.custom_data[key])
self.__setattr__(key.split(self.DJANGO_PREFIX)[0], account.custom_data[key])

self.is_active = True if account.status == account.STATUS_ENABLED else False

Expand Down

0 comments on commit 37ff75b

Please sign in to comment.