# Path: flask_editablesite/extensions.py

# 
# Path: flask_editablesite/editable/forms.py
# class TextEditForm(Form):
#     content = TextField('Content', validators=[DataRequired()])
# 
# class LongTextEditForm(Form):
#     content = TextAreaField('Content', validators=[DataRequired()])
# 
# class DateEditForm(Form):
#     content = DateField('Date', format='%d %b %Y', validators=[
#         DataRequired()])
# 
# class TimeEditForm(Form):
#     content = TimeField('Time', validators=[DataRequired()])
# 
# class ImageEditForm(Form):
#     image = FileField('Image', validators=[
#         DataRequired(),
#         FileAllowed(
#             ('gif', 'jpg', 'jpeg', 'png'),
#             ('Only image files (gif, jpg, png) can be uploaded '
#                 'for this field'))])
# 
# class ReorderForm(Form):
#     items = FieldList(FormField(ReorderItemForm))
# 
# Path: flask_editablesite/editable/utils.py
# def get_model_class(model_classpath, model_name):
#     """Dynamically imports the model with the specified classpath."""
# 
#     model_classpath_format = r'^[a-z0-9_]+(\.[A-Za-z0-9_]+)+$'
# 
#     if not re.match(model_classpath_format, model_classpath):
#         raise ValueError(
#             ('Class path "%s" for model name "%s" '
#                 'must be a valid Python module / class path (in the '
#                 'format "%s")') % (
#                     model_classpath,
#                     model_name,
#                     model_classpath_format))
# 
#     model_classpath_split = model_classpath.rpartition('.')
#     model_modulepath, model_classname = (
#         model_classpath_split[0],
#         model_classpath_split[2])
# 
#     try:
#         model_module = importlib.import_module(model_modulepath)
#     except ImportError:
#         raise ValueError(
#             ('Error importing module "%s" for '
#                 'model name "%s"') % (
#                     model_modulepath,
#                     model_name))
# 
#     model_class = getattr(model_module, model_classname, None)
#     if not model_class:
#         raise ValueError(
#             ('Class "%s" not found in module "%s" for '
#                 'model name "%s"') % (
#                     model_classname,
#                     model_modulepath,
#                     model_name))
# 
#     return model_class
# 
# Path: flask_editablesite/editable/sample_images.py
# def placeholder_or_random_sample_image():
#     """
#     Gets a random sample image if possible, otherwise the default
#     placeholder image.
#     """
# 
#     is_sample_images_configured = (
#         app.config.get('EDITABLE_SAMPLE_IMAGES_SCRAPE_URL') and
#         app.config.get('EDITABLE_SAMPLE_IMAGES_RELATIVE_PATH'))
# 
#     return (is_sample_images_configured
#             and random_sample_image()
#             or app.config['EDITABLE_PLACEHOLDER_IMAGE_RELATIVE_PATH'])
# 
# Path: flask_editablesite/editable/sample_text.py
# def placeholder_or_random_sample_text():
#     """
#     Gets a random sample chunk of text if possible, otherwise the
#     default placeholder text.
#     """
# 
#     is_sample_text_configured = (
#         app.config.get('EDITABLE_SAMPLE_TEXT_SCRAPE_URLS') and
#         True or False)
# 
#     return (is_sample_text_configured
#             and random_sample_text()
#             or app.config['EDITABLE_PLACEHOLDER_TEXT'])


from datetime import datetime
from glob import glob
from operator import itemgetter
from sqlalchemy.exc import IntegrityError
from flask import current_app as app
from flask import (abort, Blueprint, flash, url_for, redirect, request,
                   session, Response)
from flask_login import login_required, current_user
from flask_transfer import Transfer
from werkzeug import secure_filename
from flask_wtf import Form
from flask_editablesite.extensions import db
from flask_editablesite.editable.forms import (
    TextEditForm, LongTextEditForm, DateEditForm, TimeEditForm,
    ImageEditForm, ReorderForm)
from flask_editablesite.editable.utils import get_model_class
from flask_editablesite.editable.sample_images import (
    placeholder_or_random_sample_image,)
from flask_editablesite.editable.sample_text import (
    placeholder_or_random_sample_text,)
from flask_editablesite.utils import flash_errors
import os
        model_classpath = v['classpath']
    except KeyError:
        raise ValueError((
            'No class path defined in app config\'s '
            'EDITABLE_MODELS for model name "{0}"').format(
                model_name))

    try:
        title_field_name = v['title_field']
    except KeyError:
        raise ValueError((
            'No title field defined in app config\'s '
            'EDITABLE_MODELS for model name "{0}"').format(
                model_name))

    try:
        weight_field_name = v['weight_field']
    except KeyError:
        weight_field_name = None

    model_class = get_model_class(model_classpath, model_name)

    form = Form()

    if form.validate_on_submit():
        model_name_friendly = model_name.replace('_', ' ').title()
        model = model_class.new_item()

        if ('image_fields' in v) and v['image_fields']:
            for k in v['image_fields']:

# Path: flask_editablesite/extensions.py

# 
# Path: flask_editablesite/editable/forms.py
# class TextEditForm(Form):
#     content = TextField('Content', validators=[DataRequired()])
# 
# class LongTextEditForm(Form):
#     content = TextAreaField('Content', validators=[DataRequired()])
# 
# class DateEditForm(Form):
#     content = DateField('Date', format='%d %b %Y', validators=[
#         DataRequired()])
# 
# class TimeEditForm(Form):
#     content = TimeField('Time', validators=[DataRequired()])
# 
# class ImageEditForm(Form):
#     image = FileField('Image', validators=[
#         DataRequired(),
#         FileAllowed(
#             ('gif', 'jpg', 'jpeg', 'png'),
#             ('Only image files (gif, jpg, png) can be uploaded '
#                 'for this field'))])
# 
# class ReorderForm(Form):
#     items = FieldList(FormField(ReorderItemForm))
# 
# Path: flask_editablesite/editable/utils.py
# def get_model_class(model_classpath, model_name):
#     """Dynamically imports the model with the specified classpath."""
# 
#     model_classpath_format = r'^[a-z0-9_]+(\.[A-Za-z0-9_]+)+$'
# 
#     if not re.match(model_classpath_format, model_classpath):
#         raise ValueError(
#             ('Class path "%s" for model name "%s" '
#                 'must be a valid Python module / class path (in the '
#                 'format "%s")') % (
#                     model_classpath,
#                     model_name,
#                     model_classpath_format))
# 
#     model_classpath_split = model_classpath.rpartition('.')
#     model_modulepath, model_classname = (
#         model_classpath_split[0],
#         model_classpath_split[2])
# 
#     try:
#         model_module = importlib.import_module(model_modulepath)
#     except ImportError:
#         raise ValueError(
#             ('Error importing module "%s" for '
#                 'model name "%s"') % (
#                     model_modulepath,
#                     model_name))
# 
#     model_class = getattr(model_module, model_classname, None)
#     if not model_class:
#         raise ValueError(
#             ('Class "%s" not found in module "%s" for '
#                 'model name "%s"') % (
#                     model_classname,
#                     model_modulepath,
#                     model_name))
# 
#     return model_class
# 
# Path: flask_editablesite/editable/sample_images.py
# def placeholder_or_random_sample_image():
#     """
#     Gets a random sample image if possible, otherwise the default
#     placeholder image.
#     """
# 
#     is_sample_images_configured = (
#         app.config.get('EDITABLE_SAMPLE_IMAGES_SCRAPE_URL') and
#         app.config.get('EDITABLE_SAMPLE_IMAGES_RELATIVE_PATH'))
# 
#     return (is_sample_images_configured
#             and random_sample_image()
#             or app.config['EDITABLE_PLACEHOLDER_IMAGE_RELATIVE_PATH'])
# 
# Path: flask_editablesite/editable/sample_text.py
# def placeholder_or_random_sample_text():
#     """
#     Gets a random sample chunk of text if possible, otherwise the
#     default placeholder text.
#     """
# 
#     is_sample_text_configured = (
#         app.config.get('EDITABLE_SAMPLE_TEXT_SCRAPE_URLS') and
#         True or False)
# 
#     return (is_sample_text_configured
#             and random_sample_text()
#             or app.config['EDITABLE_PLACEHOLDER_TEXT'])


# Path: flask_editablesite/editable/views.py
from datetime import datetime
from glob import glob
from operator import itemgetter
from sqlalchemy.exc import IntegrityError
from flask import current_app as app
from flask import (abort, Blueprint, flash, url_for, redirect, request,
                   session, Response)
from flask_login import login_required, current_user
from flask_transfer import Transfer
from werkzeug import secure_filename
from flask_wtf import Form
from flask_editablesite.extensions import db
from flask_editablesite.editable.forms import (
    TextEditForm, LongTextEditForm, DateEditForm, TimeEditForm,
    ImageEditForm, ReorderForm)
from flask_editablesite.editable.utils import get_model_class
from flask_editablesite.editable.sample_images import (
    placeholder_or_random_sample_image,)
from flask_editablesite.editable.sample_text import (
    placeholder_or_random_sample_text,)
from flask_editablesite.utils import flash_errors
import os

        model_classpath = v['classpath']
    except KeyError:
        raise ValueError((
            'No class path defined in app config\'s '
            'EDITABLE_MODELS for model name "{0}"').format(
                model_name))

    try:
        title_field_name = v['title_field']
    except KeyError:
        raise ValueError((
            'No title field defined in app config\'s '
            'EDITABLE_MODELS for model name "{0}"').format(
                model_name))

    try:
        weight_field_name = v['weight_field']
    except KeyError:
        weight_field_name = None

    model_class = get_model_class(model_classpath, model_name)

    form = Form()

    if form.validate_on_submit():
        model_name_friendly = model_name.replace('_', ' ').title()
        model = model_class.new_item()

        if ('image_fields' in v) and v['image_fields']:
            for k in v['image_fields']:

                setattr(model, k, placeholder_or_random_sample_image())