a ton of fun happened, refactored alot
This commit is contained in:
195
app/__init__.py
195
app/__init__.py
@ -1,120 +1,145 @@
|
||||
# app/__init__.py
|
||||
# File: app/__init__.py
|
||||
|
||||
import os
|
||||
import json
|
||||
import glob
|
||||
import importlib
|
||||
import importlib.util
|
||||
import time
|
||||
|
||||
from flask import Flask,request
|
||||
from flask import Flask, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from dotenv import load_dotenv
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
|
||||
# ─── Load .env ────────────────────────────────────────────────────────────────
|
||||
dotenv_path = find_dotenv()
|
||||
if dotenv_path:
|
||||
load_dotenv(dotenv_path, override=True)
|
||||
|
||||
# Load environment variables from .env or system
|
||||
load_dotenv()
|
||||
|
||||
# ─── Initialize core extensions ─────────────────────────────────────────────────
|
||||
# ─── Core extensions ───────────────────────────────────────────────────────────
|
||||
db = SQLAlchemy()
|
||||
migrate = Migrate()
|
||||
login_manager = LoginManager()
|
||||
csrf = CSRFProtect()
|
||||
|
||||
from plugins.media.routes import generate_image_url # Import it here
|
||||
|
||||
# ─── Template helper (still in core) ──────────────────────────────────────────
|
||||
from plugins.media.routes import generate_image_url # noqa: E402
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
# ─── Configure Flask ────────────────────────────────────────────────────────
|
||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
app = Flask(
|
||||
__name__,
|
||||
static_folder=os.path.join(project_root, 'static'),
|
||||
static_url_path='/static'
|
||||
)
|
||||
app.config.from_object('app.config.Config')
|
||||
|
||||
# ─── Initialize extensions with the app ───────────────────────────────────────
|
||||
# ─── Init extensions ───────────────────────────────────────────────────────
|
||||
csrf.init_app(app)
|
||||
db.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
login_manager.init_app(app)
|
||||
login_manager.login_view = 'auth.login'
|
||||
|
||||
# ─── Register user_loader for Flask-Login ───────────────────────────────────
|
||||
from plugins.auth.models import User
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
try:
|
||||
return User.query.get(int(user_id))
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
# ─── Register error handlers ─────────────────────────────────────────────────
|
||||
from .errors import bp as errors_bp
|
||||
# ─── Core routes & errors ───────────────────────────────────────────────────
|
||||
from .errors import bp as errors_bp # noqa: E402
|
||||
app.register_blueprint(errors_bp)
|
||||
from .routes import init_app as register_core_routes # noqa: E402
|
||||
register_core_routes(app)
|
||||
app.logger.info("✔️ Registered core routes")
|
||||
|
||||
# ─── 1) Auto‐import plugin models by their package names ─────────────────────
|
||||
# This ensures that every plugins/<plugin>/models.py is imported exactly once
|
||||
plugin_model_paths = glob.glob(
|
||||
os.path.join(os.path.dirname(__file__), '..', 'plugins', '*', 'models.py')
|
||||
)
|
||||
for path in plugin_model_paths:
|
||||
# path looks like ".../plugins/plant/models.py"
|
||||
rel = path.split(os.sep)[-2] # e.g. "plant"
|
||||
pkg = f"plugins.{rel}.models" # e.g. "plugins.plant.models"
|
||||
# ─── JSON‐driven plugin loader ──────────────────────────────────────────────
|
||||
plugins_dir = os.path.join(project_root, 'plugins')
|
||||
for name in sorted(os.listdir(plugins_dir)):
|
||||
plugin_path = os.path.join(plugins_dir, name)
|
||||
manifest = os.path.join(plugin_path, 'plugin.json')
|
||||
if not os.path.isfile(manifest):
|
||||
continue
|
||||
|
||||
errors = []
|
||||
try:
|
||||
importlib.import_module(pkg)
|
||||
print(f"✅ (Startup) Loaded: {pkg}")
|
||||
meta = json.load(open(manifest))
|
||||
except Exception as e:
|
||||
print(f"❌ (Startup) Failed to load {pkg}: {e}")
|
||||
|
||||
# ─── 2) Auto‐discover & register plugin routes, CLI, entry‐points ────────────
|
||||
plugin_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'plugins'))
|
||||
for plugin in os.listdir(plugin_path):
|
||||
if plugin.endswith('.noload'):
|
||||
print(f"[⏭] Skipping plugin '{plugin}' (marked as .noload)")
|
||||
print(f"Plugin '{name}' 🛑 manifest load failed: {e}")
|
||||
continue
|
||||
|
||||
plugin_dir = os.path.join(plugin_path, plugin)
|
||||
if not os.path.isdir(plugin_dir):
|
||||
continue
|
||||
|
||||
# (a) Register routes.py
|
||||
route_file = os.path.join(plugin_dir, 'routes.py')
|
||||
if os.path.isfile(route_file):
|
||||
# 1) Import models
|
||||
for model_path in meta.get('models', []):
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location(f"plugins.{plugin}.routes", route_file)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
if hasattr(mod, 'bp'):
|
||||
app.register_blueprint(mod.bp, strict_slashes=False)
|
||||
print(f"✔️ Registered routes for plugin '{plugin}'")
|
||||
importlib.import_module(model_path)
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to load routes from plugin '{plugin}': {e}")
|
||||
errors.append(f"model import ({model_path}): {e}")
|
||||
|
||||
# (b) Register CLI and entry‐point
|
||||
init_file = os.path.join(plugin_dir, '__init__.py')
|
||||
plugin_json = os.path.join(plugin_dir, 'plugin.json')
|
||||
if os.path.isfile(init_file):
|
||||
# 1.b) user_loader hook
|
||||
ul = meta.get('user_loader')
|
||||
if ul:
|
||||
try:
|
||||
cli_module = importlib.import_module(f"plugins.{plugin}")
|
||||
if hasattr(cli_module, 'register_cli'):
|
||||
cli_module.register_cli(app)
|
||||
print(f"✔️ Registered CLI for plugin '{plugin}'")
|
||||
if os.path.isfile(plugin_json):
|
||||
with open(plugin_json, 'r') as f:
|
||||
meta = json.load(f)
|
||||
entry = meta.get('entry_point')
|
||||
if entry and hasattr(cli_module, entry):
|
||||
getattr(cli_module, entry)(app)
|
||||
print(f"✔️ Ran entry point '{entry}' for plugin '{plugin}'")
|
||||
mod = importlib.import_module(ul['module'])
|
||||
fn = getattr(mod, ul['callable'])
|
||||
fn(app)
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to load CLI for plugin '{plugin}': {e}")
|
||||
errors.append(f"user_loader ({ul['module']}:{ul['callable']}): {e}")
|
||||
|
||||
# ─── Inject current year into templates ────────────────────────────────────────
|
||||
# 2) Register routes
|
||||
routes_cfg = meta.get('routes')
|
||||
if routes_cfg:
|
||||
try:
|
||||
mod = importlib.import_module(routes_cfg['module'])
|
||||
bp_obj = getattr(mod, routes_cfg['blueprint'])
|
||||
prefix = routes_cfg.get('url_prefix')
|
||||
app.register_blueprint(bp_obj, url_prefix=prefix, strict_slashes=False)
|
||||
except Exception as e:
|
||||
errors.append(f"routes ({routes_cfg['module']}): {e}")
|
||||
|
||||
# 3) Register CLI commands
|
||||
cli_cfg = meta.get('cli')
|
||||
if cli_cfg:
|
||||
try:
|
||||
mod = importlib.import_module(cli_cfg['module'])
|
||||
fn = getattr(mod, cli_cfg['callable'])
|
||||
app.cli.add_command(fn)
|
||||
except Exception as e:
|
||||
errors.append(f"cli ({cli_cfg['module']}:{cli_cfg['callable']}): {e}")
|
||||
|
||||
# 4) Template globals
|
||||
for tg in meta.get('template_globals', []):
|
||||
try:
|
||||
mod_name, fn_name = tg['callable'].rsplit('.', 1)
|
||||
mod = importlib.import_module(mod_name)
|
||||
fn = getattr(mod, fn_name)
|
||||
app.jinja_env.globals[tg['name']] = fn
|
||||
except Exception as e:
|
||||
errors.append(f"template_global ({tg}): {e}")
|
||||
|
||||
# 5) Subplugins (models + routes)
|
||||
for sp in meta.get('subplugins', []):
|
||||
for mp in sp.get('models', []):
|
||||
try:
|
||||
importlib.import_module(mp)
|
||||
except Exception as e:
|
||||
errors.append(f"subplugin model ({mp}): {e}")
|
||||
sp_rt = sp.get('routes')
|
||||
if sp_rt:
|
||||
try:
|
||||
mod = importlib.import_module(sp_rt['module'])
|
||||
bp_obj = getattr(mod, sp_rt['blueprint'])
|
||||
prefix = sp_rt.get('url_prefix')
|
||||
app.register_blueprint(bp_obj, url_prefix=prefix, strict_slashes=False)
|
||||
except Exception as e:
|
||||
errors.append(f"subplugin routes ({sp_rt['module']}): {e}")
|
||||
|
||||
# Final status
|
||||
if errors:
|
||||
print(f"Plugin '{name}' 🛑 failed to load: {'; '.join(errors)}")
|
||||
else:
|
||||
print(f"Plugin '{name}' ✔️ Loaded Successfully.")
|
||||
|
||||
# ─── Context processors, analytics, teardown ───────────────────────────────
|
||||
@app.context_processor
|
||||
def inject_current_year():
|
||||
from datetime import datetime
|
||||
return {'current_year': datetime.now().year}
|
||||
|
||||
@app.context_processor
|
||||
@ -127,17 +152,16 @@ def create_app():
|
||||
|
||||
@app.after_request
|
||||
def log_analytics(response):
|
||||
# import here to avoid circular at module‐load time
|
||||
from plugins.admin.models import AnalyticsEvent
|
||||
from plugins.admin.models import AnalyticsEvent # noqa: E402
|
||||
try:
|
||||
duration = time.time() - getattr(request, '_start_time', time.time())
|
||||
ev = AnalyticsEvent(
|
||||
method=request.method,
|
||||
path=request.path,
|
||||
status_code=response.status_code,
|
||||
response_time=duration,
|
||||
user_agent=request.headers.get('User-Agent'),
|
||||
referer=request.headers.get('Referer'),
|
||||
method = request.method,
|
||||
path = request.path,
|
||||
status_code = response.status_code,
|
||||
response_time = duration,
|
||||
user_agent = request.headers.get('User-Agent'),
|
||||
referer = request.headers.get('Referer'),
|
||||
accept_language=request.headers.get('Accept-Language'),
|
||||
)
|
||||
db.session.add(ev)
|
||||
@ -146,6 +170,11 @@ def create_app():
|
||||
db.session.rollback()
|
||||
return response
|
||||
|
||||
@app.teardown_appcontext
|
||||
def shutdown_session(exception=None):
|
||||
db.session.remove()
|
||||
|
||||
# ─── Keep the template helper exposed ──────────────────────────────────────
|
||||
app.jinja_env.globals['generate_image_url'] = generate_image_url
|
||||
|
||||
return app
|
||||
|
@ -1,45 +1,93 @@
|
||||
import os
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
|
||||
# CONFIG_DIR is your app package; go up one to the project root
|
||||
# ─── Load .env from project root or any parent ────────────────────────────────
|
||||
dotenv_path = find_dotenv()
|
||||
if dotenv_path:
|
||||
load_dotenv(dotenv_path, override=True)
|
||||
|
||||
# ─── Paths ────────────────────────────────────────────────────────────────────
|
||||
CONFIG_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
PROJECT_ROOT = os.path.dirname(CONFIG_DIR)
|
||||
|
||||
class Config:
|
||||
SECRET_KEY = os.environ['SECRET_KEY']
|
||||
MAX_CONTENT_LENGTH = int(
|
||||
os.environ.get('MAX_CONTENT_LENGTH', 20 * 1024 * 1024 * 1024)
|
||||
)
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
||||
# ─── Environment ─────────────────────────────────────────────────────────────
|
||||
ENV = (
|
||||
os.getenv('FLASK_ENV')
|
||||
or os.getenv('DOCKER_ENV')
|
||||
or 'production'
|
||||
).lower()
|
||||
|
||||
UPLOAD_FOLDER = os.path.join(PROJECT_ROOT, "static", "uploads")
|
||||
# ─── Secret Key ──────────────────────────────────────────────────────────────
|
||||
if ENV == 'production':
|
||||
SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
if not SECRET_KEY:
|
||||
raise RuntimeError(
|
||||
"SECRET_KEY environment variable not set! "
|
||||
"Generate one with `openssl rand -hex 32` and export it."
|
||||
)
|
||||
else:
|
||||
# dev/test: fall back to env or a random one
|
||||
SECRET_KEY = os.getenv('SECRET_KEY') or os.urandom(24).hex()
|
||||
|
||||
# MySQL connection parameters
|
||||
MYSQL_USER = os.environ['MYSQL_USER']
|
||||
MYSQL_PASSWORD = os.environ['MYSQL_PASSWORD']
|
||||
MYSQL_HOST = os.environ['MYSQL_HOST']
|
||||
MYSQL_PORT = int(os.environ.get('MYSQL_PORT', 3306))
|
||||
MYSQL_DATABASE = os.environ['MYSQL_DATABASE']
|
||||
# ─── Uploads ────────────────────────────────────────────────────────────────
|
||||
# Default to PROJECT_ROOT/static/uploads; if UPLOAD_FOLDER env is set, resolve relative to PROJECT_ROOT
|
||||
_env_upload = os.getenv('UPLOAD_FOLDER', '')
|
||||
if _env_upload:
|
||||
# if absolute, use directly; otherwise join to project root
|
||||
UPLOAD_FOLDER = _env_upload if os.path.isabs(_env_upload) else os.path.join(PROJECT_ROOT, _env_upload)
|
||||
else:
|
||||
UPLOAD_FOLDER = os.path.join(PROJECT_ROOT, "static", "uploads")
|
||||
|
||||
# Build the SQLAlchemy database URI
|
||||
SQLALCHEMY_DATABASE_URI = (
|
||||
MAX_CONTENT_LENGTH = int(os.getenv('MAX_CONTENT_LENGTH', 20 * 1024**3))
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
||||
|
||||
# ─── Celery ────────────────────────────────────────────────────────────────
|
||||
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
|
||||
if not CELERY_BROKER_URL:
|
||||
raise RuntimeError("CELERY_BROKER_URL environment variable not set!")
|
||||
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', CELERY_BROKER_URL)
|
||||
|
||||
# ─── MySQL ──────────────────────────────────────────────────────────────────
|
||||
MYSQL_USER = os.getenv('MYSQL_USER')
|
||||
MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD')
|
||||
if not MYSQL_PASSWORD:
|
||||
raise RuntimeError("MYSQL_PASSWORD environment variable not set!")
|
||||
MYSQL_HOST = os.getenv('MYSQL_HOST', 'db')
|
||||
MYSQL_PORT = int(os.getenv('MYSQL_PORT', 3306))
|
||||
MYSQL_DATABASE = os.getenv('MYSQL_DATABASE')
|
||||
if not MYSQL_DATABASE:
|
||||
raise RuntimeError("MYSQL_DATABASE environment variable not set!")
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = (
|
||||
f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}"
|
||||
f"@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
|
||||
)
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
# Optional toggles
|
||||
ENABLE_DB_SEEDING = os.environ.get('ENABLE_DB_SEEDING', '0') == '1'
|
||||
DOCKER_ENV = os.environ.get('FLASK_ENV', 'production')
|
||||
# ─── Cookies / Session ──────────────────────────────────────────────────────
|
||||
SESSION_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_HTTPONLY = True
|
||||
SESSION_COOKIE_SAMESITE = 'Lax'
|
||||
REMEMBER_COOKIE_SECURE = True
|
||||
REMEMBER_COOKIE_HTTPONLY = True
|
||||
REMEMBER_COOKIE_SAMESITE = 'Lax'
|
||||
PREFERRED_URL_SCHEME = 'https'
|
||||
|
||||
# Neo4j configuration
|
||||
# ─── Toggles ────────────────────────────────────────────────────────────────
|
||||
ENABLE_DB_SEEDING = os.getenv('ENABLE_DB_SEEDING', '0') == '1'
|
||||
DOCKER_ENV = os.getenv('DOCKER_ENV', 'production')
|
||||
|
||||
# ─── Neo4j ──────────────────────────────────────────────────────────────────
|
||||
NEO4J_URI = os.getenv('NEO4J_URI', 'bolt://neo4j:7687')
|
||||
NEO4J_USER = os.getenv('NEO4J_USER', 'neo4j')
|
||||
NEO4J_PASSWORD = os.getenv('NEO4J_PASSWORD', 'your_secure_password')
|
||||
NEO4J_PASSWORD = os.getenv('NEO4J_PASSWORD')
|
||||
if not NEO4J_PASSWORD:
|
||||
raise RuntimeError("NEO4J_PASSWORD environment variable not set!")
|
||||
|
||||
# Standard image size (for placeholders, etc.)
|
||||
# ─── Misc ──────────────────────────────────────────────────────────────────
|
||||
STANDARD_IMG_SIZE = tuple(
|
||||
map(int, os.getenv('STANDARD_IMG_SIZE', '300x200').split('x'))
|
||||
)
|
||||
|
||||
PLANT_CARDS_BASE_URL = "https://plant.cards"
|
||||
ALLOW_REGISTRATION = False
|
||||
ALLOW_REGISTRATION = False
|
||||
|
15
app/routes.py
Normal file
15
app/routes.py
Normal file
@ -0,0 +1,15 @@
|
||||
from flask import render_template
|
||||
|
||||
def init_app(app):
|
||||
"""
|
||||
Register core application routes directly on the Flask app:
|
||||
- GET / → home page
|
||||
- GET /health → health check
|
||||
"""
|
||||
@app.route('/')
|
||||
def home():
|
||||
return render_template('core/home.html')
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
return 'OK', 200
|
@ -7,6 +7,6 @@
|
||||
<body>
|
||||
<h1>400 – Bad Request</h1>
|
||||
<p>{{ error.description or "Sorry, we couldn’t understand that request." }}</p>
|
||||
<a href="{{ url_for('main.index') }}">Return home</a>
|
||||
<a href="{{ url_for('home') }}">Return home</a>
|
||||
</body>
|
||||
</html>
|
||||
|
34
app/templates/core/_media_macros.html
Normal file
34
app/templates/core/_media_macros.html
Normal file
@ -0,0 +1,34 @@
|
||||
{% macro render_media_list(media_list, thumb_width=150, current_user=None) -%}
|
||||
{% if media_list %}
|
||||
<div class="row">
|
||||
{% for media in media_list %}
|
||||
<div class="col-md-3 mb-4" data-media-id="{{ media.id }}">
|
||||
<div class="card shadow-sm">
|
||||
<img src="{{ url_for('media.serve', plugin=media.plugin, filename=media.filename) }}"
|
||||
class="card-img-top" style="width:100%; height:auto;">
|
||||
{% if media.caption %}
|
||||
<div class="card-body p-2">
|
||||
<p class="card-text text-center">{{ media.caption }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="card-footer d-flex justify-content-between align-items-center p-2">
|
||||
<button class="btn btn-sm btn-outline-danger heart-btn" data-id="{{ media.id }}">
|
||||
❤️ <span class="heart-count">{{ media.hearts|length }}</span>
|
||||
</button>
|
||||
{% if current_user and (current_user.id == media.uploader_id or current_user.role == 'admin') %}
|
||||
<form method="POST" action="{{ url_for('media.set_featured_image', media_id=media.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if media.featured_entries|length %}
|
||||
<button class="btn btn-sm btn-outline-secondary" type="submit">★ Featured</button>
|
||||
{% else %}
|
||||
<button class="btn btn-sm btn-outline-primary" type="submit">☆ Set Featured</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
220
app/templates/core/base.html
Normal file
220
app/templates/core/base.html
Normal file
@ -0,0 +1,220 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}Nature In Pots Community{% endblock %}</title>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
>
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css"
|
||||
rel="stylesheet"
|
||||
>
|
||||
<style>
|
||||
body { display: flex; flex-direction: column; min-height: 100vh; }
|
||||
main { flex: 1; }
|
||||
footer { background: #f8f9fa; padding: 1rem 0; text-align: center; }
|
||||
</style>
|
||||
{% block styles %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand fw-bold" href="{{ url_for('home') }}">
|
||||
Nature In Pots
|
||||
</a>
|
||||
<button
|
||||
class="navbar-toggler"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#mainNav"
|
||||
>
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="mainNav">
|
||||
<!-- Left links -->
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('home') }}">Home</a>
|
||||
</li>
|
||||
{% if current_user.is_authenticated %}
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('plant.index') }}">Plants</a>
|
||||
</li>
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('growlog.list_logs') }}">Grow Logs</a>
|
||||
</li>
|
||||
<li class="nav-item me-2">
|
||||
<a class="nav-link" href="{{ url_for('submission.list_submissions') }}">
|
||||
Submissions
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<!-- New-item + Admin + Plugins -->
|
||||
{% if current_user.is_authenticated %}
|
||||
<div class="d-flex align-items-center">
|
||||
<!-- + New dropdown -->
|
||||
<div class="btn-group me-3">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-success"
|
||||
onclick="location.href='{{ url_for('plant.create') }}'"
|
||||
>
|
||||
<i class="bi bi-plus-lg"></i>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-success dropdown-toggle dropdown-toggle-split"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<span class="visually-hidden">Toggle menu</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('plant.create') }}">
|
||||
New Plant
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('growlog.add_log') }}">
|
||||
New Grow Log
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
class="dropdown-item"
|
||||
href="{{ url_for('submission.new_submission') }}"
|
||||
>
|
||||
New Submission
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Admin link -->
|
||||
{% if current_user.role == 'admin' %}
|
||||
<a
|
||||
class="btn btn-outline-danger me-3"
|
||||
href="{{ url_for('admin.dashboard') }}"
|
||||
>
|
||||
Admin Dashboard
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Plugins dropdown -->
|
||||
<div class="dropdown me-3">
|
||||
<a
|
||||
class="btn btn-outline-secondary dropdown-toggle"
|
||||
href="#"
|
||||
id="pluginsDropdown"
|
||||
role="button"
|
||||
data-bs-toggle="dropdown"
|
||||
>
|
||||
Plugins
|
||||
</a>
|
||||
<ul
|
||||
class="dropdown-menu dropdown-menu-end"
|
||||
aria-labelledby="pluginsDropdown"
|
||||
>
|
||||
<li><a class="dropdown-item" href="#">Materials</a></li>
|
||||
<li><a class="dropdown-item" href="#">Ledger</a></li>
|
||||
<li><a class="dropdown-item" href="#">Inventory</a></li>
|
||||
<li><a class="dropdown-item" href="#">Collectives</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Profile dropdown -->
|
||||
<div class="dropdown">
|
||||
<a
|
||||
class="d-flex align-items-center text-decoration-none dropdown-toggle"
|
||||
href="#"
|
||||
id="profileDropdown"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
>
|
||||
<i class="bi bi-person-circle fs-4 me-1"></i>
|
||||
<span>{{ current_user.username }}</span>
|
||||
</a>
|
||||
<ul
|
||||
class="dropdown-menu dropdown-menu-end text-small"
|
||||
aria-labelledby="profileDropdown"
|
||||
>
|
||||
<li><a class="dropdown-item" href="#">My Profile</a></li>
|
||||
<li><a class="dropdown-item" href="#">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('utility.upload') }}">
|
||||
Import
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="{{ url_for('utility.export_data') }}">
|
||||
Export
|
||||
</a>
|
||||
</li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li>
|
||||
<a
|
||||
class="dropdown-item text-danger"
|
||||
href="{{ url_for('auth.logout') }}"
|
||||
>
|
||||
<i class="bi bi-box-arrow-right me-1"></i> Logout
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<!-- Login / Register buttons -->
|
||||
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item me-2">
|
||||
<a class="btn btn-outline-primary" href="{{ url_for('auth.login') }}">
|
||||
Login
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="btn btn-primary" href="{{ url_for('auth.register') }}">
|
||||
Register
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="mt-3">
|
||||
{% for category, message in messages %}
|
||||
<div
|
||||
class="alert alert-{{ category }} alert-dismissible fade show"
|
||||
role="alert"
|
||||
>
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
© {{ current_year | default(2025) }} Nature In Pots Community. All rights reserved.
|
||||
</footer>
|
||||
|
||||
<script
|
||||
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
||||
></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
55
app/templates/core/home.html
Normal file
55
app/templates/core/home.html
Normal file
@ -0,0 +1,55 @@
|
||||
{% extends 'core/base.html' %}
|
||||
{% block title %}Home | Nature In Pots{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- Hero Section -->
|
||||
<div class="py-5 text-center bg-light rounded-3">
|
||||
<h1 class="display-5 fw-bold">Welcome to Nature In Pots</h1>
|
||||
<p class="fs-5 text-muted mb-4">
|
||||
Your internal platform for comprehensive plant tracking, propagation history, and collaborative logging.
|
||||
</p>
|
||||
<p class="mb-0">
|
||||
<strong class="text-success">Free to use for the time being</strong><br>
|
||||
(A future subscription or licensing model may be introduced as needed.)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Features Overview -->
|
||||
<div class="row mt-5 gy-4">
|
||||
<div class="col-md-4">
|
||||
<h3>Plant Profiles</h3>
|
||||
<p>Quickly create and manage detailed records—type, names, lineage, notes, and custom slugs for easy sharing.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Grow Logs</h3>
|
||||
<p>Maintain a timeline of growth metrics, health events, substrate mixes, and propagation notes.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Image Gallery</h3>
|
||||
<p>Upload, rotate, and feature photos for each plant. Community voting and one-click “featured” selection.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Lineage Tracking</h3>
|
||||
<p>Visualize parent–child relationships with a graph powered by Neo4j—track every cutting, seed, and division.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Pricing & Transfers</h3>
|
||||
<p>Securely log acquisition costs, resale prices, and ownership changes—with history retained and protected.</p>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<h3>Import & Export</h3>
|
||||
<p>Bulk-import plants and media via CSV/ZIP. Export your entire dataset and images for backups or reporting.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Call to Action -->
|
||||
<div class="text-center mt-5">
|
||||
{% if current_user.is_authenticated %}
|
||||
<a href="{{ url_for('plant.index') }}" class="btn btn-primary btn-lg me-2">View My Plants</a>
|
||||
<a href="{{ url_for('utility.upload') }}" class="btn btn-outline-secondary btn-lg">Import Data</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('auth.register') }}" class="btn btn-success btn-lg me-2">Register Now</a>
|
||||
<a href="{{ url_for('auth.login') }}" class="btn btn-outline-primary btn-lg">Log In</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
18
app/templates/core/media_styles.html
Normal file
18
app/templates/core/media_styles.html
Normal file
@ -0,0 +1,18 @@
|
||||
<style>
|
||||
.media-thumbnails {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.media-thumbnails li {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
}
|
||||
.media-thumbnails img {
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
padding: 2px;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user