mirror of https://github.com/logos-co/open-law.git
Merge pull request #82 from Simple2B/kostia/fix/logs_everywhere
Kostia/fix/logs everywhere
This commit is contained in:
commit
4d5b3cd560
|
@ -22,7 +22,6 @@ def create_app(environment="development"):
|
|||
user_blueprint,
|
||||
book_blueprint,
|
||||
home_blueprint,
|
||||
section_blueprint,
|
||||
vote_blueprint,
|
||||
approve_blueprint,
|
||||
star_blueprint,
|
||||
|
@ -54,7 +53,6 @@ def create_app(environment="development"):
|
|||
app.register_blueprint(user_blueprint)
|
||||
app.register_blueprint(book_blueprint)
|
||||
app.register_blueprint(home_blueprint)
|
||||
app.register_blueprint(section_blueprint)
|
||||
app.register_blueprint(vote_blueprint)
|
||||
app.register_blueprint(approve_blueprint)
|
||||
app.register_blueprint(star_blueprint)
|
||||
|
|
|
@ -28,6 +28,8 @@ def delete_nested_version_entities(book_version: m.BookVersion):
|
|||
|
||||
|
||||
def delete_nested_collection_entities(collection: m.Collection):
|
||||
for sub_collection in collection.children:
|
||||
delete_nested_collection_entities(sub_collection)
|
||||
for section in collection.sections:
|
||||
section: m.Section
|
||||
section.is_deleted = True
|
||||
|
|
|
@ -12,4 +12,4 @@
|
|||
<!-- prettier-ignore -->
|
||||
<button type="submit" id="global-search-button" class="md:flex px-3 py-2 text-xs text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 ml-2 font-medium rounded-lg text-center inline-flex items-center mr-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"><svg class="w-5 h-5 text-white-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 ml-0 mr-1"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 15.75l-2.489-2.489m0 0a3.375 3.375 0 10-4.773-4.773 3.375 3.375 0 004.774 4.774zM21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>Search</button>
|
||||
</div>
|
||||
{% include 'quickSearchWindow.html' %}
|
||||
{% include 'search/quick_search_window.html' %}
|
||||
|
|
|
@ -4,7 +4,6 @@ from .main import main_blueprint
|
|||
from .user import bp as user_blueprint
|
||||
from .book import bp as book_blueprint
|
||||
from .home import bp as home_blueprint
|
||||
from .section import bp as section_blueprint
|
||||
from .vote import bp as vote_blueprint
|
||||
from .approve import bp as approve_blueprint
|
||||
from .star import bp as star_blueprint
|
||||
|
|
|
@ -24,10 +24,14 @@ from .bp import bp
|
|||
|
||||
@bp.route("/all", methods=["GET"])
|
||||
def get_all():
|
||||
log(log.INFO, "Create query for books")
|
||||
books: m.Book = m.Book.query.filter(m.Book.is_deleted is not False).order_by(
|
||||
m.Book.id
|
||||
)
|
||||
log(log.INFO, "Create pagination for books")
|
||||
|
||||
pagination = create_pagination(total=books.count())
|
||||
log(log.INFO, "Returning data for front end")
|
||||
|
||||
return render_template(
|
||||
"book/all.html",
|
||||
|
@ -40,15 +44,22 @@ def get_all():
|
|||
@bp.route("/my_library", methods=["GET"])
|
||||
def my_library():
|
||||
if current_user.is_authenticated:
|
||||
log(log.INFO, "Create query for my_library page for books")
|
||||
|
||||
books: m.Book = m.Book.query.order_by(m.Book.id)
|
||||
books = books.filter_by(user_id=current_user.id, is_deleted=False)
|
||||
log(log.INFO, "Create pagination for books")
|
||||
|
||||
pagination = create_pagination(total=books.count())
|
||||
log(log.INFO, "Returns data for front end")
|
||||
|
||||
return render_template(
|
||||
"book/my_library.html",
|
||||
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
)
|
||||
log(log.INFO, "Returns data for front end is user is anonym")
|
||||
|
||||
return render_template(
|
||||
"book/my_library.html",
|
||||
books=[],
|
||||
|
@ -141,6 +152,8 @@ def statistic_view(book_id: int):
|
|||
@bp.route("/favorite_books", methods=["GET"])
|
||||
def favorite_books():
|
||||
if current_user.is_authenticated:
|
||||
log(log.INFO, "Creating query for books")
|
||||
|
||||
books = (
|
||||
db.session.query(
|
||||
m.Book,
|
||||
|
@ -156,7 +169,10 @@ def favorite_books():
|
|||
)
|
||||
|
||||
books = books.filter_by(is_deleted=False)
|
||||
log(log.INFO, "Creating pagination for books")
|
||||
|
||||
pagination = create_pagination(total=books.count())
|
||||
log(log.INFO, "Returns data for front end")
|
||||
|
||||
return render_template(
|
||||
"book/favorite_books.html",
|
||||
|
@ -169,6 +185,8 @@ def favorite_books():
|
|||
@bp.route("/my_contributions", methods=["GET"])
|
||||
def my_contributions():
|
||||
if current_user.is_authenticated:
|
||||
log(log.INFO, "Creating query for interpretations")
|
||||
|
||||
interpretations = (
|
||||
db.session.query(
|
||||
m.Interpretation,
|
||||
|
@ -190,8 +208,10 @@ def my_contributions():
|
|||
.group_by(m.Interpretation.id)
|
||||
.order_by(m.Interpretation.created_at.desc())
|
||||
)
|
||||
log(log.INFO, "Creating pagination for interpretations")
|
||||
|
||||
pagination = create_pagination(total=interpretations.count())
|
||||
log(log.INFO, "Returns data for front end")
|
||||
|
||||
return render_template(
|
||||
"book/my_contributions.html",
|
||||
|
|
|
@ -4,15 +4,21 @@ from flask import (
|
|||
)
|
||||
from sqlalchemy import and_
|
||||
from app import models as m, db
|
||||
from app.logger import log
|
||||
|
||||
|
||||
bp = Blueprint("home", __name__, url_prefix="/home")
|
||||
|
||||
|
||||
@bp.route("/", methods=["GET"])
|
||||
def get_all():
|
||||
log(log.INFO, "Create query for home page for books")
|
||||
|
||||
books: m.Book = (
|
||||
m.Book.query.filter_by(is_deleted=False).order_by(m.Book.id).limit(5)
|
||||
).all()
|
||||
log(log.INFO, "Create query for home page for interpretations")
|
||||
|
||||
interpretations = (
|
||||
db.session.query(
|
||||
m.Interpretation,
|
||||
|
@ -34,6 +40,7 @@ def get_all():
|
|||
.limit(5)
|
||||
.all()
|
||||
)
|
||||
log(log.INFO, "Returning data to front end")
|
||||
|
||||
return render_template(
|
||||
"home/index.html",
|
||||
|
|
|
@ -15,14 +15,18 @@ bp = Blueprint("search", __name__)
|
|||
@bp.route("/search_interpretations", methods=["GET"])
|
||||
def search_interpretations():
|
||||
q = request.args.get("q", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for interpretations")
|
||||
interpretations = m.Interpretation.query.order_by(m.Interpretation.id).filter(
|
||||
(func.lower(m.Interpretation.plain_text).like(f"%{q}%"))
|
||||
)
|
||||
log(log.INFO, "Get count of interpretations")
|
||||
count = interpretations.count()
|
||||
log(log.INFO, "Creating pagination")
|
||||
pagination = create_pagination(total=interpretations.count())
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"searchResultsInterpretations.html",
|
||||
"search/search_results_interpretations.html",
|
||||
query=q,
|
||||
interpretations=interpretations.paginate(
|
||||
page=pagination.page, per_page=pagination.per_page
|
||||
|
@ -74,7 +78,7 @@ def search_books():
|
|||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"searchResultsBooks.html",
|
||||
"search/search_results_books.html",
|
||||
query=q,
|
||||
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
|
@ -85,6 +89,7 @@ def search_books():
|
|||
@bp.route("/search_users", methods=["GET"])
|
||||
def search_users():
|
||||
q = request.args.get("q", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for users")
|
||||
users = (
|
||||
m.User.query.order_by(m.User.id)
|
||||
.filter(
|
||||
|
@ -96,12 +101,16 @@ def search_users():
|
|||
.order_by(m.User.id.asc())
|
||||
.group_by(m.User.id)
|
||||
)
|
||||
log(log.INFO, "Get count of users")
|
||||
|
||||
count = users.count()
|
||||
log(log.INFO, "Creating pagination")
|
||||
|
||||
pagination = create_pagination(total=users.count())
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"searchResultsUsers.html",
|
||||
"search/search_results_users.html",
|
||||
query=q,
|
||||
users=users.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
|
@ -112,12 +121,19 @@ def search_users():
|
|||
@bp.route("/search_tags", methods=["GET"])
|
||||
def search_tags():
|
||||
q = request.args.get("q", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for tags")
|
||||
|
||||
tags = m.Tag.query.order_by(m.Tag.id).filter(func.lower(m.Tag.name).like(f"%{q}%"))
|
||||
log(log.INFO, "Get count of tags")
|
||||
|
||||
count = tags.count()
|
||||
log(log.INFO, "Creating pagination")
|
||||
|
||||
pagination = create_pagination(total=tags.count())
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"searchResultsTags.html",
|
||||
"search/search_results_tags.html",
|
||||
query=q,
|
||||
tags=tags.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
|
@ -128,6 +144,8 @@ def search_tags():
|
|||
@bp.route("/tag_search_interpretations", methods=["GET"])
|
||||
def tag_search_interpretations():
|
||||
tag_name = request.args.get("tag_name", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for interpretations")
|
||||
|
||||
interpretations = (
|
||||
db.session.query(m.Interpretation)
|
||||
.filter(
|
||||
|
@ -141,11 +159,13 @@ def tag_search_interpretations():
|
|||
.order_by(m.Interpretation.created_at.asc())
|
||||
.group_by(m.Interpretation.id)
|
||||
)
|
||||
log(log.INFO, "Creating pagination")
|
||||
|
||||
pagination = create_pagination(total=interpretations.count())
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"tagSearchResultsInterpretations.html",
|
||||
"search/tag_search_Results_interpretations.html",
|
||||
tag_name=tag_name,
|
||||
interpretations=interpretations.paginate(
|
||||
page=pagination.page, per_page=pagination.per_page
|
||||
|
@ -158,6 +178,8 @@ def tag_search_interpretations():
|
|||
@bp.route("/tag_search_books", methods=["GET"])
|
||||
def tag_search_books():
|
||||
tag_name = request.args.get("tag_name", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for books")
|
||||
|
||||
books = (
|
||||
db.session.query(m.Book)
|
||||
.filter(
|
||||
|
@ -171,11 +193,13 @@ def tag_search_books():
|
|||
.order_by(m.Book.created_at.asc())
|
||||
.group_by(m.Book.id)
|
||||
)
|
||||
log(log.INFO, "Creating pagination")
|
||||
|
||||
pagination = create_pagination(total=books.count())
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return render_template(
|
||||
"tagSearchResultsBooks.html",
|
||||
"search/tag_search_results_books.html",
|
||||
tag_name=tag_name,
|
||||
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
|
@ -186,6 +210,8 @@ def tag_search_books():
|
|||
@bp.route("/quick_search", methods=["GET"])
|
||||
def quick_search():
|
||||
search_query = request.args.get("search_query", type=str, default="").lower()
|
||||
log(log.INFO, "Starting to build query for interpretations")
|
||||
|
||||
interpretations = (
|
||||
m.Interpretation.query.order_by(m.Interpretation.id)
|
||||
.filter(
|
||||
|
@ -200,6 +226,8 @@ def quick_search():
|
|||
interpretations_res.append(
|
||||
{"label": interpretation.section.label, "url": url_for_interpretation}
|
||||
)
|
||||
log(log.INFO, "Starting to build query for books")
|
||||
|
||||
books = (
|
||||
m.Book.query.order_by(m.Book.id)
|
||||
.filter(
|
||||
|
@ -212,6 +240,7 @@ def quick_search():
|
|||
for book in books:
|
||||
url_for_book = url_for("book.collection_view", book_id=book.id)
|
||||
books_res.append({"label": book.label, "url": url_for_book})
|
||||
log(log.INFO, "Starting to build query for users")
|
||||
|
||||
users = (
|
||||
m.User.query.order_by(m.User.id)
|
||||
|
@ -229,6 +258,7 @@ def quick_search():
|
|||
for user in users:
|
||||
url_for_user = url_for("user.profile", user_id=user.id)
|
||||
users_res.append({"label": user.username, "url": url_for_user})
|
||||
log(log.INFO, "Starting to build query for tags")
|
||||
|
||||
tags = (
|
||||
m.Tag.query.order_by(m.Tag.id)
|
||||
|
@ -239,6 +269,7 @@ def quick_search():
|
|||
for tag in tags:
|
||||
url_for_tag = url_for("search.tag_search_interpretations", tag_name=tag.name)
|
||||
tags_res.append({"label": tag.name, "url": url_for_tag})
|
||||
log(log.INFO, "Returning data to front")
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
from flask import (
|
||||
Blueprint,
|
||||
render_template,
|
||||
request,
|
||||
)
|
||||
|
||||
from app.controllers import create_pagination
|
||||
from app import models as m
|
||||
|
||||
|
||||
bp = Blueprint("section", __name__, url_prefix="/section")
|
||||
|
||||
|
||||
@bp.route("/all", methods=["GET"])
|
||||
def get_all():
|
||||
q = request.args.get("q", type=str, default=None)
|
||||
section: m.Section = m.Section.query.order_by(m.Section.id)
|
||||
if q:
|
||||
section = section.filter(m.Section.label.like(f"{q}"))
|
||||
|
||||
pagination = create_pagination(total=section.count())
|
||||
|
||||
return render_template(
|
||||
"section/all.html",
|
||||
sections=section.paginate(page=pagination.page, per_page=pagination.per_page),
|
||||
page=pagination,
|
||||
search_query=q,
|
||||
all_books=True,
|
||||
)
|
|
@ -81,22 +81,6 @@ def profile(user_id: int):
|
|||
)
|
||||
|
||||
|
||||
@bp.route("/create", methods=["POST"])
|
||||
@login_required
|
||||
def create():
|
||||
form = f.NewUserForm()
|
||||
if form.validate_on_submit():
|
||||
user = m.User(
|
||||
username=form.username.data,
|
||||
password=form.password.data,
|
||||
activated=form.activated.data,
|
||||
)
|
||||
log(log.INFO, "Form submitted. User: [%s]", user)
|
||||
flash("User added!", "success")
|
||||
user.save()
|
||||
return redirect(url_for("user.get_all"))
|
||||
|
||||
|
||||
@bp.route("/profile_delete", methods=["POST"])
|
||||
@login_required
|
||||
def profile_delete():
|
||||
|
|
Loading…
Reference in New Issue