From: Eevee Date: Sun, 15 Aug 2010 07:26:51 +0000 (-0700) Subject: Added a per-user stash. X-Git-Tag: veekun-promotions/2010082201~1 X-Git-Url: http://git.veekun.com/zzz-spline-users.git/commitdiff_plain/2fcca859668a4d3f86377bd9d74787e23021321c?hp=61467d3f78bc332dda9642d7f04a94dffadd8b3d Added a per-user stash. --- diff --git a/migration/versions/004_Add_user_stash.py b/migration/versions/004_Add_user_stash.py new file mode 100644 index 0000000..67da19f --- /dev/null +++ b/migration/versions/004_Add_user_stash.py @@ -0,0 +1,29 @@ +from sqlalchemy import * +from migrate import * +import migrate.changeset # monkeypatches Column + +import json + +from sqlalchemy import orm +from sqlalchemy.ext.declarative import declarative_base +TableBase = declarative_base() + + +class User(TableBase): + __tablename__ = 'users' + id = Column(Integer, primary_key=True) + name = Column(Unicode(length=20), nullable=False) + unique_identifier = Column(Unicode(length=32), nullable=False) + stash = Column(PickleType(pickler=json), nullable=True, default={}) + + +def upgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine + + User.__table__.c.stash.create(table=User.__table__) + User.__table__.c.stash.alter(nullable=False) + +def downgrade(migrate_engine): + TableBase.metadata.bind = migrate_engine + + User.__table__.c.stash.drop() diff --git a/splinext/users/model/__init__.py b/splinext/users/model/__init__.py index 4ad49aa..b5ea63c 100644 --- a/splinext/users/model/__init__.py +++ b/splinext/users/model/__init__.py @@ -1,5 +1,6 @@ # encoding: utf8 import colorsys +import json from math import sin, pi import random @@ -7,7 +8,7 @@ from sqlalchemy import Column, ForeignKey, or_ from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.orm import relation from sqlalchemy.orm.session import Session -from sqlalchemy.types import Integer, Unicode +from sqlalchemy.types import Integer, PickleType, Unicode from spline.model.meta import TableBase @@ -16,6 +17,7 @@ class AnonymousUser(object): Tests as false and tries to respond to method calls the expected way. """ + stash = {} def __nonzero__(self): return False @@ -32,6 +34,7 @@ class User(TableBase): id = Column(Integer, primary_key=True) name = Column(Unicode(length=20), nullable=False) unique_identifier = Column(Unicode(length=32), nullable=False) + stash = Column(PickleType(pickler=json), nullable=False, default=dict()) def __init__(self, *args, **kwargs): # Generate a unique hash if one isn't provided (which it shouldn't be)