246 lines
8.0 KiB
Python
246 lines
8.0 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from app import app, initialize_database, db_path
|
|
from models import db, User, Thought, Comment, MindMapNode, ThoughtRelation, ThoughtRating, RelationType
|
|
from models import Category, UserMindmap, UserMindmapNode, MindmapNote
|
|
import os
|
|
import sqlite3
|
|
from flask import Flask
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from datetime import datetime
|
|
|
|
# Erstelle eine temporäre Flask-App, um die Datenbank zu initialisieren
|
|
app = Flask(__name__)
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///systades.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
db.init_app(app)
|
|
|
|
def init_db():
|
|
with app.app_context():
|
|
print("Initialisiere Datenbank...")
|
|
|
|
# Tabellen erstellen
|
|
db.create_all()
|
|
print("Tabellen wurden erstellt.")
|
|
|
|
# Standardbenutzer erstellen, falls keine vorhanden sind
|
|
if User.query.count() == 0:
|
|
print("Erstelle Standardbenutzer...")
|
|
create_default_users()
|
|
|
|
# Standardkategorien erstellen, falls keine vorhanden sind
|
|
if Category.query.count() == 0:
|
|
print("Erstelle Standardkategorien...")
|
|
create_default_categories()
|
|
|
|
# Beispiel-Mindmap erstellen, falls keine Knoten vorhanden sind
|
|
if MindMapNode.query.count() == 0:
|
|
print("Erstelle Beispiel-Mindmap...")
|
|
create_sample_mindmap()
|
|
|
|
print("Datenbankinitialisierung abgeschlossen.")
|
|
|
|
def create_default_users():
|
|
"""Erstellt Standardbenutzer für die Anwendung"""
|
|
users = [
|
|
{
|
|
'username': 'admin',
|
|
'email': 'admin@example.com',
|
|
'password': 'admin',
|
|
'role': 'admin'
|
|
},
|
|
{
|
|
'username': 'user',
|
|
'email': 'user@example.com',
|
|
'password': 'user',
|
|
'role': 'user'
|
|
}
|
|
]
|
|
|
|
for user_data in users:
|
|
password = user_data.pop('password')
|
|
user = User(**user_data)
|
|
user.set_password(password)
|
|
db.session.add(user)
|
|
|
|
db.session.commit()
|
|
print(f"{len(users)} Benutzer wurden erstellt.")
|
|
|
|
def create_default_categories():
|
|
"""Erstellt die Standardkategorien für die Mindmap"""
|
|
categories = [
|
|
{
|
|
'name': 'Konzept',
|
|
'description': 'Abstrakte Ideen und theoretische Konzepte',
|
|
'color_code': '#6366f1',
|
|
'icon': 'lightbulb'
|
|
},
|
|
{
|
|
'name': 'Technologie',
|
|
'description': 'Hardware, Software, Tools und Plattformen',
|
|
'color_code': '#10b981',
|
|
'icon': 'cpu'
|
|
},
|
|
{
|
|
'name': 'Prozess',
|
|
'description': 'Workflows, Methodologien und Vorgehensweisen',
|
|
'color_code': '#f59e0b',
|
|
'icon': 'git-branch'
|
|
},
|
|
{
|
|
'name': 'Person',
|
|
'description': 'Personen, Teams und Organisationen',
|
|
'color_code': '#ec4899',
|
|
'icon': 'user'
|
|
},
|
|
{
|
|
'name': 'Dokument',
|
|
'description': 'Dokumentationen, Referenzen und Ressourcen',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'file-text'
|
|
}
|
|
]
|
|
|
|
for cat_data in categories:
|
|
category = Category(**cat_data)
|
|
db.session.add(category)
|
|
|
|
db.session.commit()
|
|
print(f"{len(categories)} Kategorien wurden erstellt.")
|
|
|
|
def create_sample_mindmap():
|
|
"""Erstellt eine Beispiel-Mindmap mit Knoten und Beziehungen"""
|
|
|
|
# Kategorien für die Zuordnung
|
|
categories = Category.query.all()
|
|
category_map = {cat.name: cat for cat in categories}
|
|
|
|
# Beispielknoten erstellen
|
|
nodes = [
|
|
{
|
|
'name': 'Wissensmanagement',
|
|
'description': 'Systematische Erfassung, Speicherung und Nutzung von Wissen in Organisationen.',
|
|
'color_code': '#6366f1',
|
|
'icon': 'database',
|
|
'category': category_map.get('Konzept'),
|
|
'x': 0,
|
|
'y': 0
|
|
},
|
|
{
|
|
'name': 'Mind-Mapping',
|
|
'description': 'Technik zur visuellen Darstellung von Informationen und Zusammenhängen.',
|
|
'color_code': '#10b981',
|
|
'icon': 'git-branch',
|
|
'category': category_map.get('Prozess'),
|
|
'x': 200,
|
|
'y': -150
|
|
},
|
|
{
|
|
'name': 'Cytoscape.js',
|
|
'description': 'JavaScript-Bibliothek für die Visualisierung und Manipulation von Graphen.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'code',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 350,
|
|
'y': -50
|
|
},
|
|
{
|
|
'name': 'Socket.IO',
|
|
'description': 'Bibliothek für Echtzeit-Kommunikation zwischen Client und Server.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'zap',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 350,
|
|
'y': 100
|
|
},
|
|
{
|
|
'name': 'Kollaboration',
|
|
'description': 'Zusammenarbeit mehrerer Benutzer an gemeinsamen Inhalten.',
|
|
'color_code': '#f59e0b',
|
|
'icon': 'users',
|
|
'category': category_map.get('Prozess'),
|
|
'x': 200,
|
|
'y': 150
|
|
},
|
|
{
|
|
'name': 'SQLite',
|
|
'description': 'Leichtgewichtige relationale Datenbank, die ohne Server-Prozess auskommt.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'database',
|
|
'category': category_map.get('Technologie'),
|
|
'x': 0,
|
|
'y': 200
|
|
},
|
|
{
|
|
'name': 'Flask',
|
|
'description': 'Leichtgewichtiges Python-Webframework für die Entwicklung von Webanwendungen.',
|
|
'color_code': '#3b82f6',
|
|
'icon': 'server',
|
|
'category': category_map.get('Technologie'),
|
|
'x': -200,
|
|
'y': 150
|
|
},
|
|
{
|
|
'name': 'REST API',
|
|
'description': 'Architekturstil für verteilte Systeme, insbesondere Webanwendungen.',
|
|
'color_code': '#10b981',
|
|
'icon': 'link',
|
|
'category': category_map.get('Konzept'),
|
|
'x': -200,
|
|
'y': -150
|
|
},
|
|
{
|
|
'name': 'Dokumentation',
|
|
'description': 'Strukturierte Erfassung und Beschreibung von Informationen und Prozessen.',
|
|
'color_code': '#ec4899',
|
|
'icon': 'file-text',
|
|
'category': category_map.get('Dokument'),
|
|
'x': -350,
|
|
'y': 0
|
|
}
|
|
]
|
|
|
|
# Knoten in die Datenbank einfügen
|
|
node_objects = {}
|
|
for node_data in nodes:
|
|
category = node_data.pop('category', None)
|
|
x = node_data.pop('x', 0)
|
|
y = node_data.pop('y', 0)
|
|
node = MindMapNode(**node_data)
|
|
if category:
|
|
node.category_id = category.id
|
|
db.session.add(node)
|
|
db.session.flush() # Generiert IDs für neue Objekte
|
|
node_objects[node.name] = node
|
|
|
|
# Beziehungen erstellen
|
|
relationships = [
|
|
('Wissensmanagement', 'Mind-Mapping'),
|
|
('Wissensmanagement', 'Kollaboration'),
|
|
('Wissensmanagement', 'Dokumentation'),
|
|
('Mind-Mapping', 'Cytoscape.js'),
|
|
('Kollaboration', 'Socket.IO'),
|
|
('Wissensmanagement', 'SQLite'),
|
|
('SQLite', 'Flask'),
|
|
('Flask', 'REST API'),
|
|
('REST API', 'Socket.IO'),
|
|
('REST API', 'Dokumentation')
|
|
]
|
|
|
|
for parent_name, child_name in relationships:
|
|
parent = node_objects.get(parent_name)
|
|
child = node_objects.get(child_name)
|
|
if parent and child:
|
|
parent.children.append(child)
|
|
|
|
db.session.commit()
|
|
print(f"{len(nodes)} Knoten und {len(relationships)} Beziehungen wurden erstellt.")
|
|
|
|
if __name__ == '__main__':
|
|
init_db()
|
|
print("Datenbank wurde erfolgreich initialisiert!")
|
|
print("Sie können die Anwendung jetzt mit 'python app.py' starten")
|
|
print("Anmelden mit:")
|
|
print(" Admin: username=admin, password=admin")
|
|
print(" User: username=user, password=user") |