# Path: cmsocial/db/base.py
# class Base(CMSBase):
#     __abstract__ = True
#     _created = Column(DateTime, default=func.now())
#     _updated = Column(DateTime, default=func.now(), onupdate=func.now())
#     #TODO: maybe add the id field here and remove it elsewhere?
# 
#     def fieldnames(self, *args):
#         all_fields = map(lambda c: str(c).split('.')[-1], self.__table__.columns)
#         real_fields = filter(lambda c: not c.startswith('_'), all_fields)
# 
#         return real_fields
# 
# Path: cmsocial/db/location.py
# class Institute(Base):
#     __tablename__ = 'institutes'
# 
#     id = Column(Integer, primary_key=True, unique=True)
#     name = Column(Unicode)
# 
#     city_id = Column(
#         Integer,
#         ForeignKey(City.id,
#                    onupdate="CASCADE", ondelete="CASCADE"),
#         nullable=False,
#         index=True)
#     city = relationship(
#         City,
#         backref=backref("institutes",
#                         cascade="all, delete-orphan",
#                         passive_deletes=True))


from datetime import timedelta, datetime
from sqlalchemy.schema import Column, ForeignKey, CheckConstraint
from sqlalchemy.types import Boolean, Integer, String, Unicode, DateTime, \
    Interval
from sqlalchemy.orm import relationship, backref
from cms.db import Contest, Participation, User
from cmsocial.db.base import Base
from cmsocial.db.location import Institute
    )

    # 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/db/base.py
# class Base(CMSBase):
#     __abstract__ = True
#     _created = Column(DateTime, default=func.now())
#     _updated = Column(DateTime, default=func.now(), onupdate=func.now())
#     #TODO: maybe add the id field here and remove it elsewhere?
# 
#     def fieldnames(self, *args):
#         all_fields = map(lambda c: str(c).split('.')[-1], self.__table__.columns)
#         real_fields = filter(lambda c: not c.startswith('_'), all_fields)
# 
#         return real_fields
# 
# Path: cmsocial/db/location.py
# class Institute(Base):
#     __tablename__ = 'institutes'
# 
#     id = Column(Integer, primary_key=True, unique=True)
#     name = Column(Unicode)
# 
#     city_id = Column(
#         Integer,
#         ForeignKey(City.id,
#                    onupdate="CASCADE", ondelete="CASCADE"),
#         nullable=False,
#         index=True)
#     city = relationship(
#         City,
#         backref=backref("institutes",
#                         cascade="all, delete-orphan",
#                         passive_deletes=True))


# Path: cmsocial/db/socialuser.py
from datetime import timedelta, datetime
from sqlalchemy.schema import Column, ForeignKey, CheckConstraint
from sqlalchemy.types import Boolean, Integer, String, Unicode, DateTime, \
    Interval
from sqlalchemy.orm import relationship, backref
from cms.db import Contest, Participation, User
from cmsocial.db.base import Base
from cmsocial.db.location import Institute

    )

    # 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")



class SocialParticipation(Base):