Image Processing: - Add Pillow dependency for image manipulation - Auto-create optimized versions on upload - Generate main image (max 800x800, 85% quality) - Generate thumbnail (max 400x400, 80% quality) - Delete original after optimization Quality Improvements: - Auto-correct EXIF orientation (photos from phones) - Convert RGBA/transparency to RGB with white background - Use LANCZOS resampling for high-quality downscaling - Optimize JPEG compression Performance: - Smaller file sizes = faster page loads - Thumbnails for product listings - Optimized full-size for detail views - Reduced storage usage Fallback: - Graceful degradation if Pillow not installed - Error handling preserves original on failure - Logging for monitoring optimization success Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Hellas – Bestand & WaWi
Überblick
Dieses Repository enthält:
- WaWi‑App (Flask + SQLite) für Artikelverwaltung, Ausbuchen, Verkäufe und Bestellungen.
- Live‑Shop‑Ansicht (
index.html) lädt Daten aus der WaWi‑App. - Import‑Script für Daten aus der ursprünglichen
hellas_bestand.html.
Struktur
wawi/app.py– Flask‑App (CRUD, Ausbuchen, Verkäufe, Benutzerverwaltung)wawi/templates/– HTML‑Templates der WaWi‑Appwawi/static/– Styles + Logowawi/hellas.db– SQLite‑Datenbank (wird automatisch erstellt)wawi/import_from_html.py– Import aushellas_bestand.htmlindex.html– Live‑Shop‑Ansicht (ruft/wawi/proxy/bestand)
WaWi lokal starten
cd wawi
python3 -m venv .venv
source .venv/bin/activate
pip install flask gunicorn
python app.py
Standardzugriff: Login über Benutzerverwaltung (siehe unten).
Developer (ENV variablen)
Diese App liest Konfiguration ausschließlich aus Umgebungsvariablen.
Für lokale Entwicklung kannst du sie direkt im Shell-Session setzen oder
eine .env-Datei in dein Startup-Script laden.
Minimal sinnvoll für lokal:
SECRET_KEY– Session-Secret (beliebiger String)APP_USER/APP_PASSWORD– initialer Admin-UserURL_PREFIX– leer lassen, wenn lokal ohne Sub-Pfad
Für Bestellungen per Mail zusätzlich:
SMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASSSMTP_FROM,ORDER_TO
Optional:
APP_API_KEY– Schutz fuer/wawi/api/bestandund/wawi/orderCOOKIE_SECURE–0fuer http lokal,1fuer https
Benutzerverwaltung
Beim ersten Start wird ein Admin aus ENV erzeugt:
APP_USER(default:admin)APP_PASSWORD(default:admin)
Passwörter werden gehasht gespeichert.
Über /users können weitere Benutzer angelegt und Passwörter zurückgesetzt werden.
Import aus hellas_bestand.html
cd wawi
python import_from_html.py /pfad/zu/hellas_bestand.html --truncate
Live‑Shop‑Ansicht (index.html)
index.html lädt den Bestand aus der WaWi‑App:
- API‑Proxy:
/wawi/proxy/bestand
Wenn du diese Datei auf einem Webserver auslieferst, stelle sicher, dass die WaWi‑App unter /wawi erreichbar ist.
Wenn du Bestellungen direkt aus index.html abschickst, muss der X-Order-Key bzw. ?key= dem APP_API_KEY entsprechen.
Der Key wird in index.html im Script‑Block gesetzt: const ORDER_KEY = "" (neben der Formularlogik). Trage dort deinen Key ein.
Umgebungsvariablen (ENV)
Pflicht/Empfohlen für Produktion
SECRET_KEY– Session‑SecretAPP_USER/APP_PASSWORD– initialer Admin‑UserURL_PREFIX– z. B./wawi(wenn hinter Sub‑Pfad)
E‑Mail (Bestellungen)
SMTP_HOST– SMTP‑ServerSMTP_PORT– z. B.587SMTP_USER/SMTP_PASS– SMTP LoginSMTP_FROM– Absender (z. B.bestand@hellas.welker.me)ORDER_TO– Empfänger, mehrere per Komma
Optional
APP_API_KEY– gemeinsamer API‑Key für/wawi/api/bestandund/wawi/orderCOOKIE_SECURE–1(default) setzt Secure‑Cookie,0deaktiviert für http
Deployment (systemd + Gunicorn)
- App nach
/var/www/hellas/wawikopieren - venv erstellen:
cd /var/www/hellas/wawi
python3 -m venv .venv
source .venv/bin/activate
pip install flask gunicorn
- Service‑Datei anlegen:
/etc/systemd/system/hellas.service
[Unit]
Description=Hellas WaWi
After=network.target
[Service]
User=www-data
Group=www-data
WorkingDirectory=/var/www/hellas/wawi
Environment="PATH=/var/www/hellas/wawi/.venv/bin"
Environment="URL_PREFIX=/wawi"
Environment="SECRET_KEY=DEIN_SECRET"
Environment="APP_USER=admin"
Environment="APP_PASSWORD=starkesPasswort"
Environment="SMTP_HOST=smtp.example.com"
Environment="SMTP_PORT=587"
Environment="SMTP_USER=dein_user"
Environment="SMTP_PASS=dein_pass"
Environment="SMTP_FROM=bestand@example.com"
Environment="ORDER_TO=admin@example.com, zweite@example.com"
Environment="APP_API_KEY=api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ExecStart=/var/www/hellas/wawi/.venv/bin/gunicorn -w 3 -b 127.0.0.1:8000 app:app
Restart=always
[Install]
WantedBy=multi-user.target
- Aktivieren:
sudo systemctl daemon-reload
sudo systemctl enable --now hellas
Nginx (Reverse‑Proxy + Shop‑Seite)
Beispiel /etc/nginx/sites-available/hellas:
server {
listen 80;
server_name hellas.welker.me;
location = / {
root /var/www/hellas;
try_files /index.html =404;
}
location /wawi/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Aktivieren:
sudo ln -s /etc/nginx/sites-available/hellas /etc/nginx/sites-enabled/hellas
sudo nginx -t
sudo systemctl reload nginx
SSL (Let’s Encrypt)
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d hellas.welker.me
Dateirechte (SQLite + Uploads)
sudo chown -R www-data:www-data /var/www/hellas/wawi
sudo chmod 750 /var/www/hellas/wawi
sudo chmod 640 /var/www/hellas/wawi/hellas.db
sudo mkdir -p /var/www/hellas/wawi/static/uploads
sudo chown -R www-data:www-data /var/www/hellas/wawi/static/uploads
Fix‑Permissions Script (inkl. Uploads)
/root/fix_wawi_permissions.sh sollte auch das Upload‑Verzeichnis setzen:
#!/bin/sh
set -e
chown -R www-data:www-data /var/www/hellas/wawi
chmod 750 /var/www/hellas/wawi
chmod 640 /var/www/hellas/wawi/hellas.db
mkdir -p /var/www/hellas/wawi/static/uploads
chown -R www-data:www-data /var/www/hellas/wawi/static/uploads
systemctl restart hellas