From 2bc81e7d59c8ef0834a75175c004bd7f5604ff7c Mon Sep 17 00:00:00 2001 From: nberting Date: Sat, 9 Jun 2018 22:05:47 +0200 Subject: [PATCH] added message option into book database, upload form, edit form --- app/forms.py | 2 ++ app/models.py | 5 +++- app/static/css/style.css | 41 +++++++++++++++++++++++++++-- app/static/js/app.js | 26 ++++++++++++++++++ app/templates/add_book.html | 4 +++ app/templates/edit_book_detail.html | 19 +++++++------ app/templates/show_book_detail.html | 21 ++++++++++----- app/views.py | 14 +++------- import_csv.py | 2 +- 9 files changed, 105 insertions(+), 29 deletions(-) diff --git a/app/forms.py b/app/forms.py index f1704ab..6089ca9 100755 --- a/app/forms.py +++ b/app/forms.py @@ -19,6 +19,7 @@ class UploadForm(FlaskForm): file = FileField() upload = SubmitField(label='Upload') wish = SubmitField(label='''I don't have the file, but wish I did.''') + message = StringField('message', default=None) class EditForm(FlaskForm): title = StringField('title', validators=[InputRequired()]) @@ -26,6 +27,7 @@ class EditForm(FlaskForm): category = StringField('category', validators=[InputRequired()]) year_published = StringField('year published', [validators.Length(max=4)],default=None) file = FileField() + message = StringField('message') class ChatForm(FlaskForm): message = StringField('message', validators=[InputRequired()]) diff --git a/app/models.py b/app/models.py index dd80db8..2f6f119 100755 --- a/app/models.py +++ b/app/models.py @@ -33,8 +33,10 @@ class Book(db.Model): backref=db.backref('books', lazy=True)) scapeX = db.Column(db.Numeric(10,2)) scapeY = db.Column(db.Numeric(10,2)) + message = db.Column(db.String(1000)) + - def __init__(self, title, file, cover, fileformat, category, year_published): + def __init__(self, title, file, cover, fileformat, category, year_published, message): self.title = title self.file = file self.cover = cover @@ -43,6 +45,7 @@ class Book(db.Model): self.year_published = year_published self.scapeX = 0 self.scapeY = 0 + self.message = message def __repr__(self): diff --git a/app/static/css/style.css b/app/static/css/style.css index 1753ba4..2ea3389 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -82,7 +82,6 @@ border-spacing:0; /* Removes the cell spacing via CSS */ .library_table th{ font-size: 20px; cursor: pointer; -background-color: #fafafa; } th.headerSortUp{ @@ -352,7 +351,7 @@ box-sizing: border-box; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-gap: 2px; - align-items: center; + align-items: top; justify-items: center; } } @@ -374,3 +373,41 @@ box-sizing: border-box; .gridbox:hover{ opacity: 0.5; } + +/* The Modal (background) */ +.modal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 1; /* Sit on top */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ +} + +/* Modal Content/Box */ +.modal-content { + background-color: #fefefe; + margin: 15% auto; /* 15% from the top and centered */ + padding: 20px; + border: 1px solid #888; + width: 40%; /* Could be more or less, depending on screen size */ +} + +/* The Close Button */ +.close { + color: red; + float: right; + font-size: 28px; + font-weight: bold; +} + +.close:hover, +.close:focus { + color: black; + text-decoration: none; + cursor: pointer; +} diff --git a/app/static/js/app.js b/app/static/js/app.js index 460c9ee..55d72bb 100755 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -253,3 +253,29 @@ $('#search').on("input", function() { }); }); + +// Get the modal +var modal = document.getElementById('myModal'); + +// Get the button that opens the modal +var btn = document.getElementById("myBtn"); + +// Get the element that closes the modal +var span = document.getElementsByClassName("close")[0]; + +// When the user clicks on the button, open the modal +btn.onclick = function() { + modal.style.display = "block"; +} + +// When the user clicks on (x), close the modal +span.onclick = function() { + modal.style.display = "none"; +} + +// When the user clicks anywhere outside of the modal, close it +window.onclick = function(event) { + if (event.target == modal) { + modal.style.display = "none"; + } +} diff --git a/app/templates/add_book.html b/app/templates/add_book.html index b9dff17..35c5c6b 100755 --- a/app/templates/add_book.html +++ b/app/templates/add_book.html @@ -41,6 +41,10 @@
Year published: {{ form.year_published(size=8, class="form-control") }}
+
+
+ Add a message for future readers: {{ form.message(size=150, class="form-control") }} +

{{ form.file }} {{ form.upload }} diff --git a/app/templates/edit_book_detail.html b/app/templates/edit_book_detail.html index 4299e95..2fa5268 100755 --- a/app/templates/edit_book_detail.html +++ b/app/templates/edit_book_detail.html @@ -31,19 +31,22 @@ {% endfor %}
-
- {{ form.category.label }} {{ form.category(size=20, +
+ Category: {{ form.category(size=20, class="form-control") }} -

-
- {{ form.year_published.label }} {{ form.year_published(size=4, class="form-control") }} +
+
+ Year published: {{ form.year_published(size=8, class="form-control") }}
-
+
Current file: {{ book.file }}
-
- +
Upload new file: {{form.file}} +
+
+ + If uploading, write a new message: {{form.message(size=150, class="form-control") }}

diff --git a/app/templates/show_book_detail.html b/app/templates/show_book_detail.html index a8b29d3..79252d3 100755 --- a/app/templates/show_book_detail.html +++ b/app/templates/show_book_detail.html @@ -16,17 +16,26 @@

Included in stack(s):

- download {{ book.fileformat }} -
-
- edit + + + + +
+ {% endblock %} + + diff --git a/app/views.py b/app/views.py index 1cf4a11..199b264 100755 --- a/app/views.py +++ b/app/views.py @@ -129,19 +129,10 @@ def remove_book_by_id(id): flash("%s deleted from library" % (title)) return redirect(url_for('show_books')) -@app.route('/potential') -def htmlpdf(): - paragraphs= ['test title'] - template = 'app/templates/potential_pdf.html' - html_string = render_template('potential_pdf.html', paragraphs=paragraphs) - html = HTML(string=html_string) - html.write_pdf(target='app/uploads/potential2.pdf'); - return render_template('potential_pdf.html', paragraphs=paragraphs) - @app.route('/books//edit', methods=['POST', 'GET']) def edit_book_by_id(id): book_to_edit = Book.query.filter_by(id=id).first() - user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published) + user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published, message= book_to_edit.message) if request.method == 'POST': if user_form.validate_on_submit(): @@ -204,6 +195,7 @@ def add_book(): title = upload_form.title.data authors = upload_form.author.data category = upload_form.category.data + message = upload_form.message.data year_published = upload_form.year_published.data if year_published=="": year_published = None @@ -248,7 +240,7 @@ def add_book(): html.write_pdf(target='app/uploads/potential.pdf'); print ('potential_pdf') - book = Book(title, filename, cover, file_extension, category,year_published) + book = Book(title, filename, cover, file_extension, category, year_published, message) db.session.add(book) for author in authors: author_name = author.get("author_name") diff --git a/import_csv.py b/import_csv.py index b43447d..bca2b12 100644 --- a/import_csv.py +++ b/import_csv.py @@ -20,7 +20,7 @@ with open(args.csv) as f: print ('get_cover', fullpath, name) cover = get_cover(fullpath, name) - book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Category'], None) + book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Category'], None, '') db.session.add(book) authors = row['Author'].split(',')