Added tag
This commit is contained in:
parent
1b63206a80
commit
923da074a6
Binary file not shown.
@ -5,4 +5,5 @@ from wtforms.validators import InputRequired
|
|||||||
class UserForm(FlaskForm):
|
class UserForm(FlaskForm):
|
||||||
title = StringField('title', validators=[InputRequired()])
|
title = StringField('title', validators=[InputRequired()])
|
||||||
author = StringField('author', validators=[InputRequired()])
|
author = StringField('author', validators=[InputRequired()])
|
||||||
|
tag = StringField('tag', validators=[InputRequired()])
|
||||||
file = FileField()
|
file = FileField()
|
||||||
|
@ -6,12 +6,14 @@ class Book(db.Model):
|
|||||||
title = db.Column(db.String(255))
|
title = db.Column(db.String(255))
|
||||||
author = db.Column(db.String(255))
|
author = db.Column(db.String(255))
|
||||||
file = 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.title = title
|
||||||
self.author = author
|
self.author = author
|
||||||
self.file = file
|
self.file = file
|
||||||
|
self.tag = tag
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Title %r>' % self.title
|
return '<Title %r>' % self.title
|
||||||
@ -22,7 +24,8 @@ class BookSchema(Schema):
|
|||||||
title = fields.Str()
|
title = fields.Str()
|
||||||
author = fields.Str()
|
author = fields.Str()
|
||||||
file = fields.Str()
|
file = fields.Str()
|
||||||
|
tag = fields.Str()
|
||||||
|
|
||||||
def must_not_be_blank(data):
|
def must_not_be_blank(data):
|
||||||
if not data:
|
if not data:
|
||||||
raise ValidationError('Data not provided.')
|
raise ValidationError('You forgot to write stuff.')
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
{{ form.csrf_token }}
|
{{ form.csrf_token }}
|
||||||
<div class="form-group">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</div>
|
<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.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 }}
|
{{ form.file }}
|
||||||
<button type="submit" class="btn btn-primary">Upload</button>
|
<button type="submit" class="btn btn-primary">Upload</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -19,11 +19,13 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Title</th>
|
<th>Title</th>
|
||||||
<th>Author</th>
|
<th>Author</th>
|
||||||
|
<th>Tag</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="books/{{ book.id }}">{{ book.title }}</a></td>
|
<td><a href="books/{{ book.id }}">{{ book.title }}</a></td>
|
||||||
<td>{{ book.author }}</td>
|
<td>{{ book.author }}</td>
|
||||||
|
<td>{{ book.tag}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -82,8 +82,9 @@ def add_book():
|
|||||||
|
|
||||||
title = user_form.title.data # You could also have used request.form['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 request.form['email']
|
||||||
|
tag = user_form.tag.data
|
||||||
# save user to database
|
# save user to database
|
||||||
book = Book(title, author, filename)
|
book = Book(title, author, filename, tag)
|
||||||
db.session.add(book)
|
db.session.add(book)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("%s added to the library" % (title))
|
flash("%s added to the library" % (title))
|
||||||
|
Loading…
Reference in New Issue
Block a user