"""
Create all the tables
"""
+ metadata = MetaData(bind=db.bind)
+ user_table = inspect_table(metadata, "core__users")
+
# Create tables needed
LocalUser_V0.__table__.create(db.bind)
RemoteUser_V0.__table__.create(db.bind)
db.commit()
# Create the fields
- metadata = MetaData(bind=db.bind)
- user_table = inspect_table(metadata, "core__users")
-
updated_column = Column(
"updated",
DateTime,
)
updated_column.create(user_table)
+ type_column = Column(
+ "type",
+ Unicode
+ )
+ type_column.create(user_table)
+
name_column = Column(
"name",
Unicode
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)
# 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
uploaded = Column(Integer, default=0)
upload_limit = Column(Integer)
+ __mapper_args__ = {
+ 'polymorphic_identity': 'user_local'
+ }
+
## TODO
# plugin data would be in a separate model
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__,