# 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


from sqlalchemy.schema import Column, ForeignKey, CheckConstraint, \
    UniqueConstraint, ForeignKeyConstraint, Table
from sqlalchemy.types import Boolean, Integer, Float, String, Unicode, \
    Interval, Enum
from sqlalchemy.orm import backref, relationship
from sqlalchemy.ext.orderinglist import ordering_list
from cms.db import Contest, Task
from cmsocial.db.base import Base

    # Access level required
    access_level = Column(
        Integer,
        nullable=False,
        default=7
    )

    # "Contest" the lesson is part of
    contest_id = Column(
        Integer,
        ForeignKey(
            Contest.id,
            onupdate="CASCADE",
            ondelete="CASCADE"
        ),
        nullable=False,
        index=True
    )

    contest = relationship(
        Contest,
        backref=backref(
            'lessons',
            cascade="all, delete-orphan",
            passive_deletes=True
        )
    )



# 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/lesson.py
from sqlalchemy.schema import Column, ForeignKey, CheckConstraint, \
    UniqueConstraint, ForeignKeyConstraint, Table
from sqlalchemy.types import Boolean, Integer, Float, String, Unicode, \
    Interval, Enum
from sqlalchemy.orm import backref, relationship
from sqlalchemy.ext.orderinglist import ordering_list
from cms.db import Contest, Task
from cmsocial.db.base import Base


    # Access level required
    access_level = Column(
        Integer,
        nullable=False,
        default=7
    )

    # "Contest" the lesson is part of
    contest_id = Column(
        Integer,
        ForeignKey(
            Contest.id,
            onupdate="CASCADE",
            ondelete="CASCADE"
        ),
        nullable=False,
        index=True
    )

    contest = relationship(
        Contest,
        backref=backref(
            'lessons',
            cascade="all, delete-orphan",
            passive_deletes=True
        )
    )



class LessonTask(Base):