forked from Ugric/Komodo-Hub
fix images not displaying when the database is cleared
This commit is contained in:
1 parent
fdfd653873
commit
ca221771ba
29 files changed
+59
-40
No files matched your search
@@ -97,7 +97,7 @@ def get_all_species():
|
|||||||
def get_species_by_name(species_english):
|
def get_species_by_name(species_english):
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
row = conn.execute(
|
row = conn.execute(
|
||||||
"SELECT * FROM species WHERE species_english = ?",
|
"SELECT * FROM species WHERE species_english = ? LIMIT 1",
|
||||||
(species_english,)
|
(species_english,)
|
||||||
).fetchone()
|
).fetchone()
|
||||||
return dict(row) if row else None
|
return dict(row) if row else None
|
||||||
@@ -105,7 +105,7 @@ def get_species_by_name(species_english):
|
|||||||
def get_species_by_id(species_id):
|
def get_species_by_id(species_id):
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
result = conn.execute(
|
result = conn.execute(
|
||||||
"SELECT * FROM species WHERE species_id = ?",
|
"SELECT * FROM species WHERE species_id = ? LIMIT 1",
|
||||||
(species_id,)
|
(species_id,)
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if result:
|
if result:
|
||||||
|
|||||||
+3
-2
@@ -122,14 +122,15 @@ def seed_species():
|
|||||||
continue
|
continue
|
||||||
conn.execute("""
|
conn.execute("""
|
||||||
INSERT INTO species
|
INSERT INTO species
|
||||||
(species_english, species_latin, body_text, category, extinction_risk, created_at)
|
(species_english, species_latin, body_text, category, extinction_risk, photoid, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
""", (
|
""", (
|
||||||
sp["species_english"],
|
sp["species_english"],
|
||||||
sp["species_latin"],
|
sp["species_latin"],
|
||||||
sp["body_text"],
|
sp["body_text"],
|
||||||
sp["category"],
|
sp["category"],
|
||||||
sp["extinction_risk"],
|
sp["extinction_risk"],
|
||||||
|
sp["photoid"],
|
||||||
datetime.now(),
|
datetime.now(),
|
||||||
))
|
))
|
||||||
print(f" ADD {sp['species_english']}")
|
print(f" ADD {sp['species_english']}")
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,8 +1,10 @@
|
|||||||
from flask import Flask, request, g
|
from flask import Flask, request, g, render_template
|
||||||
import os
|
import os
|
||||||
import importlib.util
|
import importlib.util
|
||||||
from database.db_init import init_database
|
from database.db_init import init_database
|
||||||
from database.db_commands import get_user_from_token
|
from database.db_commands import get_user_from_token
|
||||||
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
|
|
||||||
def import_pages(route, app):
|
def import_pages(route, app):
|
||||||
for root, _, files in os.walk(route):
|
for root, _, files in os.walk(route):
|
||||||
@@ -31,19 +33,39 @@ def import_pages(route, app):
|
|||||||
app.register_blueprint(module.page)
|
app.register_blueprint(module.page)
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='static', static_url_path='')
|
app = Flask(__name__, static_folder="static", static_url_path="")
|
||||||
|
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def load_user():
|
def load_user():
|
||||||
token = request.cookies.get("token")
|
token = request.cookies.get("token")
|
||||||
g.user = token and get_user_from_token(token)
|
g.user = token and get_user_from_token(token)
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_user():
|
def inject_user():
|
||||||
return {"user": g.user}
|
return {"user": g.user}
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def page_not_found(e):
|
||||||
|
return render_template(
|
||||||
|
"error.jinja",
|
||||||
|
extra_information=e,
|
||||||
|
), 404
|
||||||
|
|
||||||
|
@app.errorhandler(Exception)
|
||||||
|
def handle_bad_request(e):
|
||||||
|
print(e)
|
||||||
|
if isinstance(e, HTTPException):
|
||||||
|
return e
|
||||||
|
return render_template(
|
||||||
|
"error.jinja",
|
||||||
|
extra_information=e,
|
||||||
|
), 500
|
||||||
|
|
||||||
|
|
||||||
init_database()
|
init_database()
|
||||||
import_pages("routes", app)
|
import_pages("routes", app)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=3000, debug=True)
|
app.run(host="0.0.0.0", port=3000, debug=True)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from flask import render_template, Blueprint
|
from flask import render_template, Blueprint, send_from_directory
|
||||||
from database.db_commands import get_species_by_name
|
from database.db_commands import get_species_by_name, get_species_by_id
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
page = Blueprint("species_information", __name__)
|
page = Blueprint("species_information", __name__)
|
||||||
@@ -15,22 +15,20 @@ page = Blueprint("species_information", __name__)
|
|||||||
|
|
||||||
@page.route("/species/<species_english>")
|
@page.route("/species/<species_english>")
|
||||||
def data(species_english):
|
def data(species_english):
|
||||||
try:
|
database_entry = get_species_by_name(species_english)
|
||||||
database_entry = get_species_by_name(species_english)
|
if database_entry is None:
|
||||||
if database_entry is None:
|
raise TypeError(f"No species named '{species_english}' found in the database.")
|
||||||
raise TypeError(f"No species named '{species_english}' found in the database.")
|
return render_template(
|
||||||
return render_template(
|
"species_information/species_information.jinja",
|
||||||
"species_information/species_information.jinja",
|
english_name =(database_entry["species_english"]).capitalize(),
|
||||||
english_name =(database_entry["species_english"]).capitalize(),
|
latin_name =database_entry["species_latin"].capitalize(),
|
||||||
latin_name =database_entry["species_latin"].capitalize(),
|
main_text =database_entry["body_text"],
|
||||||
main_text =database_entry["body_text"],
|
category =database_entry["category"].capitalize(),
|
||||||
category =database_entry["category"].capitalize(),
|
extinction_risk =database_entry["extinction_risk"],
|
||||||
extinction_risk =database_entry["extinction_risk"],
|
photoid =database_entry["photoid"],
|
||||||
photoid =database_entry["photoid"],
|
species_id =str(database_entry["species_id"])
|
||||||
species_id =str(database_entry["species_id"])
|
)
|
||||||
)
|
|
||||||
except TypeError as error_information:
|
@page.route("/species/image/<photoid>")
|
||||||
return render_template(
|
def image(photoid):
|
||||||
"error.jinja",
|
return send_from_directory("database/images", photoid)
|
||||||
extra_information=error_information,
|
|
||||||
)
|
|
||||||
@@ -29,7 +29,7 @@ def species_update(species_id):
|
|||||||
|
|
||||||
if species_image and species_image.filename:
|
if species_image and species_image.filename:
|
||||||
image_id = str(uuid.uuid4())
|
image_id = str(uuid.uuid4())
|
||||||
species_image.save(f"static/images/species_database/{image_id}.jpg")
|
species_image.save(f"database/images/{image_id}")
|
||||||
|
|
||||||
update_species(species_id, eng_name, latin_name, main_text, category, extinction_risk)
|
update_species(species_id, eng_name, latin_name, main_text, category, extinction_risk)
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def add_species_to_database():
|
|||||||
image_id = ""
|
image_id = ""
|
||||||
if species_image:
|
if species_image:
|
||||||
image_id = str(uuid.uuid4())
|
image_id = str(uuid.uuid4())
|
||||||
species_image.save(f"static/images/species_database/{image_id}.jpg")
|
species_image.save(f"database/images/{image_id}")
|
||||||
print(category, extinction_risk)
|
print(category, extinction_risk)
|
||||||
add_species(eng_name, latin_name, main_text, category, extinction_risk, image_id)
|
add_species(eng_name, latin_name, main_text, category, extinction_risk, image_id)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
+3
-6
@@ -57,7 +57,7 @@ h6 {
|
|||||||
|
|
||||||
.content {
|
.content {
|
||||||
max-width: 2000px;
|
max-width: 2000px;
|
||||||
margin: 0 auto;
|
margin: 2rem auto;
|
||||||
padding: 0 1rem 1rem;
|
padding: 0 1rem 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ h6 {
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
background-color: var(--transparent);
|
background-color: var(--transparent);
|
||||||
backdrop-filter: blur(50px);
|
backdrop-filter: blur(15px);
|
||||||
height: var(--navbar-height);
|
height: var(--navbar-height);
|
||||||
min-height: 40px;
|
min-height: 40px;
|
||||||
padding: 0.5rem 1rem;
|
padding: 0.5rem 1rem;
|
||||||
@@ -75,6 +75,7 @@ h6 {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
z-index: 998;
|
z-index: 998;
|
||||||
|
max-height: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar .link_button {
|
.navbar .link_button {
|
||||||
@@ -174,10 +175,6 @@ h6 {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo::before {
|
|
||||||
content: "The Sovereign Bank of Libreland";
|
|
||||||
}
|
|
||||||
|
|
||||||
.welcome {
|
.welcome {
|
||||||
display: flex;
|
display: flex;
|
||||||
background-image: url("/1706110852106.jpg");
|
background-image: url("/1706110852106.jpg");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<a href="/species/{{ item['species_english'] }}" class="container-lite">
|
<a href="/species/{{ item['species_english'] }}" class="container-lite">
|
||||||
<h3 class="plain-white-text">{{ item['species_english'] }}</h3>
|
<h3 class="plain-white-text">{{ item['species_english'] }}</h3>
|
||||||
<div
|
<div
|
||||||
style="background-image: url('{{ url_for('static', filename='images/species_database/' ~ item['photoid'] ~ '.jpg') }}');" class="div-image">
|
style="background-image: url('{{ '/species/image/' ~ item['photoid'] }}');" class="div-image">
|
||||||
</div>
|
</div>
|
||||||
<p style="color: var(--text)">
|
<p style="color: var(--text)">
|
||||||
Main category: {{ item['category'] }}
|
Main category: {{ item['category'] }}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
{%for species in featured_species%}
|
{%for species in featured_species%}
|
||||||
<a href="/species/{{ species['species_english'] }}" class="container-lite">
|
<a href="/species/{{ species['species_english'] }}" class="container-lite">
|
||||||
<h3 class="plain-white-text">{{ species['species_english'] }}</h3>
|
<h3 class="plain-white-text">{{ species['species_english'] }}</h3>
|
||||||
<div style="background-image: url('images/species_database/{{ species['photoid'] }}.jpg');" class="div-image">
|
<div style="background-image: url('/species/image/{{ species['photoid'] }}');" class="div-image">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<a href="/admin">Admin</a>
|
<a href="/admin">Admin</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="/dashboard">Dashboard</a>
|
<a href="/dashboard">Dashboard</a>
|
||||||
|
<a href="/dashboard">Settings</a>
|
||||||
<a href="/logout">Logout</a>
|
<a href="/logout">Logout</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ button(url='/login', button_text='Login/Register', extra_classes='') }}
|
{{ button(url='/login', button_text='Login/Register', extra_classes='') }}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<h1>{{ english_name }}</h1>
|
<h1>{{ english_name }}</h1>
|
||||||
<h2><em>{{ latin_name }}</em></h2>
|
<h2><em>{{ latin_name }}</em></h2>
|
||||||
<p>Category: {{category}}</p>
|
<p>Category: {{category}}</p>
|
||||||
<img src="/images/species_database/{{ photoid }}.jpg" class="species-photo" style="max-width: 100%; height: auto; border-radius: inherit;">
|
<img src="/species/image/{{ photoid }}" class="species-photo" style="max-width: 100%; height: auto; border-radius: inherit;">
|
||||||
<p>This species is currently classed as: {{extinction_risk}}</p>
|
<p>This species is currently classed as: {{extinction_risk}}</p>
|
||||||
{% if extinction_risk == "Not Evaluated" %}
|
{% if extinction_risk == "Not Evaluated" %}
|
||||||
<img src="/images/extinction_risk/notevaluated.png" class="extinction-icon">
|
<img src="/images/extinction_risk/notevaluated.png" class="extinction-icon">
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<div style="display:flex;flex-direction: row;">
|
<div style="display:flex;flex-direction: row;">
|
||||||
<div class="container" style="height: fit-content; width:fit-content; text-align:center; max-width: 40%; padding:20px">
|
<div class="container" style="height: fit-content; width:fit-content; text-align:center; max-width: 40%; padding:20px">
|
||||||
<p> Current photo: </p>
|
<p> Current photo: </p>
|
||||||
<img src="/images/species_database/{{ sp['photoid'] }}.jpg" style="width: 100%; height: auto; margin: auto">
|
<img src="/species/image/{{ sp['photoid'] }}" style="width: 100%; height: auto; margin: auto">
|
||||||
</div>
|
</div>
|
||||||
<section id="hero" class="container">
|
<section id="hero" class="container">
|
||||||
<form action="{{ url_for('species_editor.species_update', species_id=species_id) }}" class="form" method="POST"
|
<form action="{{ url_for('species_editor.species_update', species_id=species_id) }}" class="form" method="POST"
|
||||||
|
|||||||
Reference in new issue
Block a user