more covers

master
Alex 6 years ago
parent d15ccb062e
commit d0c8cb968e

@ -1,5 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import StringField, FileField
from wtforms import StringField, FileField, validators
from wtforms.validators import InputRequired, DataRequired
from wtforms import FieldList
from wtforms import Form as NoCsrfForm
@ -15,6 +15,7 @@ class UploadForm(FlaskForm):
title = StringField('title', validators=[InputRequired()])
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
category = StringField('category', validators=[InputRequired()])
year_published = StringField('year published', [validators.Length(min=4, max=4)])
file = FileField()
upload = SubmitField(label='Upload')
wish = SubmitField(label='''I don't have the file, but wish I did.''')

@ -20,6 +20,8 @@ class Book(db.Model):
cover = db.Column(db.String(255))
fileformat = db.Column(db.String(255))
category = db.Column(db.String(255))
year_published = db.Column(db.Numeric(4,0))
html = db.Column(db.String(255))
authors = db.relationship('Author', secondary=authors,cascade="delete", lazy='subquery',
backref=db.backref('books', lazy=True),passive_deletes=True)
stacks = db.relationship('Stack', secondary=stacks, lazy='subquery',
@ -27,12 +29,13 @@ class Book(db.Model):
scapeX = db.Column(db.Numeric(10,2))
scapeY = db.Column(db.Numeric(10,2))
def __init__(self, title, file, cover, fileformat, category):
def __init__(self, title, file, cover, fileformat, category, year_published):
self.title = title
self.file = file
self.cover = cover
self.fileformat = fileformat
self.category = category
self.year_published = year_published
self.scapeX = 0
self.scapeY = 0

@ -36,6 +36,9 @@
</div>
<br>
<div class="form-group">{{ form.category.label }} {{ form.category(size=20, class="form-control") }}</div>
<br>
<div class="form-group">{{ form.year_published.label }} {{ form.year_published(size=4, class="form-control") }}</div>
<br>
{{ form.file }}
{{ form.upload }}
{{ form.wish }}

@ -42,7 +42,7 @@
$( ".no_cover" ).each(function() {
var string = $(this).children("p").html()
var string = $(this).attr('id')
var randomColor = colorHash(string).rgb
$(this).css({

@ -36,7 +36,7 @@
</tr>
{% for book in books %}
<tr>
<td><img src="/uploads/cover/{{ book.cover }}" width="80"></td>
<td><img class="no_cover" id="{{ book.title }}" src="../../uploads/cover/{{ book.cover }}" width="80" onerror="if (this.src != '../../static/img/default_cover.png') this.src = '../../static/img/default_cover.png';"></td>
<td><a href="{{url_for('show_book_by_id', id=book.id)}}">{{ book.title }}</a></td>
<td> {% for author in book.authors %}
@ -66,7 +66,7 @@
</tr>
{% for book in books_all %}
<tr>
<td><img src="/uploads/cover/{{ book.cover }}" width="80"></td>
<td><img class="no_cover" id="{{ book.title }}" src="../../uploads/cover/{{ book.cover }}" width="40" onerror="if (this.src != '../../static/img/default_cover.png') this.src = '../../static/img/default_cover.png';"></td>
<td><a href="{{url_for('show_book_by_id', id=book.id)}}">{{ book.title }}</a></td>
<td> {% for author in book.authors %}
@ -87,5 +87,3 @@
</div>
{% endblock %}

@ -20,10 +20,8 @@
{% for book in books|sort(attribute='title', reverse = False) %}
<div class = "drag" id = "{{ book.id }}" style="position: absolute;width:40px;height:auto; top:{{ book.scapeY }}px; left:{{ book.scapeX }}px;">
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" style="width:100%;height:auto;">
<p >{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" style="width:100%;height:auto;" onerror="if (this.src != '../static/img/default_cover.png') this.src = '../static/img/default_cover.png';">
<p style="font-size:7px;"><a href="books/{{ book.id }}">{{ book.title }}</a></p>
</div>
{% endfor %}
@ -40,7 +38,7 @@
$( ".no_cover" ).each(function() {
var string = $(this).children("p").html()
var string = $(this).attr('id');
var randomColor = colorHash(string).rgb
$(this).css({

@ -4,16 +4,16 @@
<div class="container">
<h1 class="header">{{ book.title }}</h1>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="150">
<p hidden="True">{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="200">
</object>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../static/img/default_cover.png') this.src = '../static/img/default_cover.png';">
<p>Author(s): <ul>{% for author in book.authors %}
<li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
{% endfor %}</ul></p>
<p>{{ book.category }}</p>
<p>{{ book.year_published }}</p>
<p>Stack(s): <ul>{% for stack in book.stacks %}
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a>

@ -35,10 +35,13 @@
{% for book in books|sort(attribute='title', reverse = False) %}
<tr>
<td>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65">
<p hidden="True">{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="40" onerror="if (this.src != '../static/img/default_cover.png') this.src = '../static/img/default_cover.png';">
<!-- <object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65">
<p hidden="True"></p>
</object>-->
</td>
<td class="title_col"><a href="books/{{ book.id }}">{{ book.title }}</a></td>

@ -18,10 +18,7 @@
{% for book in books|sort(attribute='title', reverse = False) %}
<a href="books/{{ book.id }}">
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="105">
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
{{ book.title }}</a>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="140" onerror="if (this.src != '../static/img/default_cover.png') this.src = '../static/img/default_cover.png';"><!--{{ book.title }}--></a>
{% endfor %}

@ -17,7 +17,7 @@ import os
from werkzeug.utils import secure_filename
# import sqlite3
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'chm', 'mobi'])
author_schema = AuthorSchema()
authors_schema = AuthorSchema(many=True)
@ -153,7 +153,7 @@ def edit_book_by_id(id):
@app.route('/add-book', methods=['POST', 'GET'])
def add_book():
upload_form = UploadForm()
if request.method == 'POST':
if upload_form.validate_on_submit():
@ -170,16 +170,21 @@ def add_book():
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
name, file_extension = os.path.splitext(filename)
allbooks = db.session.query(Book).all()
id = len(allbooks)+1
new_filename = str(id) +"_"+ filename
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], new_filename)
name, file_extension = os.path.splitext(new_filename)
file.save(fullpath)
cover = get_cover(fullpath, name)
title = upload_form.title.data # You could also have used request.form['name']
authors = upload_form.author.data # You could also have used
category = upload_form.category.data
year_published = upload_form.year_published.data
#print(author)
#print(len(author))
book = Book(title, filename, cover, file_extension, category)
book = Book(title, filename, cover, file_extension, category, year_published)
db.session.add(book)
for author in authors:
author_name = author.get("author_name")
@ -207,9 +212,11 @@ def add_book():
title = upload_form.title.data # You could also have used request.form['name']
authors = upload_form.author.data # You could also have used
category = upload_form.category.data
year_published = upload_form.year_published.data
#print(author)
#print(len(author))
book = Book(title, filename, cover, file_extension, category)
book = Book(title, filename, cover, file_extension, category,year_published)
db.session.add(book)
for author in authors:
author_name = author.get("author_name")

@ -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['Shelf'], row['Stack'])
book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Shelf'], None)
db.session.add(book)
authors = row['Author'].split(',')

Loading…
Cancel
Save