# Path: template_maker/extensions.py

# 
# 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/forms.py
# class TemplateBaseForm(Form):
#     '''
#     Simple form for creating a new template
#     '''
#     title = StringField('Title', validators=[DataRequired()])
#     description = TextAreaField('Description', validators=[DataRequired()])
# 
# class TemplateSectionForm(Form):
#     '''
#     Simple form for creating adding a new template section
#     '''
#     title = StringField('Title')
#     type = SelectField('Type', choices=IMPLEMENTED_SECTIONS)
# 
# class TemplateSectionTextForm(Form):
#     '''
#     WYSIWYG Editor for the TextSection and FixedTextSection Models
#     '''
#     title = StringField('Title')
#     widget = FroalaField()
# 
# Path: template_maker/data/templates.py
# def get_all_templates():
# def get_published_templates():
# def get_single_template(template_id):
# def create_new_template(data):
# def delete_template(template):
# def publish_template(template_id):
# 
# Path: template_maker/data/sections.py
# SECTION_TYPE_MAPS = {
#     'text': TextSection, 'fixed_text': FixedTextSection,
# }
# def get_template_sections(template):
# def get_single_section(section_id, template_id):
# def create_new_section(section, template_id):
# def reorder_sections(template, section_order, to_delete=None):
# def update_section(section, placeholders, template_id, form_input):
# def delete_section(section_id, template_id):
# 
# Path: template_maker/data/placeholders.py
# VARIABLE_TYPE_MAPS = {
#     'text': 1, 'date': 2,'number': 3, 'float': 4
# }
# def get_all_placeholders(html):
# def get_template_placeholders(template_id):
# def get_section_placeholders(section_id):
# def parse_placeholder_text(placeholder):
# def dedupe_placeholders(input_placeholders):
# def update_placeholders(input_placeholders, current_placeholders, template_id, section_id):
# def delete_placeholders(to_delete_placeholders, template_id, section_id):
# def create_placeholders(new_placeholders, template_id, section_id):
# 
# Path: template_maker/data/documents.py
# def get_all_documents():
# def get_documents_and_parent_templates():
# def get_document_placeholders(document_id):
# def get_single_document(document_id):
# def get_single_document_and_parent_template(document_id):
# def set_document_placeholders(template_id, document_base):
# def update_documents(template_id):
# def create_new_document(template_id, data):
# def save_document_section(placeholders, data):
# def delete_document(document):


from flask import (
    Blueprint, request, make_response,
    render_template, redirect, abort, url_for,
    flash, current_app
)
from flask.ext.login import current_user
from template_maker.extensions import login_manager
from template_maker.users.models import User
from template_maker.builder.forms import (
    TemplateBaseForm, TemplateSectionForm,
    TemplateSectionTextForm
)
from template_maker.data import (
    templates as tp, sections as sc,
    placeholders as ph, documents as dm
)
from template_maker.builder.boilerplate import boilerplate as html_boilerplate





blueprint = Blueprint(
    'builder', __name__, url_prefix='/build',
    template_folder='../templates',
)

@login_manager.user_loader
def load_user(userid):
    return User.get_by_id(int(userid))

# restrict blueprint to only authenticated users
@blueprint.before_request
def restrict_access():
    if current_app.config.get('ENV') != 'test':
        if not current_user.is_authenticated() or current_user.is_anonymous():
            return redirect(url_for('users.login'))

SECTION_FORM_MAP = {
    'text': TemplateSectionTextForm,

# Path: template_maker/extensions.py

# 
# 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/forms.py
# class TemplateBaseForm(Form):
#     '''
#     Simple form for creating a new template
#     '''
#     title = StringField('Title', validators=[DataRequired()])
#     description = TextAreaField('Description', validators=[DataRequired()])
# 
# class TemplateSectionForm(Form):
#     '''
#     Simple form for creating adding a new template section
#     '''
#     title = StringField('Title')
#     type = SelectField('Type', choices=IMPLEMENTED_SECTIONS)
# 
# class TemplateSectionTextForm(Form):
#     '''
#     WYSIWYG Editor for the TextSection and FixedTextSection Models
#     '''
#     title = StringField('Title')
#     widget = FroalaField()
# 
# Path: template_maker/data/templates.py
# def get_all_templates():
# def get_published_templates():
# def get_single_template(template_id):
# def create_new_template(data):
# def delete_template(template):
# def publish_template(template_id):
# 
# Path: template_maker/data/sections.py
# SECTION_TYPE_MAPS = {
#     'text': TextSection, 'fixed_text': FixedTextSection,
# }
# def get_template_sections(template):
# def get_single_section(section_id, template_id):
# def create_new_section(section, template_id):
# def reorder_sections(template, section_order, to_delete=None):
# def update_section(section, placeholders, template_id, form_input):
# def delete_section(section_id, template_id):
# 
# Path: template_maker/data/placeholders.py
# VARIABLE_TYPE_MAPS = {
#     'text': 1, 'date': 2,'number': 3, 'float': 4
# }
# def get_all_placeholders(html):
# def get_template_placeholders(template_id):
# def get_section_placeholders(section_id):
# def parse_placeholder_text(placeholder):
# def dedupe_placeholders(input_placeholders):
# def update_placeholders(input_placeholders, current_placeholders, template_id, section_id):
# def delete_placeholders(to_delete_placeholders, template_id, section_id):
# def create_placeholders(new_placeholders, template_id, section_id):
# 
# Path: template_maker/data/documents.py
# def get_all_documents():
# def get_documents_and_parent_templates():
# def get_document_placeholders(document_id):
# def get_single_document(document_id):
# def get_single_document_and_parent_template(document_id):
# def set_document_placeholders(template_id, document_base):
# def update_documents(template_id):
# def create_new_document(template_id, data):
# def save_document_section(placeholders, data):
# def delete_document(document):


# Path: template_maker/builder/views.py
from flask import (
    Blueprint, request, make_response,
    render_template, redirect, abort, url_for,
    flash, current_app
)
from flask.ext.login import current_user
from template_maker.extensions import login_manager
from template_maker.users.models import User
from template_maker.builder.forms import (
    TemplateBaseForm, TemplateSectionForm,
    TemplateSectionTextForm
)
from template_maker.data import (
    templates as tp, sections as sc,
    placeholders as ph, documents as dm
)
from template_maker.builder.boilerplate import boilerplate as html_boilerplate






blueprint = Blueprint(
    'builder', __name__, url_prefix='/build',
    template_folder='../templates',
)

@login_manager.user_loader
def load_user(userid):
    return User.get_by_id(int(userid))

# restrict blueprint to only authenticated users
@blueprint.before_request
def restrict_access():
    if current_app.config.get('ENV') != 'test':
        if not current_user.is_authenticated() or current_user.is_anonymous():
            return redirect(url_for('users.login'))

SECTION_FORM_MAP = {
    'text': TemplateSectionTextForm,

    'fixed_text': TemplateSectionTextForm,