categories

master
Alex 6 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__)
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):
title = StringField('title', validators=[InputRequired()])
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
tag = StringField('tag', validators=[InputRequired()])
category = StringField('category', validators=[InputRequired()])
file = FileField()
class UserForm_Edit(FlaskForm):
title = StringField('title', validators=[InputRequired()])
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)
)
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):
__tablename__ = 'books'
id = db.Column(db.Integer, primary_key = True)
@ -13,17 +18,18 @@ class Book(db.Model):
file = db.Column(db.String(255))
cover = 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',
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.file = file
self.cover = cover
self.fileformat = fileformat
self.tag = tag
self.category = category
def __repr__(self):
@ -38,18 +44,31 @@ class Author(db.Model):
id = db.Column(db.Integer(), primary_key=True)
author_name = db.Column(db.String(50))
def __init__(self, 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):
id = fields.Int(dump_only=True)
title = fields.Str()
author = fields.Str()
file = fields.Str()
authors = fields.Nested(AuthorSchema, many=True)
cover = fields.Str()
fileformat = fields.Str()
tag = fields.Str()
category = fields.Str()
def must_not_be_blank(data):
if not data:

@ -35,6 +35,27 @@ font-style: italic;
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{

@ -35,7 +35,7 @@
</table>
</div>
<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 }}
<button type="submit" class="btn btn-primary">Upload</button>
</form>

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

@ -15,26 +15,26 @@
{% endif %}
{% endwith %}
<table style="width:100%">
<table class="library_table" style="width:100%">
<tr>
<th>Cover</th>
<th>Title</th>
<th>Author</th>
<th>Filetype</th>
<th>Tag</th>
<th>Category</th>
</tr>
{% for book in books %}
{% for book in books|sort(attribute='title', reverse = False) %}
<tr>
<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>
{% endfor %}</td>
<td>{{ book.fileformat }}</td>
<td>{{ book.tag}}</td>
<td>{{ book.category}}</td>
</tr>
{% endfor %}
</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 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
import os
@ -18,6 +18,8 @@ from werkzeug.utils import secure_filename
# import sqlite3
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
author_schema = AuthorSchema()
authors_schema = AuthorSchema(many=True)
book_schema = BookSchema()
books_schema = BookSchema(many=True)
@ -79,19 +81,21 @@ def remove_book_by_id(id):
@app.route('/books/<int:id>/edit', methods=['POST', 'GET'])
def edit_book_by_id(id):
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 user_form.validate_on_submit():
# check if the post request has the file part
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']
category = user_form.category.data
# save user to database
#book = Book(title, author, filename, cover, file_extension)
db.session.commit()
book = Book.query.filter_by(id=id).first()
book.title = title
book.category = category
book.authors= []
db.session.commit()
for author in authors:
@ -134,10 +138,10 @@ def add_book():
cover = get_cover(fullpath, name)
title = user_form.title.data # You could also have used request.form['name']
authors = user_form.author.data # You could also have used
tag = user_form.tag.data
category = user_form.category.data
#print(author)
#print(len(author))
book = Book(title, filename, cover, file_extension, tag)
book = Book(title, filename, cover, file_extension, category)
db.session.add(book)
for author in authors:
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'])
def edit_author_by_id(id):
#EDIT AUTHOR TO DO
return None
return "Ask the programmer."
@ -195,16 +197,17 @@ def edit_author_by_id(id):
def get_books():
books = Book.query.all()
data, errors = books_schema.dump(books)
print(errors)
return jsonify({'books': data})
@app.route('/api/books/<int:id>', methods=['GET'])
def get_book_by_id(id):
book = Book.query.get(id)
book_result, error = book_schema.dump(book)
if not book_result:
data, error = book_schema.dump(book)
if not data:
return jsonify({"message": "Book could not be found."}), 400
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,,,,,
Structure of the Visual Book,Keith Smith,design / writing / publishing,,,,,
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,
Art and Electronic Media,Edward A. Shanken,Art,,,0,,
The Situationist City,Simon Sadler,Art,pdf,1,1,Monoskop,
@ -168,4 +168,4 @@ Orality and Literacy,Walter Ong,Digital (Steve Trim 2 reading),epub,1,1,Steve,
International Picture Language,Otto Neurath,Digital (Steve Trim 2 reading),pdf,0,1,Steve,
Protocol,Alexander R. Galloway,Media studies,pdf,1,1,Timo Klok/Monoskop,
A Prehistory of the Cloud,Tung-Hui Hu,Media Studies (Femke Trim 3),pdf,1,1,Libgen,
Paratexts: Thresholds of Interpretation,Gerard Genette,"Literature, Culture, Theory ",pdf,1,1,Memory of the World,
Paratexts: Thresholds of Interpretation,Gerard Genette,"Literature, Culture, Theory ",pdf,1,1,Memory of the World,

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
168 International Picture Language Otto Neurath Digital (Steve Trim 2 reading) pdf 0 1 Steve
169 Protocol Alexander R. Galloway Media studies pdf 1 1 Timo Klok/Monoskop
170 A Prehistory of the Cloud Tung-Hui Hu Media Studies (Femke Trim 3) pdf 1 1 Libgen
171 Paratexts: Thresholds of Interpretation Gerard Genette Literature, Culture, Theory pdf 1 1 Memory of the World
Loading…
Cancel
Save