Skip to content

Instantly share code, notes, and snippets.

@gbozee
Forked from darkpixel/gist:3473470
Last active August 29, 2015 14:07
Show Gist options
  • Save gbozee/d4e4066acb4d7ccbd27f to your computer and use it in GitHub Desktop.
Save gbozee/d4e4066acb4d7ccbd27f to your computer and use it in GitHub Desktop.
def cycle_key(self):
#TODO: Errors here will tank the system, probably need some better handling...
old_session_key = self.session_key
old_session = Session.objects.get(session_key=old_session_key)
try:
cart = Cart.objects.get(session=old_session)
super(SessionStore, self).cycle_key()
new_session_key = self.session_key
new_session = Session.objects.get(session_key=new_session_key)
cart.session = new_session
cart.save()
logger.debug('Migrated cart from session %s to %s' %(old_session_key, new_session_key))
except Cart.DoesNotExist:
logger.debug('Session %s does not have a cart to migrate' %(old_session_key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment