Refactor database initialization: streamline the process by removing the old init_database function, implementing a new structure for database setup, and ensuring the creation of a comprehensive mindmap hierarchy with an admin user. Update app.py to run on port 5000 instead of 6000.
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
website/__pycache__/app.cpython-313.pyc
Normal file
BIN
website/__pycache__/app.cpython-313.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
website/__pycache__/init_db.cpython-313.pyc
Normal file
BIN
website/__pycache__/init_db.cpython-313.pyc
Normal file
Binary file not shown.
@@ -277,4 +277,4 @@ node_thought_association = db.Table('node_thought_association',
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = create_app()
|
||||
app.run(host="0.0.0.0", port=6000, debug=True)
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
@@ -1,88 +1,144 @@
|
||||
from app import app, db, User, MindMapNode
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
|
||||
def init_database():
|
||||
"""Initialize the database with admin user and mindmap structure."""
|
||||
with app.app_context():
|
||||
# Create all tables
|
||||
db.create_all()
|
||||
|
||||
# Check if we already have users
|
||||
if User.query.first() is None:
|
||||
print("Creating admin user...")
|
||||
# Create admin user
|
||||
admin = User(username='admin', email='admin@example.com', is_admin=True)
|
||||
admin.set_password('admin123')
|
||||
db.session.add(admin)
|
||||
|
||||
# Create regular test user
|
||||
test_user = User(username='test', email='test@example.com', is_admin=False)
|
||||
test_user.set_password('test123')
|
||||
db.session.add(test_user)
|
||||
|
||||
db.session.commit()
|
||||
print("Admin user created successfully!")
|
||||
|
||||
# Check if we already have mindmap nodes
|
||||
if MindMapNode.query.first() is None:
|
||||
print("Creating initial mindmap structure...")
|
||||
# Create initial mindmap structure
|
||||
root = MindMapNode(name="Wissenschaftliche Mindmap")
|
||||
db.session.add(root)
|
||||
|
||||
# Level 1 nodes
|
||||
node1 = MindMapNode(name="Naturwissenschaften", parent=root)
|
||||
node2 = MindMapNode(name="Geisteswissenschaften", parent=root)
|
||||
node3 = MindMapNode(name="Technologie", parent=root)
|
||||
node4 = MindMapNode(name="Künste", parent=root)
|
||||
db.session.add_all([node1, node2, node3, node4])
|
||||
|
||||
# Level 2 nodes - Naturwissenschaften
|
||||
node1_1 = MindMapNode(name="Physik", parent=node1)
|
||||
node1_2 = MindMapNode(name="Biologie", parent=node1)
|
||||
node1_3 = MindMapNode(name="Chemie", parent=node1)
|
||||
node1_4 = MindMapNode(name="Astronomie", parent=node1)
|
||||
db.session.add_all([node1_1, node1_2, node1_3, node1_4])
|
||||
|
||||
# Level 2 nodes - Geisteswissenschaften
|
||||
node2_1 = MindMapNode(name="Philosophie", parent=node2)
|
||||
node2_2 = MindMapNode(name="Geschichte", parent=node2)
|
||||
node2_3 = MindMapNode(name="Psychologie", parent=node2)
|
||||
node2_4 = MindMapNode(name="Soziologie", parent=node2)
|
||||
db.session.add_all([node2_1, node2_2, node2_3, node2_4])
|
||||
|
||||
# Level 2 nodes - Technologie
|
||||
node3_1 = MindMapNode(name="Informatik", parent=node3)
|
||||
node3_2 = MindMapNode(name="Biotechnologie", parent=node3)
|
||||
node3_3 = MindMapNode(name="Künstliche Intelligenz", parent=node3)
|
||||
node3_4 = MindMapNode(name="Energietechnik", parent=node3)
|
||||
db.session.add_all([node3_1, node3_2, node3_3, node3_4])
|
||||
|
||||
# Level 2 nodes - Künste
|
||||
node4_1 = MindMapNode(name="Bildende Kunst", parent=node4)
|
||||
node4_2 = MindMapNode(name="Musik", parent=node4)
|
||||
node4_3 = MindMapNode(name="Literatur", parent=node4)
|
||||
node4_4 = MindMapNode(name="Film", parent=node4)
|
||||
db.session.add_all([node4_1, node4_2, node4_3, node4_4])
|
||||
|
||||
# Level 3 nodes - a few examples
|
||||
# Physik
|
||||
MindMapNode(name="Quantenphysik", parent=node1_1)
|
||||
MindMapNode(name="Relativitätstheorie", parent=node1_1)
|
||||
|
||||
# Informatik
|
||||
MindMapNode(name="Maschinelles Lernen", parent=node3_1)
|
||||
MindMapNode(name="Softwareentwicklung", parent=node3_1)
|
||||
MindMapNode(name="Datenbanken", parent=node3_1)
|
||||
|
||||
# Commit changes
|
||||
db.session.commit()
|
||||
print("Mindmap structure created successfully!")
|
||||
|
||||
print("Database initialization complete.")
|
||||
# Pfade zu möglichen Datenbankdateien
|
||||
db_paths = [
|
||||
Path("instance/mindmap.db"),
|
||||
Path("mindmap.db"),
|
||||
Path("website/instance/mindmap.db"),
|
||||
Path("website/mindmap.db")
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_database()
|
||||
print("You can now run the application with 'python app.py'")
|
||||
print("Login with:")
|
||||
print(" Admin: username=admin, password=admin123")
|
||||
print(" User: username=test, password=test123")
|
||||
# Lösche bestehende Datenbankdateien
|
||||
for db_path in db_paths:
|
||||
if db_path.exists():
|
||||
try:
|
||||
print(f"Lösche Datenbank: {db_path}")
|
||||
os.remove(db_path)
|
||||
except Exception as e:
|
||||
print(f"Fehler beim Löschen von {db_path}: {e}")
|
||||
|
||||
# Stelle sicher, dass das instance-Verzeichnis existiert
|
||||
instance_dir = Path("instance")
|
||||
if not instance_dir.exists():
|
||||
os.makedirs(instance_dir)
|
||||
|
||||
# Importiere Datenbankmodelle und erstelle die Datenbank
|
||||
from app import db, create_app, User, MindMapNode, Thought, Comment
|
||||
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
print("Erstelle neue Datenbank...")
|
||||
db.drop_all() # Stelle sicher, dass alle Tabellen gelöscht sind
|
||||
db.create_all() # Erstelle Tabellen basierend auf den Modellen
|
||||
|
||||
# Erstelle einen Admin-Benutzer
|
||||
admin = User(username="admin", email="admin@example.com", is_admin=True)
|
||||
admin.set_password("admin123")
|
||||
db.session.add(admin)
|
||||
|
||||
# Erstelle Root-Node
|
||||
root = MindMapNode(name="Wissenschaft")
|
||||
db.session.add(root)
|
||||
|
||||
# Hauptkategorien erstellen
|
||||
naturwissenschaften = MindMapNode(name="Naturwissenschaften", parent=root)
|
||||
geisteswissenschaften = MindMapNode(name="Geisteswissenschaften", parent=root)
|
||||
sozialwissenschaften = MindMapNode(name="Sozialwissenschaften", parent=root)
|
||||
ingenieurwissenschaften = MindMapNode(name="Ingenieurwissenschaften", parent=root)
|
||||
medizin = MindMapNode(name="Medizin", parent=root)
|
||||
informatik = MindMapNode(name="Informatik", parent=root)
|
||||
|
||||
db.session.add_all([naturwissenschaften, geisteswissenschaften, sozialwissenschaften,
|
||||
ingenieurwissenschaften, medizin, informatik])
|
||||
|
||||
# Unterkategorien für Naturwissenschaften
|
||||
physik = MindMapNode(name="Physik", parent=naturwissenschaften)
|
||||
chemie = MindMapNode(name="Chemie", parent=naturwissenschaften)
|
||||
biologie = MindMapNode(name="Biologie", parent=naturwissenschaften)
|
||||
astronomie = MindMapNode(name="Astronomie", parent=naturwissenschaften)
|
||||
geologie = MindMapNode(name="Geologie", parent=naturwissenschaften)
|
||||
|
||||
# Unterkategorien für Physik
|
||||
quantenphysik = MindMapNode(name="Quantenphysik", parent=physik)
|
||||
relativitätstheorie = MindMapNode(name="Relativitätstheorie", parent=physik)
|
||||
thermodynamik = MindMapNode(name="Thermodynamik", parent=physik)
|
||||
|
||||
# Unterkategorien für Geisteswissenschaften
|
||||
philosophie = MindMapNode(name="Philosophie", parent=geisteswissenschaften)
|
||||
geschichte = MindMapNode(name="Geschichte", parent=geisteswissenschaften)
|
||||
linguistik = MindMapNode(name="Linguistik", parent=geisteswissenschaften)
|
||||
literaturwissenschaft = MindMapNode(name="Literaturwissenschaft", parent=geisteswissenschaften)
|
||||
religionswissenschaft = MindMapNode(name="Religionswissenschaft", parent=geisteswissenschaften)
|
||||
|
||||
# Unterkategorien für Sozialwissenschaften
|
||||
soziologie = MindMapNode(name="Soziologie", parent=sozialwissenschaften)
|
||||
psychologie = MindMapNode(name="Psychologie", parent=sozialwissenschaften)
|
||||
politikwissenschaft = MindMapNode(name="Politikwissenschaft", parent=sozialwissenschaften)
|
||||
wirtschaftswissenschaften = MindMapNode(name="Wirtschaftswissenschaften", parent=sozialwissenschaften)
|
||||
|
||||
# Unterkategorien für Ingenieurwissenschaften
|
||||
maschinenbau = MindMapNode(name="Maschinenbau", parent=ingenieurwissenschaften)
|
||||
elektrotechnik = MindMapNode(name="Elektrotechnik", parent=ingenieurwissenschaften)
|
||||
bauingenieurwesen = MindMapNode(name="Bauingenieurwesen", parent=ingenieurwissenschaften)
|
||||
verfahrenstechnik = MindMapNode(name="Verfahrenstechnik", parent=ingenieurwissenschaften)
|
||||
|
||||
# Unterkategorien für Medizin
|
||||
humanmedizin = MindMapNode(name="Humanmedizin", parent=medizin)
|
||||
zahnmedizin = MindMapNode(name="Zahnmedizin", parent=medizin)
|
||||
pharmazie = MindMapNode(name="Pharmazie", parent=medizin)
|
||||
neurologie = MindMapNode(name="Neurologie", parent=medizin)
|
||||
onkologie = MindMapNode(name="Onkologie", parent=medizin)
|
||||
|
||||
# Unterkategorien für Informatik
|
||||
künstliche_intelligenz = MindMapNode(name="Künstliche Intelligenz", parent=informatik)
|
||||
datenbanken = MindMapNode(name="Datenbanken", parent=informatik)
|
||||
softwareentwicklung = MindMapNode(name="Softwareentwicklung", parent=informatik)
|
||||
computergrafik = MindMapNode(name="Computergrafik", parent=informatik)
|
||||
cybersicherheit = MindMapNode(name="Cybersicherheit", parent=informatik)
|
||||
|
||||
# Alle Nodes zur Session hinzufügen
|
||||
all_nodes = [physik, chemie, biologie, astronomie, geologie,
|
||||
quantenphysik, relativitätstheorie, thermodynamik,
|
||||
philosophie, geschichte, linguistik, literaturwissenschaft, religionswissenschaft,
|
||||
soziologie, psychologie, politikwissenschaft, wirtschaftswissenschaften,
|
||||
maschinenbau, elektrotechnik, bauingenieurwesen, verfahrenstechnik,
|
||||
humanmedizin, zahnmedizin, pharmazie, neurologie, onkologie,
|
||||
künstliche_intelligenz, datenbanken, softwareentwicklung, computergrafik, cybersicherheit]
|
||||
|
||||
db.session.add_all(all_nodes)
|
||||
|
||||
# Füge einen Beispiel-Gedanken hinzu
|
||||
thought = Thought(
|
||||
content="Dies ist ein Beispiel-Gedanke zur Wissenschaft allgemein.",
|
||||
branch="Wissenschaft",
|
||||
user_id=1 # Admin-Benutzer
|
||||
)
|
||||
db.session.add(thought)
|
||||
root.thoughts.append(thought)
|
||||
|
||||
# Füge weitere Beispiel-Gedanken hinzu
|
||||
thought_ai = Thought(
|
||||
content="Künstliche Intelligenz transformiert viele Bereiche der Wissenschaft und Gesellschaft.",
|
||||
branch="Künstliche Intelligenz",
|
||||
user_id=1
|
||||
)
|
||||
db.session.add(thought_ai)
|
||||
künstliche_intelligenz.thoughts.append(thought_ai)
|
||||
|
||||
thought_physik = Thought(
|
||||
content="Die Quantenphysik stellt unser Verständnis der Realität grundlegend in Frage.",
|
||||
branch="Quantenphysik",
|
||||
user_id=1
|
||||
)
|
||||
db.session.add(thought_physik)
|
||||
quantenphysik.thoughts.append(thought_physik)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
print("Datenbank wurde erfolgreich initialisiert!")
|
||||
print(f"Admin-Benutzer erstellt: admin/admin123")
|
||||
print(f"Root-Node 'Wissenschaft' erstellt mit mehreren Hauptkategorien und Unterkategorien")
|
||||
Binary file not shown.
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
from init_db import init_database
|
||||
from app import app
|
||||
import sys
|
||||
from app import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Initialize the database first
|
||||
init_database()
|
||||
|
||||
# Run the Flask application
|
||||
# Run the app directly - no need to call init_database as it doesn't exist
|
||||
app.run(host="0.0.0.0", debug=True)
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<div class="flex flex-col space-y-4 sm:flex-row sm:space-y-0 sm:space-x-4 justify-center">
|
||||
<a href="{{ url_for('mindmap') }}" class="bg-gradient-to-r from-indigo-500 to-purple-600 hover:from-indigo-600 hover:to-purple-700 text-white font-semibold px-6 py-3 rounded-lg transition-all duration-300 transform hover:scale-105">
|
||||
Starte die Mindmap
|
||||
Zum Netzwerk
|
||||
</a>
|
||||
{% if not current_user.is_authenticated %}
|
||||
<a href="{{ url_for('register') }}" class="glass hover:bg-white/20 text-white font-semibold px-6 py-3 rounded-lg transition-all duration-300 transform hover:scale-105">
|
||||
@@ -20,19 +20,16 @@
|
||||
|
||||
<div class="mt-12 grid grid-cols-1 md:grid-cols-3 gap-6 w-full max-w-4xl">
|
||||
<div class="glass p-6 text-white">
|
||||
<div class="text-3xl mb-2">🧠</div>
|
||||
<h3 class="text-xl font-semibold mb-2">Visualisiere Wissen</h3>
|
||||
<p class="text-white/80">Erkenne Zusammenhänge zwischen verschiedenen Wissensgebieten durch intuitive Mindmaps.</p>
|
||||
</div>
|
||||
|
||||
<div class="glass p-6 text-white">
|
||||
<div class="text-3xl mb-2">💡</div>
|
||||
<h3 class="text-xl font-semibold mb-2">Teile Gedanken</h3>
|
||||
<p class="text-white/80">Füge deine eigenen Gedanken zu bestehenden Themen hinzu und bereichere die Community.</p>
|
||||
</div>
|
||||
|
||||
<div class="glass p-6 text-white">
|
||||
<div class="text-3xl mb-2">🔄</div>
|
||||
<h3 class="text-xl font-semibold mb-2">Interaktive Vernetzung</h3>
|
||||
<p class="text-white/80">Beteilige dich an Diskussionen und sieh wie sich Ideen gemeinsam entwickeln.</p>
|
||||
</div>
|
||||
|
||||
@@ -99,6 +99,13 @@
|
||||
.node:hover circle {
|
||||
filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.8));
|
||||
}
|
||||
|
||||
/* Fix for "keine Auswahl" text */
|
||||
#selected-node-title {
|
||||
width: 100%;
|
||||
overflow: visible;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -346,12 +353,21 @@
|
||||
// Create hierarchical layout
|
||||
const root = d3.hierarchy(data);
|
||||
|
||||
// Create tree layout
|
||||
const treeLayout = d3.tree()
|
||||
.size([height - 100, width - 200])
|
||||
.nodeSize([80, 200]);
|
||||
// Create radial layout instead of tree for all-direction branches
|
||||
const radius = Math.min(width, height) / 2 - 100;
|
||||
|
||||
treeLayout(root);
|
||||
const radialLayout = d3.cluster()
|
||||
.size([360, radius]);
|
||||
|
||||
radialLayout(root);
|
||||
|
||||
// Convert to Cartesian coordinates
|
||||
root.descendants().forEach(d => {
|
||||
// Convert from polar to Cartesian coordinates
|
||||
const angle = (d.x - 90) / 180 * Math.PI;
|
||||
d.x = d.y * Math.cos(angle);
|
||||
d.y = d.y * Math.sin(angle);
|
||||
});
|
||||
|
||||
// Create links
|
||||
const links = g.selectAll('.link')
|
||||
@@ -360,10 +376,10 @@
|
||||
.append('path')
|
||||
.attr('class', 'link')
|
||||
.attr('d', d => {
|
||||
return `M${d.source.y},${d.source.x}
|
||||
C${(d.source.y + d.target.y) / 2},${d.source.x}
|
||||
${(d.source.y + d.target.y) / 2},${d.target.x}
|
||||
${d.target.y},${d.target.x}`;
|
||||
return `M${d.source.x},${d.source.y}
|
||||
C${(d.source.x + d.target.x) / 2},${(d.source.y + d.target.y) / 2}
|
||||
${(d.source.x + d.target.x) / 2},${(d.source.y + d.target.y) / 2}
|
||||
${d.target.x},${d.target.y}`;
|
||||
});
|
||||
|
||||
// Create nodes
|
||||
@@ -375,7 +391,7 @@
|
||||
const categoryClass = getNodeCategory(d.data.name, rootCategories);
|
||||
return `node ${categoryClass} ${d.data.id === selectedNode ? 'node--selected' : ''}`;
|
||||
})
|
||||
.attr('transform', d => `translate(${d.y},${d.x})`)
|
||||
.attr('transform', d => `translate(${d.x},${d.y})`)
|
||||
.on('click', (event, d) => selectNode(d.data.id, d.data.name))
|
||||
.on('mouseover', function(event, d) {
|
||||
tooltip.transition()
|
||||
|
||||
35
website/test_app.py
Normal file
35
website/test_app.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Seite</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; }
|
||||
.container { max-width: 800px; margin: 0 auto; padding: 20px; border: 1px solid #ddd; border-radius: 5px; }
|
||||
h1 { color: #333; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Test Seite funktioniert!</h1>
|
||||
<p>Wenn Sie diese Seite sehen können, funktioniert der grundlegende Flask-Server korrekt.</p>
|
||||
<p>Server-Status:</p>
|
||||
<ul>
|
||||
<li>Flask läuft auf Port 5000</li>
|
||||
<li>Keine Datenbankverbindung erforderlich</li>
|
||||
<li>Keine Templates erforderlich</li>
|
||||
</ul>
|
||||
<p>Versuchen Sie, diese URL in verschiedenen Browsern zu öffnen.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
Reference in New Issue
Block a user