aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authorJessica Tallon <tsyesika@tsyesika.se>2015-07-17 17:49:18 +0200
committerJessica Tallon <tsyesika@tsyesika.se>2015-07-31 15:14:41 +0200
commit283e6d8b9f09341e3b97418b79f389bfdfee6498 (patch)
treec4ad5e0749ed311c3248e051ab36f189273d4840 /mediagoblin/db/models.py
parentaa9ba3ed8010362466d14037e2c9950ce3bc2cb2 (diff)
downloadmediagoblin-283e6d8b9f09341e3b97418b79f389bfdfee6498.tar.lz
mediagoblin-283e6d8b9f09341e3b97418b79f389bfdfee6498.tar.xz
mediagoblin-283e6d8b9f09341e3b97418b79f389bfdfee6498.zip
Add polymorphic properties to User
This adds the ability to search for any user based on the generic User case and be given back the specific LocalUser or RemoteUser. This will require any code using the model to look which attributes they are searching on and specify the specific User model they are on if they're not on the generic User model. This will also require new users to be created with LocalUser.
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index ef37aef8..41c36764 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -237,6 +237,9 @@ class User(Base, UserMixin):
bio = Column(UnicodeText)
name = Column(Unicode)
+ # This is required for the polymorphic inheritance
+ type = Column(Unicode)
+
created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
updated = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
@@ -245,6 +248,11 @@ class User(Base, UserMixin):
# Lazy getters
get_location = relationship("Location", lazy="joined")
+ __mapper_args__ = {
+ 'polymorphic_identity': 'user',
+ 'polymorphic_on': type
+ }
+
def has_privilege(self, privilege, allow_admin=True):
"""
This method checks to make sure a user has all the correct privileges
@@ -324,6 +332,10 @@ class LocalUser(User):
uploaded = Column(Integer, default=0)
upload_limit = Column(Integer)
+ __mapper_args__ = {
+ 'polymorphic_identity': 'user_local'
+ }
+
## TODO
# plugin data would be in a separate model
@@ -394,6 +406,10 @@ class RemoteUser(User):
id = Column(Integer, ForeignKey("core__users.id"), primary_key=True)
webfinger = Column(Unicode, unique=True)
+ __mapper_args__ = {
+ 'polymorphic_identity': 'user_remote'
+ }
+
def __repr__(self):
return "<{0} #{1} {2}>".format(
self.__class__.__name__,