04/24 Fixed bulk import check for duplicate
This commit is contained in:
@@ -445,6 +445,42 @@ def get_all_websites():
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_existing_website_urls() -> set:
|
||||
"""Return a set of normalised (lowercased, stripped) URLs already in the DB.
|
||||
Used by the bulk import dialog to detect duplicates before inserting.
|
||||
Includes both active and inactive websites so re-importing a soft-deleted
|
||||
site is also flagged rather than silently creating a second record.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = get_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT url FROM websites")
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
return {(r[0] or "").strip().lower() for r in rows}
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_existing_website_names() -> set:
|
||||
"""Return a set of normalised (lowercased, stripped) names already in the DB.
|
||||
Used alongside get_existing_website_urls() for duplicate detection.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = get_connection()
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT name FROM websites")
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
return {(r[0] or "").strip().lower() for r in rows}
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_website_by_id(website_id: int):
|
||||
conn = None
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user