# Path: cmsocial/db/socialuser.py
# class SocialUser(Base):
#     """Class to store stats and custom fields (institute_id?) of a user.
# 
#     """
#     __tablename__ = 'social_users'
# 
#     # User.id == SocialUser.id
#     id = Column(
#         Integer,
#         ForeignKey("users.id",
#             onupdate="CASCADE",
#             ondelete="CASCADE"
#         ),
#         primary_key=True,
#         unique=True
#     )
# 
#     user = relationship(
#         User,
#         backref=backref(
#             "social_user",
#             uselist=False
#         )
#     )
# 
#     # Registration time
#     registration_time = Column(
#         DateTime,
#         nullable=False,
#         default=datetime.utcnow()
#     )
# 
#     # Access level
#     access_level = Column(
#         Integer,
#         nullable=False,
#         default=6
#     )
# 
#     # Recover code (for password reset)
#     recover_code = Column(
#         String,
#         nullable=True
#     )
# 
#     # The last time this user requested a new password
#     last_recover = Column(
#         DateTime,
#         nullable=False,
#         default=datetime.utcfromtimestamp(0)
#     )
# 
#     # CUSTOM FIELDS:
# 
#     # Institute
#     institute_id = Column(
#         Integer,
#         ForeignKey(
#             Institute.id,
#             onupdate="CASCADE",
#             ondelete="SET NULL"
#         ),
#         nullable=True,
#         index=True
#     )
# 
#     institute = relationship(
#         Institute,
#         backref=backref(
#             "users",
#             cascade="all, delete-orphan",
#             passive_deletes=True
#         )
#     )
# 
#     # List of tasktags (not "approved" yet) created by this user
#     # FIXME: the following causes a circular dependency
#     # tasktags = relationship("TaskTag")


from cms.db import SessionGen, User
from cmsocial.db.socialuser import SocialUser
# -*- coding: utf-8 -*-


def main():
    with SessionGen() as s:
        for user in s.query(User).all():
            if not s.query(SocialUser).filter(SocialUser.id == user.id).first():
                if raw_input("User " + user.first_name + " " + user.last_name + " doesn't have metadata. Create? [Y/n]") in ["y", "Y", ""]:

# Path: cmsocial/db/socialuser.py
# class SocialUser(Base):
#     """Class to store stats and custom fields (institute_id?) of a user.
# 
#     """
#     __tablename__ = 'social_users'
# 
#     # User.id == SocialUser.id
#     id = Column(
#         Integer,
#         ForeignKey("users.id",
#             onupdate="CASCADE",
#             ondelete="CASCADE"
#         ),
#         primary_key=True,
#         unique=True
#     )
# 
#     user = relationship(
#         User,
#         backref=backref(
#             "social_user",
#             uselist=False
#         )
#     )
# 
#     # Registration time
#     registration_time = Column(
#         DateTime,
#         nullable=False,
#         default=datetime.utcnow()
#     )
# 
#     # Access level
#     access_level = Column(
#         Integer,
#         nullable=False,
#         default=6
#     )
# 
#     # Recover code (for password reset)
#     recover_code = Column(
#         String,
#         nullable=True
#     )
# 
#     # The last time this user requested a new password
#     last_recover = Column(
#         DateTime,
#         nullable=False,
#         default=datetime.utcfromtimestamp(0)
#     )
# 
#     # CUSTOM FIELDS:
# 
#     # Institute
#     institute_id = Column(
#         Integer,
#         ForeignKey(
#             Institute.id,
#             onupdate="CASCADE",
#             ondelete="SET NULL"
#         ),
#         nullable=True,
#         index=True
#     )
# 
#     institute = relationship(
#         Institute,
#         backref=backref(
#             "users",
#             cascade="all, delete-orphan",
#             passive_deletes=True
#         )
#     )
# 
#     # List of tasktags (not "approved" yet) created by this user
#     # FIXME: the following causes a circular dependency
#     # tasktags = relationship("TaskTag")


# Path: cmsocial/scripts/syncusers.py
from cms.db import SessionGen, User
from cmsocial.db.socialuser import SocialUser

# -*- coding: utf-8 -*-


def main():
    with SessionGen() as s:
        for user in s.query(User).all():
            if not s.query(SocialUser).filter(SocialUser.id == user.id).first():
                if raw_input("User " + user.first_name + " " + user.last_name + " doesn't have metadata. Create? [Y/n]") in ["y", "Y", ""]:

                    x = SocialUser()