more covers

geo
Alex 7 years ago
parent d15ccb062e
commit d0c8cb968e

@ -1,5 +1,5 @@
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, FileField from wtforms import StringField, FileField, validators
from wtforms.validators import InputRequired, DataRequired from wtforms.validators import InputRequired, DataRequired
from wtforms import FieldList from wtforms import FieldList
from wtforms import Form as NoCsrfForm from wtforms import Form as NoCsrfForm
@ -15,6 +15,7 @@ class UploadForm(FlaskForm):
title = StringField('title', validators=[InputRequired()]) title = StringField('title', validators=[InputRequired()])
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
category = StringField('category', validators=[InputRequired()]) category = StringField('category', validators=[InputRequired()])
year_published = StringField('year published', [validators.Length(min=4, max=4)])
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.''')

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

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

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

@ -36,7 +36,7 @@
</tr> </tr>
{% for book in books %} {% for book in books %}
<tr> <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><a href="{{url_for('show_book_by_id', id=book.id)}}">{{ book.title }}</a></td>
<td> {% for author in book.authors %} <td> {% for author in book.authors %}
@ -66,7 +66,7 @@
</tr> </tr>
{% for book in books_all %} {% for book in books_all %}
<tr> <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><a href="{{url_for('show_book_by_id', id=book.id)}}">{{ book.title }}</a></td>
<td> {% for author in book.authors %} <td> {% for author in book.authors %}
@ -87,5 +87,3 @@
</div> </div>
{% endblock %} {% endblock %}

@ -20,10 +20,8 @@
{% for book in books|sort(attribute='title', reverse = False) %} {% 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;"> <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 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';">
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
<p style="font-size:7px;"><a href="books/{{ book.id }}">{{ book.title }}</a></p> <p style="font-size:7px;"><a href="books/{{ book.id }}">{{ book.title }}</a></p>
</div> </div>
{% endfor %} {% endfor %}
@ -40,7 +38,7 @@
$( ".no_cover" ).each(function() { $( ".no_cover" ).each(function() {
var string = $(this).children("p").html() var string = $(this).attr('id');
var randomColor = colorHash(string).rgb var randomColor = colorHash(string).rgb
$(this).css({ $(this).css({

@ -4,16 +4,16 @@
<div class="container"> <div class="container">
<h1 class="header">{{ book.title }}</h1> <h1 class="header">{{ book.title }}</h1>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="150"> <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 hidden="True">{{ book.title }}</p>
<img src="../uploads/cover/{{ book.cover }}" width="200">
</object>
<p>Author(s): <ul>{% for author in book.authors %} <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> <li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
{% endfor %}</ul></p> {% endfor %}</ul></p>
<p>{{ book.category }}</p>
<p>{{ book.year_published }}</p>
<p>Stack(s): <ul>{% for stack in book.stacks %} <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> <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) %} {% for book in books|sort(attribute='title', reverse = False) %}
<tr> <tr>
<td> <td>
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65">
<p hidden="True">{{ book.title }}</p> <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';">
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object> <!-- <object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="65">
<p hidden="True"></p>
</object>-->
</td> </td>
<td class="title_col"><a href="books/{{ book.id }}">{{ book.title }}</a></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) %} {% for book in books|sort(attribute='title', reverse = False) %}
<a href="books/{{ book.id }}"> <a href="books/{{ book.id }}">
<object class="no_cover" data="../static/img/default_cover.png" type="image/png" width="105"> <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>
<img src="../uploads/cover/{{ book.cover }}" width="80">
</object>
{{ book.title }}</a>
{% endfor %} {% endfor %}

@ -17,7 +17,7 @@ import os
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
# import sqlite3 # import sqlite3
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'epub', 'chm', 'mobi'])
author_schema = AuthorSchema() author_schema = AuthorSchema()
authors_schema = AuthorSchema(many=True) authors_schema = AuthorSchema(many=True)
@ -170,16 +170,21 @@ def add_book():
return redirect(request.url) return redirect(request.url)
if file and allowed_file(file.filename): if file and allowed_file(file.filename):
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], filename) allbooks = db.session.query(Book).all()
name, file_extension = os.path.splitext(filename) 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) file.save(fullpath)
cover = get_cover(fullpath, name) cover = get_cover(fullpath, name)
title = upload_form.title.data # You could also have used request.form['name'] title = upload_form.title.data # You could also have used request.form['name']
authors = upload_form.author.data # You could also have used authors = upload_form.author.data # You could also have used
category = upload_form.category.data category = upload_form.category.data
year_published = upload_form.year_published.data
#print(author) #print(author)
#print(len(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) db.session.add(book)
for author in authors: for author in authors:
author_name = author.get("author_name") 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'] title = upload_form.title.data # You could also have used request.form['name']
authors = upload_form.author.data # You could also have used authors = upload_form.author.data # You could also have used
category = upload_form.category.data category = upload_form.category.data
year_published = upload_form.year_published.data
#print(author) #print(author)
#print(len(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) 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['Shelf'], row['Stack']) book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Shelf'], None)
db.session.add(book) db.session.add(book)
authors = row['Author'].split(',') authors = row['Author'].split(',')

Loading…
Cancel
Save