added message option into book database, upload form, edit form
This commit is contained in:
parent
0696c94a14
commit
2bc81e7d59
@ -19,6 +19,7 @@ class UploadForm(FlaskForm):
|
|||||||
file = FileField()
|
file = FileField()
|
||||||
upload = SubmitField(label='Upload')
|
upload = SubmitField(label='Upload')
|
||||||
wish = SubmitField(label='''I don't have the file, but wish I did.''')
|
wish = SubmitField(label='''I don't have the file, but wish I did.''')
|
||||||
|
message = StringField('message', default=None)
|
||||||
|
|
||||||
class EditForm(FlaskForm):
|
class EditForm(FlaskForm):
|
||||||
title = StringField('title', validators=[InputRequired()])
|
title = StringField('title', validators=[InputRequired()])
|
||||||
@ -26,6 +27,7 @@ class EditForm(FlaskForm):
|
|||||||
category = StringField('category', validators=[InputRequired()])
|
category = StringField('category', validators=[InputRequired()])
|
||||||
year_published = StringField('year published', [validators.Length(max=4)],default=None)
|
year_published = StringField('year published', [validators.Length(max=4)],default=None)
|
||||||
file = FileField()
|
file = FileField()
|
||||||
|
message = StringField('message')
|
||||||
|
|
||||||
class ChatForm(FlaskForm):
|
class ChatForm(FlaskForm):
|
||||||
message = StringField('message', validators=[InputRequired()])
|
message = StringField('message', validators=[InputRequired()])
|
||||||
|
@ -33,8 +33,10 @@ class Book(db.Model):
|
|||||||
backref=db.backref('books', lazy=True))
|
backref=db.backref('books', lazy=True))
|
||||||
scapeX = db.Column(db.Numeric(10,2))
|
scapeX = db.Column(db.Numeric(10,2))
|
||||||
scapeY = 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.title = title
|
||||||
self.file = file
|
self.file = file
|
||||||
self.cover = cover
|
self.cover = cover
|
||||||
@ -43,6 +45,7 @@ class Book(db.Model):
|
|||||||
self.year_published = year_published
|
self.year_published = year_published
|
||||||
self.scapeX = 0
|
self.scapeX = 0
|
||||||
self.scapeY = 0
|
self.scapeY = 0
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -82,7 +82,6 @@ border-spacing:0; /* Removes the cell spacing via CSS */
|
|||||||
.library_table th{
|
.library_table th{
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-color: #fafafa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
th.headerSortUp{
|
th.headerSortUp{
|
||||||
@ -352,7 +351,7 @@ box-sizing: border-box;
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
grid-gap: 2px;
|
grid-gap: 2px;
|
||||||
align-items: center;
|
align-items: top;
|
||||||
justify-items: center;
|
justify-items: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,3 +373,41 @@ box-sizing: border-box;
|
|||||||
.gridbox:hover{
|
.gridbox:hover{
|
||||||
opacity: 0.5;
|
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;
|
||||||
|
}
|
||||||
|
@ -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 <span> 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 <span> (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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -41,6 +41,10 @@
|
|||||||
<br>
|
<br>
|
||||||
Year published: {{ form.year_published(size=8, class="form-control") }}
|
Year published: {{ form.year_published(size=8, class="form-control") }}
|
||||||
<br>
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="width: 50%">
|
||||||
|
Add a message for future readers: {{ form.message(size=150, class="form-control") }}
|
||||||
|
<br></div>
|
||||||
<br>
|
<br>
|
||||||
{{ form.file }}
|
{{ form.file }}
|
||||||
{{ form.upload }}
|
{{ form.upload }}
|
||||||
|
@ -31,19 +31,22 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</div><br>
|
</div><br>
|
||||||
<div class="form-group">
|
<div class="form-group" style="padding-bottom: 10px;">
|
||||||
{{ form.category.label }} {{ form.category(size=20,
|
Category: {{ form.category(size=20,
|
||||||
class="form-control") }}
|
class="form-control") }}
|
||||||
</div><br>
|
|
||||||
<div class="form-group">
|
|
||||||
{{ form.year_published.label }} {{ form.year_published(size=4, class="form-control") }}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group" style="padding-bottom: 10px;">
|
||||||
|
Year published: {{ form.year_published(size=8, class="form-control") }}
|
||||||
|
</div>
|
||||||
|
<div class="form-group" style="padding-bottom: 10px;">
|
||||||
Current file: {{ book.file }}
|
Current file: {{ book.file }}
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group" style="padding-bottom: 10px;">
|
||||||
|
|
||||||
Upload new file: {{form.file}}
|
Upload new file: {{form.file}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group" style="padding-bottom: 10px;">
|
||||||
|
|
||||||
|
If uploading, write a new message: {{form.message(size=150, class="form-control") }}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
@ -16,17 +16,26 @@
|
|||||||
|
|
||||||
<p>Included in stack(s): <ul>{% for stack in book.stacks %}
|
<p>Included in stack(s): <ul>{% for stack in book.stacks %}
|
||||||
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a>
|
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a>
|
||||||
<p style="font-size: 10px;"><a href='{{url_for('remove_from_stack', stackid=stack.id, bookid=book.id)}}'> Remove from stack</a></p>
|
<p style="font-size: 10px;"><a href="{{url_for('remove_from_stack', stackid=stack.id, bookid=book.id)}}"> Remove from stack</a></p>
|
||||||
|
|
||||||
|
|
||||||
{% endfor %}</ul></p>
|
{% endfor %}</ul></p>
|
||||||
|
|
||||||
<a href="../uploads/{{ book.file }}">download {{ book.fileformat }}</a>
|
<button id="myBtn" style= "width: 180px; font-size: 10pt;"><a> Download this {{ book.fileformat }}</a></button>
|
||||||
|
<button style= "font-size: 10pt;"> <a href="{{ url_for('edit_book_by_id', id=book.id )}}">edit</a></button>
|
||||||
|
<button style= "font-size: 10pt;"> <a href="{{ url_for('remove_book_by_id', id=book.id)}}">delete</a></button>
|
||||||
|
|
||||||
|
<div id="myModal" class="modal">
|
||||||
|
<div class="modal-content">
|
||||||
|
<span class="close">×</span>
|
||||||
|
<h3>A message from the uploading librarian:</h3>
|
||||||
|
<p style="font-style: italic;">"{{book.message or 'Happy reading.'}}" </p>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<h4><a href="../uploads/{{ book.file }}"> >>>> Link to file <<<<</h4>
|
||||||
<a href="{{ url_for('edit_book_by_id', id=book.id )}}">edit</a>
|
</div></div>
|
||||||
<br>
|
|
||||||
<a href="{{ url_for('remove_book_by_id', id=book.id)}}">delete</a>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
14
app/views.py
14
app/views.py
@ -129,19 +129,10 @@ def remove_book_by_id(id):
|
|||||||
flash("%s deleted from library" % (title))
|
flash("%s deleted from library" % (title))
|
||||||
return redirect(url_for('show_books'))
|
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/<int:id>/edit', methods=['POST', 'GET'])
|
@app.route('/books/<int:id>/edit', methods=['POST', 'GET'])
|
||||||
def edit_book_by_id(id):
|
def edit_book_by_id(id):
|
||||||
book_to_edit = Book.query.filter_by(id=id).first()
|
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 request.method == 'POST':
|
||||||
if user_form.validate_on_submit():
|
if user_form.validate_on_submit():
|
||||||
@ -204,6 +195,7 @@ def add_book():
|
|||||||
title = upload_form.title.data
|
title = upload_form.title.data
|
||||||
authors = upload_form.author.data
|
authors = upload_form.author.data
|
||||||
category = upload_form.category.data
|
category = upload_form.category.data
|
||||||
|
message = upload_form.message.data
|
||||||
year_published = upload_form.year_published.data
|
year_published = upload_form.year_published.data
|
||||||
if year_published=="":
|
if year_published=="":
|
||||||
year_published = None
|
year_published = None
|
||||||
@ -248,7 +240,7 @@ def add_book():
|
|||||||
html.write_pdf(target='app/uploads/potential.pdf');
|
html.write_pdf(target='app/uploads/potential.pdf');
|
||||||
print ('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)
|
db.session.add(book)
|
||||||
for author in authors:
|
for author in authors:
|
||||||
author_name = author.get("author_name")
|
author_name = author.get("author_name")
|
||||||
|
@ -20,7 +20,7 @@ with open(args.csv) as f:
|
|||||||
print ('get_cover', fullpath, name)
|
print ('get_cover', fullpath, name)
|
||||||
cover = 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)
|
db.session.add(book)
|
||||||
authors = row['Author'].split(',')
|
authors = row['Author'].split(',')
|
||||||
|
Loading…
Reference in New Issue
Block a user