can no longer have duplicate species in species database
This commit is contained in:
1 parent
9fd560f6a8
commit
1c7bf3c37e
5 files changed
+19
-24
No files matched your search
Whitespace-only changes.
+15
-22
@@ -4,19 +4,22 @@ from database.db_connection import get_db
|
||||
|
||||
def add_species(english, latin, body, category, extinction_risk, image_id):
|
||||
with get_db() as conn:
|
||||
conn.execute("""
|
||||
INSERT INTO species (
|
||||
species_english,
|
||||
species_latin,
|
||||
body_text,
|
||||
category,
|
||||
extinction_risk,
|
||||
created_at,
|
||||
photoid
|
||||
try:
|
||||
conn.execute("""
|
||||
INSERT INTO species (
|
||||
species_english,
|
||||
species_latin,
|
||||
body_text,
|
||||
category,
|
||||
extinction_risk,
|
||||
created_at,
|
||||
photoid
|
||||
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""", (english, latin.lower(), body, category, extinction_risk, datetime.now(), image_id))
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""", (english.title(), latin.lower(), body, category, extinction_risk, datetime.now(), image_id))
|
||||
except:
|
||||
raise ValueError("This species already exists in the database, would you like to edit it?")
|
||||
|
||||
|
||||
def get_all_species():
|
||||
@@ -48,16 +51,6 @@ WHERE
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
|
||||
def get_species_by_name(species_english):
|
||||
with get_db() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT * FROM species WHERE species_english = ?",
|
||||
(species_english,)
|
||||
).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
|
||||
def delete_species(species_id):
|
||||
with get_db() as conn:
|
||||
conn.execute(
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ def init_database():
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS species (
|
||||
species_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
species_english TEXT,
|
||||
species_english TEXT UNIQUE,
|
||||
species_latin TEXT,
|
||||
body_text TEXT,
|
||||
category TEXT,
|
||||
|
||||
Binary file not shown.
@@ -14,7 +14,7 @@ def portal():
|
||||
@page.route("/", methods=["POST"])
|
||||
def add_species_to_database():
|
||||
try:
|
||||
eng_name = request.form["eng_name"].capitalize()
|
||||
eng_name = request.form["eng_name"].title()
|
||||
latin_name = request.form["latin_name"].capitalize()
|
||||
main_text = request.form["main_text"]
|
||||
category = request.form["category"].capitalize()
|
||||
@@ -36,6 +36,8 @@ def add_species_to_database():
|
||||
"species_portal/species_portal_failed.jinja",
|
||||
error_information=error_information
|
||||
)
|
||||
|
||||
# now add editing functionality
|
||||
|
||||
|
||||
@page.route("/delete/<species_english>", methods=["POST"])
|
||||
|
||||
Reference in new issue
Block a user