Skip to content

Commit aee6cef

Browse files
committed
log statements
1 parent 113ca31 commit aee6cef

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

library_db/library.db

0 Bytes
Binary file not shown.

library_db/routes/api/user/user.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import re
22
from hashlib import md5
33
from datetime import date, datetime
4-
from flask import Blueprint, session, request
4+
from flask import Blueprint, session, request, current_app
55

66

77
from library_db.utils.db_utils import (
88
get_media,
99
is_media_borrowed,
1010
get_user_data,
11-
borrow_book,
11+
borrow_media,
1212
update_user,
1313
delete_user,
1414
)
@@ -42,8 +42,9 @@ def borrow(media_id):
4242
if age_limit > age:
4343
return {"error": "User too Young"}
4444

45-
borrow_book(media_id, user.get("id"))
45+
borrow_media(media_id, user.get("id"))
4646

47+
current_app.logger.info(f"{session['email']} Borrowed media with id {media_id}")
4748
return {"status": "success"}
4849

4950

@@ -159,4 +160,5 @@ def remove_user():
159160
session.pop("email")
160161
session.pop("pwdhash")
161162

163+
current_app.logger(f"{session['email']} Deleted user with email {session['email']}")
162164
return {"status": "success"}

library_db/routes/general/general.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def home():
1111
global visit_counter
1212

13-
current_app.logger.info(f"Home Page visited {visit_counter} times.")
1413
visit_counter += 1
14+
current_app.logger.info(f"Home Page visited {visit_counter} times.")
1515
template_vars = get_template_vars(session)
1616
return render_template("general/index.html", **template_vars)

library_db/routes/panel/admin/admin.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def del_user():
7979
)
8080

8181
delete_user(user.get("id"))
82+
current_app.logger(f"{session['email']} Deleted user with email {user['email']}")
8283
return redirect(url_for("panel_bluep.admin_bluep.user_managment"))
8384

8485

@@ -130,7 +131,7 @@ def get_error_log(log):
130131
return send_from_directory(
131132
directory=error_log_dir, path=log, as_attachment=True
132133
)
133-
134+
134135
return abort(404)
135136

136137

library_db/routes/panel/staff/staff.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
render_template,
77
request,
88
abort,
9+
current_app,
910
)
1011

1112

@@ -136,6 +137,9 @@ def ret_error(error: str):
136137
isbn=isbn,
137138
)
138139

140+
current_app.logger.info(
141+
f"{session['email']} Updated media {media.title} with id {id}"
142+
)
139143
return redirect(url_for("panel_bluep.staff_bluep.staff_panel_alter"))
140144

141145

@@ -177,6 +181,7 @@ def alter_author():
177181

178182
update_author(id, author_name)
179183

184+
current_app.logger.info(f"{session['email']} Updated author {author} with id {id}")
180185
return redirect(url_for("panel_bluep.staff_bluep.staff_panel_alter"))
181186

182187

@@ -203,7 +208,7 @@ def ret_error(error: str):
203208
try:
204209
isbn = int(isbn)
205210
except ValueError:
206-
return ret_error("ISBN has to be Number")
211+
return ret_error("ISBN has to be a Number")
207212

208213
if get_media_id(title):
209214
return ret_error("Media with this Title already exsists")
@@ -221,14 +226,15 @@ def ret_error(error: str):
221226

222227
author = get_author_id(author)
223228

224-
add_media_item(
229+
new_id = add_media_item(
225230
title=title,
226231
author_id=author,
227232
age_limit=age_limit,
228233
media_type_id=media_type,
229234
isbn=isbn,
230235
)
231236

237+
current_app.logger.info(f"{session['email']} Added media {title} with id {new_id}")
232238
return redirect(url_for("panel_bluep.staff_bluep.staff_panel_addremove"))
233239

234240

@@ -255,8 +261,9 @@ def add_author():
255261
)
256262
)
257263

258-
add_author_to_db(author)
264+
new_id = add_author_to_db(author)
259265

266+
current_app.logger.info(f"{session['email']} Added author with id {new_id}")
260267
return redirect(url_for("panel_bluep.staff_bluep.staff_panel_addremove"))
261268

262269

@@ -284,4 +291,7 @@ def remove_media():
284291
)
285292

286293
delete_media(media_id)
294+
current_app.logger.info(
295+
f"{session['email']} Removed media {media} with id {media_id}"
296+
)
287297
return redirect(url_for("panel_bluep.staff_bluep.staff_panel_addremove"))

library_db/routes/panel/user/user.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
request,
99
abort,
1010
Response,
11+
current_app,
1112
)
1213

1314

@@ -78,4 +79,5 @@ def delete_user():
7879
if pwdhash != md5(password.encode()).hexdigest():
7980
return abort(Response("Wrong Password", 401))
8081

82+
current_app.logger(f"{session['email']} Deleted user with email {session['email']}")
8183
return redirect(url_for("auth_bluep.login", next="/me/profile"))

library_db/utils/db_utils.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def estimate_return_date(media_id: int) -> date | None:
239239
return deadline.date()
240240

241241

242-
def borrow_book(media_id: int, user_id: int):
242+
def borrow_media(media_id: int, user_id: int):
243243
statement = """
244244
INSERT INTO borrowings (media_id, user_id, borrow_date)
245245
VALUES (?, ?, ?)
@@ -351,8 +351,8 @@ def author_exsists(name: str) -> bool:
351351

352352

353353
def add_media_item(
354-
title: str, author_id: int, age_limit: int, media_type_id: int, isbn: int = None
355-
):
354+
title: str, author_id: int, age_limit: int, media_type_id: int, isbn: int | None = None
355+
) -> int | None:
356356
statement = """
357357
INSERT INTO media (
358358
title, media_type_id,
@@ -367,6 +367,8 @@ def add_media_item(
367367

368368
con.commit()
369369

370+
return cur.lastrowid
371+
370372

371373
def get_media_type_id(media_type: str) -> int | None:
372374
cur = con.cursor()
@@ -393,12 +395,14 @@ def get_media_id(title: str) -> int | None:
393395
return res[0]
394396

395397

396-
def add_author_to_db(name: str):
398+
def add_author_to_db(name: str) -> int | None:
397399
cur = con.cursor()
398400
cur.execute("""INSERT INTO authors (name) VALUES(?)""", (name,))
399401

400402
con.commit()
401403

404+
return cur.lastrowid
405+
402406

403407
def delete_media(media_id: int):
404408
cur = con.cursor()

0 commit comments

Comments
 (0)