回答編集履歴
2
add
test
CHANGED
@@ -52,19 +52,7 @@
|
|
52
52
|
|
53
53
|
<script>
|
54
54
|
|
55
|
-
var dict =
|
56
|
-
|
57
|
-
{
|
58
|
-
|
59
|
-
|
55
|
+
var dict = { "title1:"db1","title2":"db2", "title3":"db3","title4":"db4" }
|
60
|
-
|
61
|
-
"データ2":"PAL",
|
62
|
-
|
63
|
-
"データ3":"NUM",
|
64
|
-
|
65
|
-
"データ4":"BUN"
|
66
|
-
|
67
|
-
}
|
68
56
|
|
69
57
|
|
70
58
|
|
@@ -82,7 +70,7 @@
|
|
82
70
|
|
83
71
|
```python
|
84
72
|
|
85
|
-
model_table = {"
|
73
|
+
model_table = {"db1",database1,"db2":database2,"db3":database3,"db4":database4}
|
86
74
|
|
87
75
|
|
88
76
|
|
1
解決
test
CHANGED
@@ -1,16 +1,28 @@
|
|
1
|
-
|
1
|
+
最終的にはVue.Jsは使わないことにしました。
|
2
2
|
|
3
|
-
FORMのactionタグに追加したURL/IDでFLASKへ飛ばそうとした。
|
4
3
|
|
5
|
-
JSにはソースの可読性を高めるため、タイトルとURL末尾のエンドを書いた
|
6
4
|
|
7
|
-
|
5
|
+
#解決した方法
|
8
6
|
|
9
|
-
F
|
7
|
+
HTMLフォームとFLASKのFORM-MODEL処理について、下記の辞書を使い紐付けを行った。
|
10
8
|
|
11
|
-
JS側からはMAPのINDEXから生成したもので、紐付けている。
|
12
9
|
|
10
|
+
|
11
|
+
JS
|
12
|
+
|
13
|
+
dict = { "title1:"db1","title2":"db2", "title3":"db3","title4":"db4" }
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
python
|
18
|
+
|
19
|
+
model_table = {"db1",database1,"db2":database2,"db3":database3,"db4":database4}
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
全体的なループカウンタは、Flask側からJINJA2でループを回して、レンダリング時にloop.index0を使いIDタグに命名している。
|
24
|
+
|
13
|
-
|
25
|
+
DOM完成後にJSでdictのループを回して(MAPのINDEXから生成)してhtmlを書き換えている。
|
14
26
|
|
15
27
|
|
16
28
|
|
@@ -68,6 +80,78 @@
|
|
68
80
|
|
69
81
|
```
|
70
82
|
|
83
|
+
```python
|
84
|
+
|
85
|
+
model_table = {"MAP":database1,"PAL":database2,"BUN":database3,"NUM":database4}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
#データインポート処理
|
90
|
+
|
91
|
+
@app.route('/import')
|
92
|
+
|
93
|
+
@app.route('/import/<model_name>',methods=["GET", "POST"])
|
94
|
+
|
95
|
+
def data_import(model_name):
|
96
|
+
|
97
|
+
if request.method == 'POST':
|
98
|
+
|
99
|
+
if 'file' not in request.files:
|
100
|
+
|
101
|
+
flash('No file part')
|
102
|
+
|
103
|
+
return redirect(request.url)
|
104
|
+
|
105
|
+
file = request.files['file']
|
106
|
+
|
107
|
+
if file.filename == '':
|
108
|
+
|
109
|
+
flash(name + "ファイルを選択してください。", "failed")
|
110
|
+
|
111
|
+
return redirect(request.url)
|
112
|
+
|
113
|
+
if file and allowed_file(file.filename):
|
114
|
+
|
115
|
+
filename = secure_filename(file.filename)
|
116
|
+
|
117
|
+
filename =os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
118
|
+
|
119
|
+
file.save(filename)
|
120
|
+
|
121
|
+
model = model_table[model_name]
|
122
|
+
|
123
|
+
objects = model.data_import(filename)
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
#new_report = Report(report_name=filename, report_welder_wps_association_id=report_id) #create a database entry with exact filename
|
128
|
+
|
129
|
+
#db.session.add(new_report)
|
130
|
+
|
131
|
+
#db.session.commit()
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
return render_template(
|
136
|
+
|
137
|
+
'table_viewer.html',
|
138
|
+
|
139
|
+
forms = range(4)
|
140
|
+
|
141
|
+
)
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
return render_template(
|
146
|
+
|
147
|
+
'import.html',
|
148
|
+
|
149
|
+
forms = [1,2,3,4]
|
150
|
+
|
151
|
+
)
|
152
|
+
|
153
|
+
```
|
154
|
+
|
71
155
|
|
72
156
|
|
73
157
|
#あとがき
|