diff --git a/app/forms.py b/app/forms.py index fac45fc..11398bf 100755 --- a/app/forms.py +++ b/app/forms.py @@ -14,6 +14,7 @@ class AuthorForm(NoCsrfForm): class UserForm(FlaskForm): title = StringField('title', validators=[InputRequired()]) author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) + tag = StringField('tag', validators=[InputRequired()]) file = FileField() class UserForm_Edit(FlaskForm): diff --git a/app/models.py b/app/models.py index 76e354c..3b654f2 100755 --- a/app/models.py +++ b/app/models.py @@ -9,12 +9,16 @@ class Book(db.Model): cover = db.Column(db.String(255)) fileformat = db.Column(db.String(255)) author = db.relationship('Author') + tag = db.Column(db.String(255)) + + def __init__(self, title, file, cover, fileformat, tag): - def __init__(self, title, file, cover, fileformat): self.title = title self.file = file self.cover = cover self.fileformat = fileformat + self.tag = tag + def __repr__(self): return '' % self.title @@ -40,7 +44,8 @@ class BookSchema(Schema): file = fields.Str() cover = fields.Str() fileformat = fields.Str() + tag = fields.Str() def must_not_be_blank(data): if not data: - raise ValidationError('Data not provided.') + raise ValidationError('You forgot to write stuff.') diff --git a/app/templates/add_book.html b/app/templates/add_book.html index 0dc2ba8..375001b 100755 --- a/app/templates/add_book.html +++ b/app/templates/add_book.html @@ -35,6 +35,7 @@ </table> </div> <br> +<div class="form-group">{{ form.tag.label }} {{ form.tag(size=20, class="form-control") }}</div> {{ form.file }} <button type="submit" class="btn btn-primary">Upload</button> </form> diff --git a/app/templates/show_books.html b/app/templates/show_books.html index c967889..4113728 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -20,18 +20,27 @@ <th>Cover</th> <th>Title</th> <th>Author</th> +<<<<<<< HEAD <th>Filetype</th> +======= + <th>Tag</th> +>>>>>>> 18f7acebcd760ab12a86ada4423cbefcbdaafdf5 </tr> {% for book in books %} <tr> <td><img src="../uploads/cover/{{ book.cover }}" width="80"></td> <td><a href="books/{{ book.id }}">{{ book.title }}</a></td> +<<<<<<< HEAD <td> {% for author in book.author %} <li> {{ author.author_name }}</li> {% endfor %}</td> <td>{{ book.fileformat }}</td> +======= + <td>{{ book.author }}</td> + <td>{{ book.tag}}</td> +>>>>>>> 18f7acebcd760ab12a86ada4423cbefcbdaafdf5 </tr> {% endfor %} </table> diff --git a/app/uploads/The_Moral_Of_The_Xerox.pdf b/app/uploads/The_Moral_Of_The_Xerox.pdf new file mode 100644 index 0000000..e9c246e Binary files /dev/null and b/app/uploads/The_Moral_Of_The_Xerox.pdf differ diff --git a/app/views.py b/app/views.py index d4359af..4ac30f8 100755 --- a/app/views.py +++ b/app/views.py @@ -127,10 +127,11 @@ def add_book(): file.save(fullpath) cover = get_cover(fullpath, name) title = user_form.title.data # You could also have used request.form['name'] - author = user_form.author.data # You could also have used request.form['email'] + author = user_form.author.data # You could also have used + tag = user_form.tag.data print(author) print(len(author)) - book = Book(title, filename, cover, file_extension) + book = Book(title, filename, cover, file_extension, tag) db.session.add(book) db.session.commit() book = Book.query.filter_by(title=title).first() @@ -138,7 +139,6 @@ def add_book(): this_author = Author(this_author.get('author_name')) book.author.append(this_author) db.session.commit() - #author = "hallo" # save user to database