mirror of
https://github.com/tiyn/container-critique.git
synced 2025-04-03 00:27:48 +02:00
src: database update for item
This commit is contained in:
parent
2110d22c02
commit
88b07dd8a0
@ -39,7 +39,7 @@ def gen_arch_string():
|
|||||||
entries.reverse()
|
entries.reverse()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
ident = entry[0]
|
ident = entry[0]
|
||||||
title = db.get_item_by_id(entry[1])[1]
|
title = db.get_item_by_id(entry[1]).name
|
||||||
year = entry[2]
|
year = entry[2]
|
||||||
rating = entry[4]
|
rating = entry[4]
|
||||||
username = db.get_user_by_id(entry[5]).name
|
username = db.get_user_by_id(entry[5]).name
|
||||||
@ -67,7 +67,7 @@ def gen_user_string(name):
|
|||||||
"""
|
"""
|
||||||
content_string = ""
|
content_string = ""
|
||||||
last_year = ""
|
last_year = ""
|
||||||
entries = db.get_entries_by_name(name)
|
entries = db.get_entries_by_user(name)
|
||||||
if entries is None:
|
if entries is None:
|
||||||
return ""
|
return ""
|
||||||
entries.sort(key=lambda y: y[1])
|
entries.sort(key=lambda y: y[1])
|
||||||
@ -76,7 +76,7 @@ def gen_user_string(name):
|
|||||||
entries.reverse()
|
entries.reverse()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
ident = entry[0]
|
ident = entry[0]
|
||||||
title = db.get_item_by_id(entry[1])[1]
|
title = db.get_item_by_id(entry[1]).name
|
||||||
year = entry[2]
|
year = entry[2]
|
||||||
rating = entry[4]
|
rating = entry[4]
|
||||||
username = db.get_user_by_id(entry[5]).name
|
username = db.get_user_by_id(entry[5]).name
|
||||||
@ -110,7 +110,7 @@ def gen_index_string():
|
|||||||
entries.reverse()
|
entries.reverse()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
ident = entry[0]
|
ident = entry[0]
|
||||||
title = db.get_item_by_id(entry[1])[1]
|
title = db.get_item_by_id(entry[1]).name
|
||||||
year = entry[2]
|
year = entry[2]
|
||||||
text = entry[3]
|
text = entry[3]
|
||||||
rating = entry[4]
|
rating = entry[4]
|
||||||
@ -142,13 +142,13 @@ def gen_stand_string(ident):
|
|||||||
entry = db.get_entry_by_id(ident)
|
entry = db.get_entry_by_id(ident)
|
||||||
content_string = ""
|
content_string = ""
|
||||||
if entry is not None:
|
if entry is not None:
|
||||||
ident = entry[0]
|
ident = entry.id
|
||||||
title = db.get_item_by_id(entry[1])[1]
|
title = db.get_item_by_id(entry.item_id).name
|
||||||
year = entry[2]
|
year = entry.date
|
||||||
text = entry[3]
|
text = entry.text
|
||||||
rating = entry[4]
|
rating = entry.rating
|
||||||
username = db.get_user_by_id(entry[5]).name
|
username = db.get_user_by_id(entry.user_id).name
|
||||||
reviewed = entry[6]
|
reviewed = entry.reviewed
|
||||||
content_string += "<h1>" + title + \
|
content_string += "<h1>" + title + \
|
||||||
" (" + year + ") "
|
" (" + year + ") "
|
||||||
content_string += rating_to_star(rating)
|
content_string += rating_to_star(rating)
|
||||||
@ -179,7 +179,7 @@ def get_rss_string():
|
|||||||
entries.reverse()
|
entries.reverse()
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
ident = entry[0]
|
ident = entry[0]
|
||||||
title = db.get_item_by_id(entry[1])[1]
|
title = db.get_item_by_id(entry[1]).name
|
||||||
year = entry[2]
|
year = entry[2]
|
||||||
text = entry[3]
|
text = entry[3]
|
||||||
rating = entry[4]
|
rating = entry[4]
|
||||||
|
@ -26,6 +26,28 @@ class User():
|
|||||||
def get_id(self):
|
def get_id(self):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
||||||
|
class Item():
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.id = None
|
||||||
|
|
||||||
|
def set_id(self, ident):
|
||||||
|
self.id = ident
|
||||||
|
|
||||||
|
class Entry():
|
||||||
|
|
||||||
|
def __init__(self, item_id, date, text, rating, user_id, reviewed):
|
||||||
|
self.item_id = item_id
|
||||||
|
self.date = date
|
||||||
|
self.text = text
|
||||||
|
self.rating = rating
|
||||||
|
self.user_id = user_id
|
||||||
|
self.reviewed = reviewed
|
||||||
|
|
||||||
|
def set_id(self, ident):
|
||||||
|
self.id = ident
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
|
||||||
@ -118,9 +140,13 @@ class Database:
|
|||||||
crs = db.cursor()
|
crs = db.cursor()
|
||||||
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE + " WHERE id = ?"
|
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE + " WHERE id = ?"
|
||||||
crs.execute(query, (ident, ))
|
crs.execute(query, (ident, ))
|
||||||
return crs.fetchone()
|
fetched = crs.fetchone()
|
||||||
|
if fetched is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return self.db_to_entry(*fetched)
|
||||||
|
|
||||||
def get_entries_by_name(self, name):
|
def get_entries_by_user(self, name):
|
||||||
db = self.connect()
|
db = self.connect()
|
||||||
crs = db.cursor()
|
crs = db.cursor()
|
||||||
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE + \
|
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE + \
|
||||||
@ -134,7 +160,11 @@ class Database:
|
|||||||
crs = db.cursor()
|
crs = db.cursor()
|
||||||
query = "SELECT * FROM " + self.ITEM_TABLE_FILE + " WHERE id = ?"
|
query = "SELECT * FROM " + self.ITEM_TABLE_FILE + " WHERE id = ?"
|
||||||
crs.execute(query, (ident, ))
|
crs.execute(query, (ident, ))
|
||||||
return crs.fetchone()
|
fetched = crs.fetchone()
|
||||||
|
if fetched is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return self.db_to_item(*fetched)
|
||||||
|
|
||||||
def get_user_by_id(self, ident):
|
def get_user_by_id(self, ident):
|
||||||
db = self.connect()
|
db = self.connect()
|
||||||
@ -162,3 +192,13 @@ class Database:
|
|||||||
user = User(name, pass_hash)
|
user = User(name, pass_hash)
|
||||||
user.set_id(ident)
|
user.set_id(ident)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
def db_to_item(self, ident, name):
|
||||||
|
item = Item(name)
|
||||||
|
item.set_id(ident)
|
||||||
|
return item
|
||||||
|
|
||||||
|
def db_to_entry(self, ident, item_id, date, text, rating, user_id, reviewed):
|
||||||
|
entry = Entry(item_id, date, text, rating, user_id, reviewed)
|
||||||
|
entry.set_id(ident)
|
||||||
|
return entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user