-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
92 lines (74 loc) · 3.58 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from interface import ObjectInterface
from flask import Flask, render_template, request, redirect, url_for, abort
import utils
FILENAME_DATABASE = 'data/database.db'
app = Flask(__name__,
static_folder='gui/static',
template_folder='gui/templates')
def get_interface() -> ObjectInterface:
interface = ObjectInterface(FILENAME_DATABASE)
interface.connect()
return interface
# Eigene Methoden in den Templates
@app.context_processor
def utility_processor():
return dict(display_datetime=utils.display_datetime)
@app.route('/')
def class_list():
with get_interface() as interface:
interface.cursor.execute("SELECT id FROM structure_class ORDER BY id")
return render_template('class_list.html', classes=[interface.get_class(row['id']) for row in interface.cursor.fetchall()])
@app.route('/datatype/<int:datatype_id>')
def show_datatype(datatype_id: int):
with get_interface() as interface:
# Klasse ermitteln
datatype = interface.get_datatype(datatype_id)
return render_template('show_datatype.html', datatype=datatype)
@app.route('/class/<int:class_id>')
def show_class(class_id: int):
with get_interface() as interface:
# Klasse ermitteln
class_ = interface.get_class(class_id)
# Attribute ermitteln
all_attributes = [aa.get_attribute() for aa in class_.get_attribute_assignments(True)]
class_attributes = [aa.get_attribute() for aa in class_.get_attribute_assignments()]
inherited_attributes = [ta for ta in all_attributes if ta.id not in [ca.id for ca in class_attributes]]
# Referenzen ermitteln
all_references = class_.get_references(recursive=True)
class_references = class_.get_references()
inherited_references = [tr for tr in all_references if tr.id not in [cr.id for cr in class_references]]
# Objekte ermitteln
objects = interface.get_instances(class_id, recursive=True)
return render_template('show_class.html',
class_=class_,
class_attributes=class_attributes,
inherited_attributes=inherited_attributes,
class_references=class_references,
inherited_references=inherited_references,
objects=objects)
# Attributzuweisung anzeigen
@app.route('/attribute/<int:class_id>/<int:attribute_id>')
def show_attribute_assignment(class_id: int, attribute_id: int):
with get_interface() as interface:
# Klasse und Attributzuweisung ermitteln
class_ = interface.get_class(class_id)
attribute_assignments = [aa for aa in class_.get_attribute_assignments() if aa.class_id == class_id and aa.attribute_id == attribute_id]
if len(attribute_assignments) == 0:
abort(400, 'Attribute assignment not found')
attribute_assignment = attribute_assignments[0]
return render_template('show_attribute_assignment.html',
class_=class_,
attribute=attribute_assignment.get_attribute())
# Objekt anzeigen
@app.route('/object/<int:object_id>')
def show_object(object_id: int):
with get_interface() as interface:
object_ = interface.get_object(object_id)
return render_template('show_object.html', object_=object_)
# Logeinträge anzeigen
@app.route('/log')
def log():
with get_interface() as interface:
return render_template('log.html', rows=interface.get_log())
if __name__ == '__main__':
app.run(debug=True)