forked from Ugric/Komodo-Hub
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):
|
def add_species(english, latin, body, category, extinction_risk, image_id):
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
conn.execute("""
|
try:
|
||||||
INSERT INTO species (
|
conn.execute("""
|
||||||
species_english,
|
INSERT INTO species (
|
||||||
species_latin,
|
species_english,
|
||||||
body_text,
|
species_latin,
|
||||||
category,
|
body_text,
|
||||||
extinction_risk,
|
category,
|
||||||
created_at,
|
extinction_risk,
|
||||||
photoid
|
created_at,
|
||||||
|
photoid
|
||||||
|
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
""", (english, latin.lower(), body, category, extinction_risk, datetime.now(), image_id))
|
""", (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():
|
def get_all_species():
|
||||||
@@ -48,16 +51,6 @@ WHERE
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
return [dict(row) for row in rows]
|
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):
|
def delete_species(species_id):
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
conn.execute(
|
conn.execute(
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ def init_database():
|
|||||||
conn.execute("""
|
conn.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS species (
|
CREATE TABLE IF NOT EXISTS species (
|
||||||
species_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
species_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
species_english TEXT,
|
species_english TEXT UNIQUE,
|
||||||
species_latin TEXT,
|
species_latin TEXT,
|
||||||
body_text TEXT,
|
body_text TEXT,
|
||||||
category TEXT,
|
category TEXT,
|
||||||
|
|||||||
Binary file not shown.
@@ -14,7 +14,7 @@ def portal():
|
|||||||
@page.route("/", methods=["POST"])
|
@page.route("/", methods=["POST"])
|
||||||
def add_species_to_database():
|
def add_species_to_database():
|
||||||
try:
|
try:
|
||||||
eng_name = request.form["eng_name"].capitalize()
|
eng_name = request.form["eng_name"].title()
|
||||||
latin_name = request.form["latin_name"].capitalize()
|
latin_name = request.form["latin_name"].capitalize()
|
||||||
main_text = request.form["main_text"]
|
main_text = request.form["main_text"]
|
||||||
category = request.form["category"].capitalize()
|
category = request.form["category"].capitalize()
|
||||||
@@ -36,6 +36,8 @@ def add_species_to_database():
|
|||||||
"species_portal/species_portal_failed.jinja",
|
"species_portal/species_portal_failed.jinja",
|
||||||
error_information=error_information
|
error_information=error_information
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# now add editing functionality
|
||||||
|
|
||||||
|
|
||||||
@page.route("/delete/<species_english>", methods=["POST"])
|
@page.route("/delete/<species_english>", methods=["POST"])
|
||||||
|
|||||||
Reference in new issue
Block a user