diff --git a/src/app.py b/src/app.py index 1d7d1af..0a3a6b8 100644 --- a/src/app.py +++ b/src/app.py @@ -1,5 +1,4 @@ -from flask import Flask, flash, make_response, render_template, redirect, \ - abort, url_for, request +from flask import Flask, flash, render_template, redirect, abort, url_for from flask_ckeditor import CKEditor from flask_login import current_user, login_user, LoginManager, logout_user, \ login_required @@ -8,7 +7,7 @@ import os import config import content as con_gen -from database import Database, User +from database import Database from forms import LoginForm, RegisterForm, WriteForm @@ -109,11 +108,9 @@ def register(): if form.validate_on_submit(): user = db.get_user_by_name(form.username.data) if user is None: - user = User(form.username.data) - user.set_password(form.password.data) - ident = db.insert_user(user) + ident = db.insert_user(form.username.data, form.password.data) if ident is not None: - user.set_id(ident) + user = db.get_user_by_id(ident) login_user(user) return redirect(url_for("index")) flash("An error occured during registration.") @@ -139,7 +136,7 @@ def write_entry(): def delete_entry(ident): if not current_user.is_authenticated: return redirect(url_for("index")) - if current_user.id == db.get_entry_by_id(ident)[5]: + if current_user.id == db.get_entry_by_id(ident).user_id: db.delete_entry(ident) return redirect(url_for("index")) diff --git a/src/content.py b/src/content.py index 42cc593..467e34e 100644 --- a/src/content.py +++ b/src/content.py @@ -33,16 +33,16 @@ def gen_arch_string(): entries = db.get_entries() if entries is None: return "" - entries.sort(key=lambda y: y[1]) + entries.sort(key=lambda y: db.get_item_by_id(y.item_id).name) entries.reverse() - entries.sort(key=lambda y: y[2]) + entries.sort(key=lambda y: y.date) entries.reverse() for entry in entries: - ident = entry[0] - title = db.get_item_by_id(entry[1]).name - year = entry[2] - rating = entry[4] - username = db.get_user_by_id(entry[5]).name + ident = entry.id + title = db.get_item_by_id(entry.item_id).name + year = entry.date + rating = entry.rating + username = db.get_user_by_id(entry.user_id).name if year != last_year: if last_year != "": content_string += "\n" @@ -70,16 +70,16 @@ def gen_user_string(name): entries = db.get_entries_by_user(name) if entries is None: return "" - entries.sort(key=lambda y: y[1]) + entries.sort(key=lambda y: db.get_item_by_id(y.item_id).name) entries.reverse() - entries.sort(key=lambda y: y[2]) + entries.sort(key=lambda y: y.date) entries.reverse() for entry in entries: - ident = entry[0] - title = db.get_item_by_id(entry[1]).name - year = entry[2] - rating = entry[4] - username = db.get_user_by_id(entry[5]).name + ident = entry.id + title = db.get_item_by_id(entry.item_id).name + year = entry.date + rating = entry.rating + username = db.get_user_by_id(entry.user_id).name if year != last_year: if last_year != "": content_string += "\n" @@ -109,13 +109,13 @@ def gen_index_string(): return "" entries.reverse() for entry in entries: - ident = entry[0] - title = db.get_item_by_id(entry[1]).name - year = entry[2] - text = entry[3] - rating = entry[4] - username = db.get_user_by_id(entry[5]).name - reviewed = entry[6] + ident = entry.id + title = db.get_item_by_id(entry.item_id).name + year = entry.date + text = entry.text + rating = entry.rating + username = db.get_user_by_id(entry.user_id).name + reviewed = entry.reviewed content_string += "