# Path: template_maker/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, ondelete=None, pk_name='id', **kwargs):
# 
# Path: template_maker/users/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     __tablename__ = 'users'
#     email = Column(db.String(80), unique=True, nullable=False)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     first_name = Column(db.String(30), nullable=True)
#     last_name = Column(db.String(30), nullable=True)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     def __init__(self, email, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
# 
#     @property
#     def full_name(self):
#         return "{0} {1}".format(self.first_name, self.last_name)
# 
#     def __repr__(self):
#         return '<User({email!r})>'.format(email=self.email)


from template_maker.database import (
    Column,
    Model,
    db,
    ReferenceCol,
)
from template_maker.users.models import User
from sqlalchemy.dialects.postgres import ARRAY
    - position: Where in the template the section lies
    - template_id: Foreign Key relationship back to the TemplateBase
    - section_type: The type of section to be used. This uses "joined
    table inheritance": http://docs.sqlalchemy.org/en/rel_0_9/orm/inheritance.html
    '''

    __tablename__ = 'template_section'
    id = Column(db.Integer, primary_key=True)
    title = Column(db.String(255))
    description = Column(db.Text)
    template_id = ReferenceCol('template_base')
    template_placeholders = db.relationship('TemplatePlaceholders', cascade='all,delete', lazy='dynamic')
    section_type = Column('section_type', db.String(50))
    __mapper_args__ = {'polymorphic_on': section_type}

    def __init__(self, template_id=None, title=None, description=None):
        self.template_id = template_id
        self.title = title
        self.description = description

class TextSection(TemplateSection):
    '''
    TextSection is a class of TemplateSection; it supports large text input with
    placeholder interpolation

    Fields:
    - id: 1:1 Relationship from TemplateSection
    - text: Text of the section
    '''
    __tablename__ = 'text_section'

# Path: template_maker/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
# class SurrogatePK(object):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
#     def get_by_id(cls, id):
# def ReferenceCol(tablename, nullable=False, ondelete=None, pk_name='id', **kwargs):
# 
# Path: template_maker/users/models.py
# class User(UserMixin, SurrogatePK, Model):
# 
#     __tablename__ = 'users'
#     email = Column(db.String(80), unique=True, nullable=False)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     first_name = Column(db.String(30), nullable=True)
#     last_name = Column(db.String(30), nullable=True)
#     active = Column(db.Boolean(), default=False)
#     is_admin = Column(db.Boolean(), default=False)
# 
#     def __init__(self, email, **kwargs):
#         db.Model.__init__(self, email=email, **kwargs)
# 
#     @property
#     def full_name(self):
#         return "{0} {1}".format(self.first_name, self.last_name)
# 
#     def __repr__(self):
#         return '<User({email!r})>'.format(email=self.email)


# Path: template_maker/builder/models.py
from template_maker.database import (
    Column,
    Model,
    db,
    ReferenceCol,
)
from template_maker.users.models import User
from sqlalchemy.dialects.postgres import ARRAY

    - position: Where in the template the section lies
    - template_id: Foreign Key relationship back to the TemplateBase
    - section_type: The type of section to be used. This uses "joined
    table inheritance": http://docs.sqlalchemy.org/en/rel_0_9/orm/inheritance.html
    '''

    __tablename__ = 'template_section'
    id = Column(db.Integer, primary_key=True)
    title = Column(db.String(255))
    description = Column(db.Text)
    template_id = ReferenceCol('template_base')
    template_placeholders = db.relationship('TemplatePlaceholders', cascade='all,delete', lazy='dynamic')
    section_type = Column('section_type', db.String(50))
    __mapper_args__ = {'polymorphic_on': section_type}

    def __init__(self, template_id=None, title=None, description=None):
        self.template_id = template_id
        self.title = title
        self.description = description

class TextSection(TemplateSection):
    '''
    TextSection is a class of TemplateSection; it supports large text input with
    placeholder interpolation

    Fields:
    - id: 1:1 Relationship from TemplateSection
    - text: Text of the section
    '''
    __tablename__ = 'text_section'

    section_id = Column(db.Integer, db.ForeignKey('template_section.id'), primary_key=True)