diff --git a/app/forms.py b/app/forms.py
index 211872c..607a15b 100755
--- a/app/forms.py
+++ b/app/forms.py
@@ -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.''')
diff --git a/app/models.py b/app/models.py
index ea199b3..c0235a7 100755
--- a/app/models.py
+++ b/app/models.py
@@ -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
diff --git a/app/templates/add_book.html b/app/templates/add_book.html
index 2121566..c01dc37 100755
--- a/app/templates/add_book.html
+++ b/app/templates/add_book.html
@@ -36,6 +36,9 @@
{{ form.category.label }} {{ form.category(size=20, class="form-control") }}
+
+{{ form.year_published.label }} {{ form.year_published(size=4, class="form-control") }}
+
{{ form.file }}
{{ form.upload }}
{{ form.wish }}
diff --git a/app/templates/base.html b/app/templates/base.html
index ea87afe..b3eab28 100755
--- a/app/templates/base.html
+++ b/app/templates/base.html
@@ -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({
diff --git a/app/templates/results.html b/app/templates/results.html
index 9262d35..dcbe3cf 100644
--- a/app/templates/results.html
+++ b/app/templates/results.html
@@ -36,7 +36,7 @@
{% for book in books %}
- |
+ |
{{ book.title }} |
{% for author in book.authors %}
@@ -66,7 +66,7 @@
|
{% for book in books_all %}
- |
+ |
{{ book.title }} |
{% for author in book.authors %}
@@ -87,5 +87,3 @@
{% endblock %}
-
-
diff --git a/app/templates/scape.html b/app/templates/scape.html
index 75745f9..7e222f3 100644
--- a/app/templates/scape.html
+++ b/app/templates/scape.html
@@ -20,10 +20,8 @@
{% for book in books|sort(attribute='title', reverse = False) %}
{% 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({
diff --git a/app/templates/show_book_detail.html b/app/templates/show_book_detail.html
index 7a1cce5..4963946 100755
--- a/app/templates/show_book_detail.html
+++ b/app/templates/show_book_detail.html
@@ -4,16 +4,16 @@
-
+
Author(s):
+ {{ book.category }}
+ {{ book.year_published }}
+
Stack(s): {% for stack in book.stacks %}
- {{ stack.stack_name }}
diff --git a/app/templates/show_books.html b/app/templates/show_books.html
index 7cfe4b1..f6c5667 100755
--- a/app/templates/show_books.html
+++ b/app/templates/show_books.html
@@ -35,10 +35,13 @@
{% for book in books|sort(attribute='title', reverse = False) %}
-
+
+
+
+
|
{{ book.title }} |
diff --git a/app/templates/show_books_grid.html b/app/templates/show_books_grid.html
index aaecc4f..b41bab4 100644
--- a/app/templates/show_books_grid.html
+++ b/app/templates/show_books_grid.html
@@ -18,10 +18,7 @@
{% for book in books|sort(attribute='title', reverse = False) %}
-
- {{ book.title }}
+
{% endfor %}
diff --git a/app/views.py b/app/views.py
index cdbd7e1..c6cdc91 100755
--- a/app/views.py
+++ b/app/views.py
@@ -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")
diff --git a/import_csv.py b/import_csv.py
index 23d3cc9..b0a178e 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['Shelf'], row['Stack'])
+ book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Shelf'], None)
db.session.add(book)
authors = row['Author'].split(',')
|