diff --git a/app/__init__.py b/app/__init__.py index e653e29..ea15099 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,6 +7,7 @@ from werkzeug.utils import secure_filename basedir = os.path.abspath(os.path.dirname(__file__)) UPLOAD_FOLDER = os.path.join(basedir, 'uploads') +UPLOAD_FOLDER_COVER = os.path.join(basedir, 'uploads/cover') ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) app = Flask(__name__) diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc index d71f35d..5bdcb03 100644 Binary files a/app/__pycache__/__init__.cpython-36.pyc and b/app/__pycache__/__init__.cpython-36.pyc differ diff --git a/app/__pycache__/forms.cpython-36.pyc b/app/__pycache__/forms.cpython-36.pyc index e1e9300..44774c3 100644 Binary files a/app/__pycache__/forms.cpython-36.pyc and b/app/__pycache__/forms.cpython-36.pyc differ diff --git a/app/__pycache__/models.cpython-36.pyc b/app/__pycache__/models.cpython-36.pyc index 99c9588..a37e942 100644 Binary files a/app/__pycache__/models.cpython-36.pyc and b/app/__pycache__/models.cpython-36.pyc differ diff --git a/app/__pycache__/views.cpython-36.pyc b/app/__pycache__/views.cpython-36.pyc index bd54b0d..5215722 100644 Binary files a/app/__pycache__/views.cpython-36.pyc and b/app/__pycache__/views.cpython-36.pyc differ diff --git a/app/forms.py b/app/forms.py index a4b251f..fac45fc 100755 --- a/app/forms.py +++ b/app/forms.py @@ -1,8 +1,21 @@ from flask_wtf import FlaskForm from wtforms import StringField, FileField -from wtforms.validators import InputRequired +from wtforms.validators import InputRequired, DataRequired +from wtforms import FieldList +from wtforms import Form as NoCsrfForm +from wtforms.fields import StringField, FormField, SubmitField +from app.models import Book, BookSchema, Author + +# - - - Forms - - - +class AuthorForm(NoCsrfForm): + # this forms is never exposed so we can user the non CSRF version + author_name = StringField('Author Name', validators=[DataRequired()]) class UserForm(FlaskForm): title = StringField('title', validators=[InputRequired()]) - author = StringField('author', validators=[InputRequired()]) + author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) file = FileField() + +class UserForm_Edit(FlaskForm): + title = StringField('title', validators=[InputRequired()]) + author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) diff --git a/app/models.py b/app/models.py index ebe947a..76e354c 100755 --- a/app/models.py +++ b/app/models.py @@ -2,26 +2,44 @@ from app import db from marshmallow import Schema, fields, ValidationError, pre_load class Book(db.Model): + __tablename__ = 'books' id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(255)) - author = db.Column(db.String(255)) file = db.Column(db.String(255)) + cover = db.Column(db.String(255)) + fileformat = db.Column(db.String(255)) + author = db.relationship('Author') - - def __init__(self, title, author, file): + def __init__(self, title, file, cover, fileformat): self.title = title - self.author = author self.file = file + self.cover = cover + self.fileformat = fileformat def __repr__(self): return '