categories

geo
Alex 7 years ago
parent 85d3854f8a
commit ac23e131c5

BIN
.DS_Store vendored

Binary file not shown.

@ -21,8 +21,3 @@ db = SQLAlchemy(app)
app.config.from_object(__name__) app.config.from_object(__name__)
from app import views from app import views
@app.cli.command()
@click.argument('name')
def import_csv(name):
print("hello")

@ -14,9 +14,10 @@ class AuthorForm(NoCsrfForm):
class UserForm(FlaskForm): class UserForm(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)
tag = StringField('tag', validators=[InputRequired()]) category = StringField('category', validators=[InputRequired()])
file = FileField() file = FileField()
class UserForm_Edit(FlaskForm): class UserForm_Edit(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()])

@ -6,6 +6,11 @@ authors = db.Table('books_authors',
db.Column('author_id', db.Integer, db.ForeignKey('authors.id'), primary_key=True) db.Column('author_id', db.Integer, db.ForeignKey('authors.id'), primary_key=True)
) )
tags = db.Table('books_tags',
db.Column('book_id', db.Integer, db.ForeignKey('books.id'), primary_key=True),
db.Column('tag_id', db.Integer, db.ForeignKey('tags.id'), primary_key=True)
)
class Book(db.Model): class Book(db.Model):
__tablename__ = 'books' __tablename__ = 'books'
id = db.Column(db.Integer, primary_key = True) id = db.Column(db.Integer, primary_key = True)
@ -13,17 +18,18 @@ class Book(db.Model):
file = db.Column(db.String(255)) file = db.Column(db.String(255))
cover = db.Column(db.String(255)) cover = db.Column(db.String(255))
fileformat = db.Column(db.String(255)) fileformat = db.Column(db.String(255))
tag = db.Column(db.String(255)) category = db.Column(db.String(255))
authors = db.relationship('Author', secondary=authors, lazy='subquery', authors = db.relationship('Author', secondary=authors, lazy='subquery',
backref=db.backref('books', lazy=True)) backref=db.backref('books', lazy=True))
def __init__(self, title, file, cover, fileformat, tag): tags = db.relationship('Tag', secondary=tags, lazy='subquery',
backref=db.backref('books', lazy=True))
def __init__(self, title, file, cover, fileformat, category):
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.tag = tag self.category = category
def __repr__(self): def __repr__(self):
@ -38,18 +44,31 @@ class Author(db.Model):
id = db.Column(db.Integer(), primary_key=True) id = db.Column(db.Integer(), primary_key=True)
author_name = db.Column(db.String(50)) author_name = db.Column(db.String(50))
def __init__(self, author_name): def __init__(self, author_name):
self.author_name = author_name self.author_name = author_name
class Tag(db.Model):
__tablename__ = 'tags'
id = db.Column(db.Integer(), primary_key=True)
tag = db.Column(db.String(50))
def __init__(self, tag):
self.tag = tag
class AuthorSchema(Schema):
id = fields.Int(dump_only=True)
author_name = fields.Str()
class BookSchema(Schema): class BookSchema(Schema):
id = fields.Int(dump_only=True) id = fields.Int(dump_only=True)
title = fields.Str() title = fields.Str()
author = fields.Str()
file = fields.Str() file = fields.Str()
authors = fields.Nested(AuthorSchema, many=True)
cover = fields.Str() cover = fields.Str()
fileformat = fields.Str() fileformat = fields.Str()
tag = fields.Str() category = fields.Str()
def must_not_be_blank(data): def must_not_be_blank(data):
if not data: if not data:

@ -35,6 +35,27 @@ font-style: italic;
padding: 0px 8px; padding: 0px 8px;
}
.library_table a{
text-decoration: none;
color: black;
}
.library_table .title_col{
font-size: 17px;
}
.library_table .author_col{
font-size: 12px;
}
.library_table li{
list-style-type: none;
}
.library_table tr:nth-child(even){
background-color: #F8F8F8;
} }
.header input{ .header input{

@ -35,7 +35,7 @@
</table> </table>
</div> </div>
<br> <br>
<div class="form-group">{{ form.tag.label }} {{ form.tag(size=20, class="form-control") }}</div> <div class="form-group">{{ form.category.label }} {{ form.category(size=20, class="form-control") }}</div>
{{ form.file }} {{ form.file }}
<button type="submit" class="btn btn-primary">Upload</button> <button type="submit" class="btn btn-primary">Upload</button>
</form> </form>

@ -28,6 +28,9 @@
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</div>
<div class="form-group">
{{ form.category.label }} {{ form.category(size=20, class="form-control") }}
</div> </div>
<br> <br>
<button type="submit" class="btn btn-primary">Update</button> <button type="submit" class="btn btn-primary">Update</button>

@ -15,26 +15,26 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
<table style="width:100%"> <table class="library_table" style="width:100%">
<tr> <tr>
<th>Cover</th> <th>Cover</th>
<th>Title</th> <th>Title</th>
<th>Author</th> <th>Author</th>
<th>Filetype</th> <th>Filetype</th>
<th>Tag</th> <th>Category</th>
</tr> </tr>
{% for book in books %} {% for book in books|sort(attribute='title', reverse = False) %}
<tr> <tr>
<td><img src="../uploads/cover/{{ book.cover }}" width="80"></td> <td><img src="../uploads/cover/{{ book.cover }}" width="80"></td>
<td><a href="books/{{ book.id }}">{{ book.title }}</a></td> <td class="title_col"><a href="books/{{ book.id }}">{{ book.title }}</a></td>
<td> {% for author in book.authors %} <td class="author_col"> {% 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 %}</td> {% endfor %}</td>
<td>{{ book.fileformat }}</td> <td>{{ book.fileformat }}</td>
<td>{{ book.tag}}</td> <td>{{ book.category}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

@ -9,7 +9,7 @@ from app import app, db
from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
from app.forms import UserForm, UserForm_Edit from app.forms import UserForm, UserForm_Edit
from app.models import Book, BookSchema, Author from app.models import Book, BookSchema, Author, AuthorSchema
from app.cover import get_cover from app.cover import get_cover
import os import os
@ -18,6 +18,8 @@ from werkzeug.utils import secure_filename
# import sqlite3 # import sqlite3
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
author_schema = AuthorSchema()
authors_schema = AuthorSchema(many=True)
book_schema = BookSchema() book_schema = BookSchema()
books_schema = BookSchema(many=True) books_schema = BookSchema(many=True)
@ -79,19 +81,21 @@ def remove_book_by_id(id):
@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 = UserForm_Edit(title = book_to_edit.title, author =book_to_edit.authors) user_form = UserForm_Edit(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category )
if request.method == 'POST': if request.method == 'POST':
if user_form.validate_on_submit(): if user_form.validate_on_submit():
# check if the post request has the file part # check if the post request has the file part
title = user_form.title.data # You could also have used request.form['name'] title = user_form.title.data # You could also have used request.form['name']
authors = user_form.author.data # You could also have used request.form['email'] authors = user_form.author.data # You could also have used request.form['email']
category = user_form.category.data
# save user to database # save user to database
#book = Book(title, author, filename, cover, file_extension) #book = Book(title, author, filename, cover, file_extension)
db.session.commit() db.session.commit()
book = Book.query.filter_by(id=id).first() book = Book.query.filter_by(id=id).first()
book.title = title book.title = title
book.category = category
book.authors= [] book.authors= []
db.session.commit() db.session.commit()
for author in authors: for author in authors:
@ -134,10 +138,10 @@ def add_book():
cover = get_cover(fullpath, name) cover = get_cover(fullpath, name)
title = user_form.title.data # You could also have used request.form['name'] title = user_form.title.data # You could also have used request.form['name']
authors = user_form.author.data # You could also have used authors = user_form.author.data # You could also have used
tag = user_form.tag.data category = user_form.category.data
#print(author) #print(author)
#print(len(author)) #print(len(author))
book = Book(title, filename, cover, file_extension, tag) book = Book(title, filename, cover, file_extension, category)
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")
@ -181,9 +185,7 @@ def show_author_by_id(id):
@app.route('/authors/<int:id>/edit', methods=['POST', 'GET']) @app.route('/authors/<int:id>/edit', methods=['POST', 'GET'])
def edit_author_by_id(id): def edit_author_by_id(id):
#EDIT AUTHOR TO DO return "Ask the programmer."
return None
@ -195,16 +197,17 @@ def edit_author_by_id(id):
def get_books(): def get_books():
books = Book.query.all() books = Book.query.all()
data, errors = books_schema.dump(books) data, errors = books_schema.dump(books)
print(errors)
return jsonify({'books': data}) return jsonify({'books': data})
@app.route('/api/books/<int:id>', methods=['GET']) @app.route('/api/books/<int:id>', methods=['GET'])
def get_book_by_id(id): def get_book_by_id(id):
book = Book.query.get(id) book = Book.query.get(id)
book_result, error = book_schema.dump(book) data, error = book_schema.dump(book)
if not book_result: if not data:
return jsonify({"message": "Book could not be found."}), 400 return jsonify({"message": "Book could not be found."}), 400
else: else:
return jsonify({'book': book_result}) return jsonify({'book': data })

@ -140,7 +140,7 @@ Mondotheque: a radiated book / un livre irradiant / een iradierend boek,"André
An Atlas of Typeforms,"James Sutton, Alan Bartram",design / writing / publishing,,,,, An Atlas of Typeforms,"James Sutton, Alan Bartram",design / writing / publishing,,,,,
Structure of the Visual Book,Keith Smith,design / writing / publishing,,,,, Structure of the Visual Book,Keith Smith,design / writing / publishing,,,,,
The Uses of Literacy,Richard Hoggart,design / writing / publishing,pdf,0,1,Monoskop, The Uses of Literacy,Richard Hoggart,design / writing / publishing,pdf,0,1,Monoskop,
Control and Freedom: Power and Paranoia in the Age of Fiber Optics,Wendy Hui Kyong Chun,desk,pdf,1,1,LibGen,Chun_ControlandFreedom.pdf Control and Freedom: Power and Paranoia in the Age of Fiber Optics,Wendy Hui Kyong Chun,desk,pdf,1,1,LibGen,
The New Media Reader,"Noah Wardrip-Fruin, Nick Montfort (editors)",desk,pdf,1,1,LibGen, The New Media Reader,"Noah Wardrip-Fruin, Nick Montfort (editors)",desk,pdf,1,1,LibGen,
Art and Electronic Media,Edward A. Shanken,Art,,,0,, Art and Electronic Media,Edward A. Shanken,Art,,,0,,
The Situationist City,Simon Sadler,Art,pdf,1,1,Monoskop, The Situationist City,Simon Sadler,Art,pdf,1,1,Monoskop,

1 Title Author Shelf Format OCR Downloaded Origin Filename
140 An Atlas of Typeforms James Sutton, Alan Bartram design / writing / publishing
141 Structure of the Visual Book Keith Smith design / writing / publishing
142 The Uses of Literacy Richard Hoggart design / writing / publishing pdf 0 1 Monoskop
143 Control and Freedom: Power and Paranoia in the Age of Fiber Optics Wendy Hui Kyong Chun desk pdf 1 1 LibGen Chun_ControlandFreedom.pdf
144 The New Media Reader Noah Wardrip-Fruin, Nick Montfort (editors) desk pdf 1 1 LibGen
145 Art and Electronic Media Edward A. Shanken Art 0
146 The Situationist City Simon Sadler Art pdf 1 1 Monoskop
Loading…
Cancel
Save