article library page and individual articles working

This commit is contained in:
TussockyJoker committed 2026-04-06 05:29:34 +01:00
1 parent 8dc5dacd09
commit 23884c2bad
8 files changed
+118 -6

No files matched your search

+10
View File
@@ -92,6 +92,16 @@ def get_all_species():
with get_db() as conn:
rows = conn.execute("SELECT * FROM species").fetchall()
return [dict(row) for row in rows]
def get_all_articles():
with get_db() as conn:
rows = conn.execute("SELECT * FROM articles").fetchall()
return [dict(row) for row in rows]
def get_article_by_id(id):
with get_db() as conn:
row = conn.execute("SELECT * FROM articles WHERE article_id = ? LIMIT 1", (id,)).fetchone()
return dict(row) if row else None
def get_species_by_name(species_english):
+32
View File
@@ -0,0 +1,32 @@
from flask import render_template, Blueprint, send_from_directory
from database.db_commands import get_article_by_id, get_species_by_id
import sqlite3
page = Blueprint("article", __name__)
# this page works by taking the species name (in english) from the url and using that to read the database.
# Because of this we are able to create one page and simply generate links based on the contents of the database
# i.e. we can create a button with the hyperlink /species/iguana and this will
# allow the user to view the information about the species
# please be aware the page expects a .jpg at:
# /static/images/species_database/{{photoid}}.jpg but this will be generated automatically
# so long as you use the species_portal or species editor pages I created - CS
@page.route("/articles/<article_id>")
def data(article_id):
database_entry = get_article_by_id(article_id)
if database_entry is None:
raise TypeError(f"No species named '{species_english}' found in the database.")
return render_template(
"library/article.jinja",
article_id =database_entry["article_id" ].capitalize(),
title =database_entry["title" ].capitalize(),
subtitle =database_entry["subtitle" ],
main_text =database_entry["main_text" ].capitalize(),
author =database_entry["author" ],
publish_date=database_entry["publish_date" ])
@page.route("/species/image/<photoid>")
def image(photoid):
return send_from_directory("database/images", photoid)
+30
View File
@@ -0,0 +1,30 @@
from flask import render_template, Blueprint, request
import configparser
from database.db_commands import get_all_articles, search_species, get_species_by_name
from utilities.featured_species import featured_species_function
config = configparser.ConfigParser()
page = Blueprint("articles", __name__, url_prefix="/articles")
# article library page
@page.route("")
def all_species():
article_list = get_all_articles()
article_list = sorted(article_list, key=lambda sp: sp["title"])
for sp in article_list:
print(sp['title'])
return render_template("library/library.jinja", articles=article_list)
# search page
@page.route("/search")
def search():
query = request.args.get("search-query")
results = search_species(query)
print(results)
return render_template("/species/species_search.jinja", results=results, query=query)
+3 -2
View File
@@ -22,9 +22,10 @@
<section class="species-grid">
{% for item in items %}
<a href="/articles/{{ item['article_id'] }}" class="container-lite">
<h3 class="plain-white-text">{{ item['article_title'] }}</h3>
<h3 class="plain-white-text">{{ item['title'] }}</h3>
<p style="color: var(--text)">
Main category: {{ item['category'] }}
Main category: {{ item['author'] }}
Date published: {{ item["publish_date"] }}
</p>
</a>
+23
View File
@@ -0,0 +1,23 @@
{% extends "base.jinja" %}
{% block title %}{{ english_name }} {% endblock %}
{% block head %}
{% endblock %}
{% block content %}
{% from 'button.jinja' import button %}
<div class="species-layout">
<section id="summary" style="padding: 10px 20px; text-align: center; margin-top:1rem" class="container">
<h1>{{ title }}</h1>
<h2><em>{{ subtitle }}</em></h2>
<p>Category: {{author}}</p>
<p>Category: {{publish_date}}</p>
</section>
<section id="info" style="padding: 10px 20px; text-align: center;" class="container">
<p>{{ main_text }}</p>
</section>
</div>
{# this button should only be visible to certain account types #}
{# <div style="text-align: right;">
{{ button(url='/species/editor/'+species_id, button_text='Edit Species') }}
</div> #}
{% endblock %}
+16
View File
@@ -0,0 +1,16 @@
{% extends "base.jinja" %}
{% block title %}Species Database{% endblock %}
{% block head %}
{% endblock %}
{% block content %}
{% from 'button.jinja' import button %}
{% from 'display_items.jinja' import display_all_articles %}
{% from 'search_bar.jinja' import search_bar%}
<section class="title">
Article Library
</section>
{# All Articles #}
{{search_bar("/articles/search", "")}}
<h2 style="text-align: center; margin-top: 30px;">All Articles</h2>
{{display_all_articles(articles)}}
{% endblock %}
+2 -2
View File
@@ -5,7 +5,7 @@
{% block content %}
{% from 'button.jinja' import button %}
{% from 'featured_species.jinja' import featured_species_section %}
{% from 'display_items.jinja' import display_all_items %}
{% from 'display_items.jinja' import display_all_species %}
{% from 'search_bar.jinja' import search_bar%}
<section class="title">
Species Database
@@ -16,5 +16,5 @@ Species Database
{# All Species #}
{{search_bar("/species/search", "")}}
<h2 style="text-align: center; margin-top: 30px;">All Species</h2>
{{display_all_items(species)}}
{{display_all_species(species)}}
{% endblock %}
+2 -2
View File
@@ -4,12 +4,12 @@
{% endblock %}
{% block content %}
{% from 'button.jinja' import button %}
{% from 'display_items.jinja' import display_all_items %}
{% from 'display_items.jinja' import display_all_species %}
{% from 'search_bar.jinja' import search_bar%}
<section class="title">
Species Database
</section>
{# All Species #}
{{search_bar("/species/search", query)}}
{{display_all_items(results)}}
{{display_all_species(results)}}
{% endblock %}