diff --git a/.DS_Store b/.DS_Store index 5008ddf..3644916 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/app/__init__.py b/app/__init__.py index 0b5bb99..a1cb2a7 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -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") diff --git a/app/forms.py b/app/forms.py index 11398bf..62cb3fe 100755 --- a/app/forms.py +++ b/app/forms.py @@ -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()]) diff --git a/app/models.py b/app/models.py index ab40883..b103540 100755 --- a/app/models.py +++ b/app/models.py @@ -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: diff --git a/app/static/css/style.css b/app/static/css/style.css index 8e1aa24..f147b54 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -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{ diff --git a/app/templates/add_book.html b/app/templates/add_book.html index 375001b..1fbb362 100755 --- a/app/templates/add_book.html +++ b/app/templates/add_book.html @@ -35,7 +35,7 @@
-
{{ form.tag.label }} {{ form.tag(size=20, class="form-control") }}
+
{{ form.category.label }} {{ form.category(size=20, class="form-control") }}
{{ form.file }} diff --git a/app/templates/edit_book_detail.html b/app/templates/edit_book_detail.html index 5d5110c..0125983 100755 --- a/app/templates/edit_book_detail.html +++ b/app/templates/edit_book_detail.html @@ -29,6 +29,9 @@ {% endfor %} +
+ {{ form.category.label }} {{ form.category(size=20, class="form-control") }} +

diff --git a/app/templates/show_books.html b/app/templates/show_books.html index e7cef45..cd78abb 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -15,26 +15,26 @@ {% endif %} {% endwith %} - +
- + - {% for book in books %} + {% for book in books|sort(attribute='title', reverse = False) %} - + - - + {% endfor %}
Cover Title Author FiletypeTagCategory
{{ book.title }}{{ book.title }} {% for author in book.authors %} + {% for author in book.authors %}
  • {{ author.author_name }}
  • {% endfor %}
    {{ book.fileformat }}{{ book.tag}}{{ book.category}}
    diff --git a/app/views.py b/app/views.py index 7e54a0d..b8a5e53 100755 --- a/app/views.py +++ b/app/views.py @@ -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//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//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/', 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 }) diff --git a/xpublibrary.csv b/xpublibrary.csv index 25bb07c..1725e02 100644 --- a/xpublibrary.csv +++ b/xpublibrary.csv @@ -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, \ No newline at end of file +Paratexts: Thresholds of Interpretation,Gerard Genette,"Literature, Culture, Theory ",pdf,1,1,Memory of the World,