Skip to content

Commit

Permalink
Merge pull request #48 from boris/review-add-markdown
Browse files Browse the repository at this point in the history
Review: add markdown
  • Loading branch information
Boris Quiroz authored Aug 23, 2023
2 parents cdad161 + ee8ce0a commit 74e73fa
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 56 deletions.
1 change: 1 addition & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, *args, author_id=None, editorial_id=None, genre_id=None, **kw
validators=[InputRequired()])
book_rating = IntegerField('Puntuación', validators=[NumberRange(min=0, max=5)])
book_review = TextAreaField('Reseña')
book_cover = StringField('Imagen')
book_tags = StringField('Tags')
submit = SubmitField('Agregar')

Expand Down
16 changes: 15 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import markdown
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask_login import login_required, current_user
from flask_sqlalchemy import SQLAlchemy
Expand Down Expand Up @@ -68,6 +69,7 @@ def add_book():
book_pages = request.form['book_pages']
book_rating = request.form['book_rating']
book_review = request.form['book_review']
book_cover = request.form['book_cover']

# Normalize some values
if request.form['book_is_read'].lower() == 'si':
Expand All @@ -90,6 +92,7 @@ def add_book():
shared = is_shared,
rating = book_rating,
review = book_review,
cover = book_cover,
id_user = current_user.id,
id_author = id_author,
id_editorial = id_editorial,
Expand Down Expand Up @@ -134,6 +137,7 @@ def edit_book(book_id):
book.shared = form.book_is_shared.data == 'Si'
book.rating = form.book_rating.data
book.review = form.book_review.data
book.cover = form.book_cover.data
book.tags = form.book_tags.data

db.session.commit()
Expand Down Expand Up @@ -255,14 +259,24 @@ def show_author(author_id):
@main.route('/show_book/<int:book_id>')
@login_required
def show_book(book_id):
current_book = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.read, Book.shared, Book.rating, Book.review, Author.name.label('author_name'), Author.country.label('author_country'), Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\
current_book = db.session.query(Book.id, Book.title, Book.year, Book.pages, Book.read, Book.shared, Book.rating, Book.review, Book.cover, Author.name.label('author_name'), Author.country.label('author_country'), Editorial.name.label('editorial_name'), Genre.name.label('genre_name'))\
.filter(Book.id == book_id)\
.join(Author)\
.join(Editorial)\
.join(Genre)

review = db.session.query(Book.review).filter(Book.id == book_id)
review = markdown.markdown(review[0][0])

#rev = []
#for r in review:
# r = dict(r)
# r['content'] = markdown.markdown(r['content'])
# rev.append(r)

return render_template('show_book.html',
greeting = current_user.name,
review = review,
book = current_book,
)

Expand Down
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Book(db.Model):
shared = db.Column(db.Boolean, default=False)
rating = db.Column(db.Integer)
review = db.Column(db.Text)
cover = db.Column(db.String(255))
id_user = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
id_author = db.Column(db.Integer, db.ForeignKey('author.id'), nullable=False)
id_editorial = db.Column(db.Integer, db.ForeignKey('editorial.id'), nullable=False)
Expand Down
5 changes: 3 additions & 2 deletions app/templates/add_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ <h1 class="title is-1">Agregar nuevo libro</h1>
<p>{{ form.book_is_read.label }} {{ form.book_is_read }}</p>
<p>{{ form.book_is_shared.label }} {{ form.book_is_shared }}</p>
<p>{{ form.book_rating.label }} {{ form.book_rating(size=4) }}</p>
<p>{{ form.book_tags.label }} {{ form.book_tags(size=30) }}</p>
<p>{{ form.book_review.label }} {{ form.book_review(class_='wide-textarea', rows=10) }}</p>
<p>{{ form.book_cover.label }} {{ form.book_cover }}</p>
<!--<p>{{ form.book_tags.label }} {{ form.book_tags(size=30) }}</p>-->
<p>{{ form.book_review.label }} (soporta <a href="https://www.markdownguide.org/basic-syntax/">markdown</a>){{ form.book_review(class_='wide-textarea', rows=10) }}</p>
<br>
{{ form.submit }}
</form>
Expand Down
7 changes: 7 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
width: 100%;
height: 200px;
}
.bd-example-row-flex-cols .row {
background-color: transparent;
}
.bd-example-row [class^="col"], .bd-example-cssgrid .grid > * {
background-color: transparent;
border: 0;
}
</style>

<body class="p-3 m-0 border-0 bd-example bd-example-row bd-example-row-flex-cols">
Expand Down
5 changes: 3 additions & 2 deletions app/templates/edit_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ <h1 class="title is-1">Editar libro</h1>
<p>{{ form.book_is_read.label }} {{ form.book_is_read(checked=book_is_read) }}</p>
<p>{{ form.book_is_shared.label }} {{ form.book_is_shared(checked=book_is_shared) }}</p>
<p>{{ form.book_rating.label }} {{ form.book_rating(value=book.rating) }}</p>
<p>{{ form.book_tags.label }} {{ form.book_tags(value=book.tags) }}</p>
<p>{{ form.book_review.label }} {{ form.book_review(value=book.review, class_='wide-textarea', rows=10) }}</p>
<p>{{ form.book_cover.label }} {{ form.book_cover(value=book.cover) }}</p>
<!--<p>{{ form.book_tags.label }} {{ form.book_tags(value=book.tags) }}</p>-->
<p>{{ form.book_review.label }} (soporta <a href="https://www.markdownguide.org/basic-syntax/">markdown</a>){{ form.book_review(value=book.review, class_='wide-textarea', rows=10) }}</p>
{{ form.submit }}
</form>
</div>
Expand Down
42 changes: 24 additions & 18 deletions app/templates/show_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,34 @@

<div class="container has-text-justified">
<h1 class="title">{{ item[1] }}</h1>
<h2 class="text-muted">{{ item[8] }} ({{ item[9] }})</h2>
<br></br>
<p><b>Género: </b>{{ item[11] }}</p>
<p><b>Editorial: </b>{{ item[10] }}</p>
<p><b>Año: </b>{{ item[2] }}</p>
<p><b>¿Leído?: </b>{% if item[4] %}<i class="bi bi-check-square-fill"></i>{%else%}<i class="bi bi-x-square-fill"></i>{%endif%}</p>
<p><b>¿Prestado?: </b>{% if item[5] %}<i class="bi bi-check-square-fill"></i>{%else%}<i class="bi bi-x-square-fill"></i>{%endif%}</p>
<p><b>Número de páginas: </b>{{ item[3] }}</p>
<p><b>Puntuación: </b>{{ item[6] * '<i class="bi bi-star-fill"></i>' |safe}}</p>
<p><b>Reseña: </b></p>
<p>{{ item[7] }}</p>
<br></br>
<h2 class="text-muted">{{ item[9] }} ({{ item[10] }})</h2>

<div class="container">
<div class="row no-gutters">
<div class="col-sm-5">
<p><b>Género: </b>{{ item[12] }}</p>
<p><b>Editorial: </b>{{ item[11] }}</p>
<p><b>Año: </b>{{ item[2] }}</p>
<p><b>¿Leído?: </b>{% if item[4] %}<i class="bi bi-check-square-fill"></i>{%else%}<i class="bi bi-x-square-fill"></i>{%endif%}</p>
<p><b>¿Prestado?: </b>{% if item[5] %}<i class="bi bi-check-square-fill"></i>{%else%}<i class="bi bi-x-square-fill"></i>{%endif%}</p>
<p><b>Número de páginas: </b>{{ item[3] }}</p>
<p><b>Puntuación: </b>{{ item[6] * '<i class="bi bi-star-fill"></i>' |safe}}</p>
<br>
<p><img src="{{ item[8] }}"></p>
</div>
<div class="col-sm-7">
{{ review | safe }}
</div>
</div>
</div>
</div>

<hr>

<nav class="navbar fixed-bottom navbar-light bg-light">
<div class="text-nowrap">
<a href="{{ url_for('main.edit_book', book_id = item[0]) }}">Editar Libro</a>
<a href="{{ url_for('main.delete_book', book_id = item[0]) }}">Borrar Libro</a>
</div>
</nav>
<div class="text-nowrap">
<a href="{{ url_for('main.edit_book', book_id = item[0]) }}">Editar Libro</a>
<a href="{{ url_for('main.delete_book', book_id = item[0]) }}">Borrar Libro</a>
</div>
{% endfor %}
</div>
{% endblock %}
Binary file modified migrations/__pycache__/env.cpython-38.pyc
Binary file not shown.
Binary file removed migrations/__pycache__/env.cpython-39.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""empty message
Revision ID: 5f7d46cc782b
Revision ID: 98513b724e75
Revises:
Create Date: 2023-04-03 06:42:18.715967
Create Date: 2023-08-12 12:58:31.467298
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5f7d46cc782b'
revision = '98513b724e75'
down_revision = None
branch_labels = None
depends_on = None
Expand Down Expand Up @@ -55,6 +55,8 @@ def upgrade():
sa.Column('read', sa.Boolean(), nullable=True),
sa.Column('shared', sa.Boolean(), nullable=True),
sa.Column('rating', sa.Integer(), nullable=True),
sa.Column('review', sa.Text(), nullable=True),
sa.Column('cover', sa.String(length=255), nullable=True),
sa.Column('id_user', sa.Integer(), nullable=False),
sa.Column('id_author', sa.Integer(), nullable=False),
sa.Column('id_editorial', sa.Integer(), nullable=False),
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 0 additions & 30 deletions migrations/versions/abfd49079cd8_.py

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ Flask-Testing==0.8.1
Flask-WTF==1.0.1
greenlet==1.1.2
importlib-metadata==4.12.0
importlib-resources==6.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
Mako==1.2.1
Markdown==3.4.4
MarkupSafe==2.1.1
mysqlclient==2.1.1
passlib==1.7.4
Expand Down

0 comments on commit 74e73fa

Please sign in to comment.