forked from Ugric/Komodo-Hub
started working on activities page
This commit is contained in:
1 parent
159af0ac98
commit
31db14f904
4 files changed
+169
-1
No files matched your search
@@ -294,9 +294,77 @@ def init_programs_database():
|
||||
""")
|
||||
print("Programs database tables initialised.")
|
||||
|
||||
def init_activities_database():
|
||||
activities_list = [
|
||||
{
|
||||
"title": "Build a Bird Feeder",
|
||||
"description": "Create a bird feeder using recycled materials.",
|
||||
"species": "Bird Conservation",
|
||||
"due_date": "3 days",
|
||||
"difficulty": "Easy"
|
||||
},
|
||||
{
|
||||
"title": "Plant a Tree",
|
||||
"description": "Plant a tree in your garden or local area to help restore natural habitats and support wildlife.",
|
||||
"species": "Habitat Restoration",
|
||||
"due_date": "5 days",
|
||||
"difficulty": "Medium"
|
||||
},
|
||||
{
|
||||
"title": "Organise a Conservation Awareness Campaign",
|
||||
"description": "Plan and deliver a campaign to raise awareness about endangered species.",
|
||||
"species": "Education & Conservation",
|
||||
"due_date": "2 weeks",
|
||||
"difficulty": "Hard"
|
||||
}
|
||||
]
|
||||
|
||||
with get_db() as conn:
|
||||
# Create activities table if it doesn't exist
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS activities (
|
||||
activity_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT,
|
||||
species TEXT,
|
||||
due_date TEXT,
|
||||
difficulty TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
print("Activities table created/found.")
|
||||
|
||||
# Insert activities if not already in table
|
||||
for activity in activities_list:
|
||||
exists = conn.execute(
|
||||
"SELECT activity_id FROM activities WHERE title = ?",
|
||||
(activity["title"],)
|
||||
).fetchone()
|
||||
if exists:
|
||||
print(f" SKIP {activity['title']} (already exists)")
|
||||
continue
|
||||
|
||||
conn.execute("""
|
||||
INSERT INTO activities
|
||||
(title, description, species, due_date, difficulty, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""", (
|
||||
activity["title"],
|
||||
activity["description"],
|
||||
activity["species"],
|
||||
activity["due_date"],
|
||||
activity["difficulty"],
|
||||
datetime.now(),
|
||||
))
|
||||
print(f" ADD {activity['title']}")
|
||||
print("Activities seeding complete.")
|
||||
|
||||
|
||||
|
||||
init_database()
|
||||
init_accounts_database()
|
||||
init_classes_database()
|
||||
init_programs_database()
|
||||
init_articles()
|
||||
init_activities_database()
|
||||
register_user("admin", "admin@komodohub.org", "admin", "admin")
|
||||
@@ -68,4 +68,4 @@ def handle_bad_request(e):
|
||||
import_pages("routes", app)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=3000, debug=True)
|
||||
app.run(host="0.0.0.0", port=3001, debug=True)
|
||||
@@ -0,0 +1,34 @@
|
||||
from flask import render_template, Blueprint, g, request, redirect, url_for
|
||||
from database.db_connection import get_db
|
||||
|
||||
page = Blueprint('activities', __name__, url_prefix='/activities')
|
||||
|
||||
|
||||
@page.route('/', methods=['GET', 'POST'])
|
||||
def home():
|
||||
# Handle admin creating activity
|
||||
if request.method == 'POST':
|
||||
if g.user and g.user["account_type"] == "admin":
|
||||
with get_db() as conn:
|
||||
conn.execute("""
|
||||
INSERT INTO activities
|
||||
(title, description, species, due_date, difficulty)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""", (
|
||||
request.form['title'],
|
||||
request.form['description'],
|
||||
request.form['species'],
|
||||
request.form['due_date'],
|
||||
request.form['difficulty']
|
||||
))
|
||||
|
||||
return redirect(url_for('activities.home'))
|
||||
|
||||
# GET: load activities from DB
|
||||
with get_db() as conn:
|
||||
activities = conn.execute("SELECT * FROM activities").fetchall()
|
||||
|
||||
return render_template(
|
||||
'activities/activities.jinja',
|
||||
activities=activities
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
{% extends "base.jinja" %}
|
||||
{% block title %}Activities{% endblock %}
|
||||
{% block content %}
|
||||
{% from 'button.jinja' import button %}
|
||||
|
||||
{% block head %}
|
||||
<style>
|
||||
.activity-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 30px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.activity-card {
|
||||
background: #0b5d2a;
|
||||
padding: 25px;
|
||||
border-radius: 12px;
|
||||
width: 300px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
<section style="padding: 50px 20px; text-align: center;">
|
||||
<h1>Activities</h1>
|
||||
|
||||
<!-- Activities List -->
|
||||
<div class="activity-container">
|
||||
{% for activity in activities %}
|
||||
<div class="activity-card">
|
||||
<h3>{{ activity.title }}</h3>
|
||||
<p>{{ activity.description }}</p>
|
||||
<p><strong>Category:</strong> {{ activity.species }}</p>
|
||||
<p><strong>Due:</strong> {{ activity.due_date }}</p>
|
||||
<p><strong>Difficulty:</strong> {{ activity.difficulty }}</p>
|
||||
|
||||
{{ button(url='#', button_text='Start Activity', extra_classes='homepage-btn') }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ADMIN ONLY SECTION -->
|
||||
{% if g.user and g.user["account_type"] == "admin" %}
|
||||
<section style="padding: 50px 20px; text-align: center; background-color: #eee;">
|
||||
<h2>Create New Activity (Admin)</h2>
|
||||
|
||||
<form method="POST" class="activity-form">
|
||||
<input type="text" name="title" placeholder="Activity Title" required><br><br>
|
||||
|
||||
<textarea name="description" placeholder="Description" required></textarea><br><br>
|
||||
|
||||
<input type="text" name="species" placeholder="Species / Program" required><br><br>
|
||||
|
||||
<input type="text" name="due_date" placeholder="due_date"><br><br>
|
||||
|
||||
<input type="text" name="difficulty" placeholder="difficulty"><br><br>
|
||||
|
||||
<button type="submit" class="homepage-btn">Publish Activity</button>
|
||||
</form>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user