From 923da074a6fa4f05ccda465928f36fedaa4cec40 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 23 May 2018 11:16:25 +0200 Subject: [PATCH] Added tag --- app/__pycache__/__init__.cpython-36.pyc | Bin 831 -> 805 bytes app/forms.py | 1 + app/models.py | 7 +++++-- app/templates/add_book.html | 2 ++ app/templates/show_books.html | 2 ++ app/views.py | 3 ++- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/__pycache__/__init__.cpython-36.pyc b/app/__pycache__/__init__.cpython-36.pyc index d71f35dc070e14e161fba24cf5349f12d53ecb66..419c685eb921a428a2d36f028ee0bc637f1232af 100644 GIT binary patch delta 57 zcmdnbwv>(Cn3tDJ%aL&-`*J46Ta(u_Nyv*aFfbH>h+iuD8Tq-X`iVK2$*KAk1*J*4 KIhje5nC$_fA`jUB delta 84 zcmZ3=wx5mNn3tF9n?1uu_T@~BQIpp*Nmz<9FfbH>h+lU4p~b01#rlaksTD=}nJGE? mF8SqoIr)hx#rkPEiN)Ev#f3SUC8@f(iNz(UMU$T~*#iI=`WvYL diff --git a/app/forms.py b/app/forms.py index a4b251f..c9ccbb4 100755 --- a/app/forms.py +++ b/app/forms.py @@ -5,4 +5,5 @@ from wtforms.validators import InputRequired class UserForm(FlaskForm): title = StringField('title', validators=[InputRequired()]) author = StringField('author', validators=[InputRequired()]) + tag = StringField('tag', validators=[InputRequired()]) file = FileField() diff --git a/app/models.py b/app/models.py index ebe947a..466bc0a 100755 --- a/app/models.py +++ b/app/models.py @@ -6,12 +6,14 @@ class Book(db.Model): title = db.Column(db.String(255)) author = db.Column(db.String(255)) file = db.Column(db.String(255)) + tag = db.Column(db.String(255)) - def __init__(self, title, author, file): + def __init__(self, title, author, file, tag): self.title = title self.author = author self.file = file + self.tag = tag def __repr__(self): return '' % self.title @@ -22,7 +24,8 @@ class BookSchema(Schema): title = fields.Str() author = fields.Str() file = 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 a27cccd..d5f4654 100755 --- a/app/templates/add_book.html +++ b/app/templates/add_book.html @@ -18,6 +18,8 @@ {{ form.csrf_token }} <div class="form-group">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</div> <div class="form-group">{{ form.author.label }} {{ form.author(size=20, class="form-control") }}</div> + <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 1e592ee..a49fd53 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -19,11 +19,13 @@ <tr> <th>Title</th> <th>Author</th> + <th>Tag</th> </tr> {% for book in books %} <tr> <td><a href="books/{{ book.id }}">{{ book.title }}</a></td> <td>{{ book.author }}</td> + <td>{{ book.tag}}</td> </tr> {% endfor %} </table> diff --git a/app/views.py b/app/views.py index 7a100e9..1233276 100755 --- a/app/views.py +++ b/app/views.py @@ -82,8 +82,9 @@ def add_book(): 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'] + tag = user_form.tag.data # save user to database - book = Book(title, author, filename) + book = Book(title, author, filename, tag) db.session.add(book) db.session.commit() flash("%s added to the library" % (title))