Fixed all pep8 warnings
This commit is contained in:
@ -30,7 +30,7 @@ class CategoryController(DatabaseController):
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row == None:
|
||||
if row is None:
|
||||
return None
|
||||
|
||||
params = dict(zip(self.FIELDS, row))
|
||||
@ -44,7 +44,7 @@ class CategoryController(DatabaseController):
|
||||
)
|
||||
rows = cursor.fetchall()
|
||||
|
||||
if rows == None:
|
||||
if rows is None:
|
||||
return None
|
||||
|
||||
categories = list()
|
||||
|
@ -17,8 +17,8 @@ class DatabaseController(ABC):
|
||||
def __init__(self):
|
||||
self._conn = None
|
||||
try:
|
||||
# Creates a connection and specifies a flag to parse all types back down into
|
||||
# Python declared types e.g. date & time
|
||||
# Creates a connection and specifies a flag to parse all types
|
||||
# back down into Python declared types e.g. date & time
|
||||
self._conn = sqlite3.connect(
|
||||
self.__sqlitefile, detect_types=sqlite3.PARSE_DECLTYPES)
|
||||
except sqlite3.Error as e:
|
||||
@ -28,10 +28,10 @@ class DatabaseController(ABC):
|
||||
print(e)
|
||||
|
||||
def __del__(self):
|
||||
if self._conn != None:
|
||||
if self._conn is not None:
|
||||
self._conn.close()
|
||||
|
||||
""" Takes a dictionary of fields and returns the object
|
||||
""" Takes a dictionary of fields and returns the object
|
||||
with those fields populated """
|
||||
|
||||
def new_instance(self, of: type, with_fields: Mapping[str, Any]):
|
||||
|
@ -22,7 +22,11 @@ class ProductController(DatabaseController):
|
||||
]
|
||||
|
||||
self._conn.execute(
|
||||
"INSERT INTO Products (name, image, description, cost, categoryID, sellerID, postedDate, quantityAvailable) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"""
|
||||
INSERT INTO Products
|
||||
(name, image, description, cost, categoryID,
|
||||
sellerID, postedDate, quantityAvailable)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
params
|
||||
)
|
||||
self._conn.commit()
|
||||
@ -38,7 +42,7 @@ class ProductController(DatabaseController):
|
||||
)
|
||||
rows = cursor.fetchmany()
|
||||
|
||||
if rows == None:
|
||||
if rows is None:
|
||||
return None
|
||||
|
||||
products = list()
|
||||
@ -51,16 +55,17 @@ class ProductController(DatabaseController):
|
||||
|
||||
return products
|
||||
|
||||
def read_all(self, category: str = "", search_term: str = "") -> list[Product] | None:
|
||||
def read_all(self, category: str = "",
|
||||
search_term: str = "") -> list[Product] | None:
|
||||
params = [
|
||||
"%" + category + "%",
|
||||
"%" + search_term + "%"
|
||||
]
|
||||
|
||||
cursor = self._conn.execute(
|
||||
"""SELECT * FROM Products
|
||||
INNER JOIN Categories ON Products.categoryID = Categories.id
|
||||
WHERE Categories.name LIKE ?
|
||||
"""SELECT * FROM Products
|
||||
INNER JOIN Categories ON Products.categoryID = Categories.id
|
||||
WHERE Categories.name LIKE ?
|
||||
AND Products.name LIKE ?
|
||||
""",
|
||||
params
|
||||
|
@ -23,7 +23,9 @@ class UserController(DatabaseController):
|
||||
]
|
||||
|
||||
self._conn.execute(
|
||||
"INSERT INTO Users (username, password, first_name, last_name, email, phone, role) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
"""INSERT INTO Users
|
||||
(username, password, first_name, last_name, email, phone, role)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
params
|
||||
)
|
||||
self._conn.commit()
|
||||
@ -39,7 +41,7 @@ class UserController(DatabaseController):
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row != None:
|
||||
if row is not None:
|
||||
params = dict(zip(self.FIELDS, row))
|
||||
|
||||
# Is user a seller
|
||||
@ -63,7 +65,7 @@ class UserController(DatabaseController):
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
|
||||
if row != None:
|
||||
if row is not None:
|
||||
params = dict(zip(self.FIELDS, row))
|
||||
|
||||
# Is user a seller
|
||||
|
Reference in New Issue
Block a user