forked from formfactory-ai/formfactory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
427 lines (377 loc) · 15 KB
/
app.py
File metadata and controls
427 lines (377 loc) · 15 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
from flask import Flask, render_template, request, jsonify
import os
import json
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def home():
# Home page to list links to different forms
return render_template('home.html')
@app.route('/area1/sub1')
def area1_sub1():
return "<h1>Area 1 - Sub Area 1</h1>"
@app.route('/area1/sub2')
def area1_sub2():
return "<h1>Area 1 - Sub Area 2</h1>"
@app.route('/area1/sub3')
def area1_sub3():
return "<h1>Area 1 - Sub Area 3</h1>"
# 添加 Area 2 和 Area 3 的路由
@app.route('/area2/sub1')
def area2_sub1():
return "<h1>Area 2 - Sub Area 1</h1>"
@app.route('/area3/sub3')
def area3_sub3():
return "<h1>Area 3 - Sub Area 3</h1>"
@app.route('/form1', methods=['GET', 'POST'])
def form1():
if request.method == 'POST':
# Process form1 data
name = request.form['name']
email = request.form['email']
return f"Form 1 Submitted! Name: {name}, Email: {email}"
return render_template('form.html')
@app.route('/form-config', methods=['GET'])
def form_config():
# 动态字段配置,包括全局标签位置
response = {
'title': 'Grant Application',
"label_position": "top", # 全局标签位置,可以是 "top" 或 "left"
# "label_position": "left", # 全局标签位置,可以是 "top" 或 "left"
# "allowManualInput": False,
"allowManualInput": True,
"fields": [
{"name": "first_name", "label": "First Name", "type": "string", "required": True, "row": 1, "col": 3},
{"name": "last_name", "label": "Last Name", "type": "string", "required": True, "row": 1, "col": 3},
{"name": "email", "label": "Email", "type": "email", "required": True, "row": 2, "col": 6},
{"name": "dob", "label": "Date of Birth", "type": "date", "required": True, "row": 2, "col": 6},
{"name": "gender", "label": "Gender", "type": "radio", "options": ["Male", "Female"], "required": True, "row": 3},
{"name": "subscribe", "label": "Subscribe to Newsletter", "type": "checkbox", "required": False, "row": 4}
]
}
return jsonify(response)
@app.route('/form-config-group', methods=['GET'])
def form_config_group():
response = {
'title': 'Grant Application',
"label_position": "top",
"allowManualInput": True,
"groups": [
{
"name": "Basic Information",
"fields": [
{"name": "first_name", "label": "First Name", "type": "string", "required": True, "col": 6},
{"name": "last_name", "label": "Last Name", "type": "string", "required": True, "col": 6},
{"name": "email", "label": "Email", "type": "email", "required": True, "col": 6},
{"name": "dob", "label": "Date of Birth", "type": "date", "required": True, "col": 6},
]
},
{
"name": "Educational Background",
"repeatable": True,
"fields": [
{"name": "university", "label": "University", "type": "string", "required": True, "col": 4},
{"name": "degree", "label": "Degree", "type": "string", "required": True, "col": 4},
{"name": "graduation_date", "label": "Graduation Date", "type": "date", "required": True, "col": 4},
]
},
{
"name": "Research Information",
"fields": [
{"name": "research_topic", "label": "Research Topic", "type": "string", "required": True, "col": 12},
{"name": "publications", "label": "Publications", "type": "string", "required": False, "col": 12},
]
},
]
}
return jsonify(response)
@app.route('/form2', methods=['GET', 'POST'])
def form2():
if request.method == 'POST':
# Process form2 data
category = request.form['category']
feedback = request.form['feedback']
return f"Form 2 Submitted! Category: {category}, Feedback: {feedback}"
return render_template('form2.html')
@app.route('/academic-research/job-application', methods=['GET', 'POST'])
def job_application_form():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A11.html', data)
return jsonify({
"message": "Application Submitted Successfully!",
"data": data
})
return render_template('A11.html')
@app.route('/academic-research/grant-application', methods=['GET', 'POST'])
def grant_application_form():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A12.html', data)
return jsonify({
"message": "Application Submitted Successfully!",
"data": data
})
return render_template('A12.html')
@app.route('/academic-research/student-registration', methods=['GET', 'POST'])
def student_registration():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A13.html', data)
return jsonify({
"message": "Student Registration Submitted Successfully!",
"data": data
})
return render_template('A13.html')
@app.route('/academic-research/paper-submission', methods=['GET', 'POST'])
def paper_submission():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A14.html', data)
return jsonify({
"message": "Paper Submission Successful!",
"data": data
})
return render_template('A14.html')
@app.route('/academic-research/course-registration', methods=['GET', 'POST'])
def course_registration():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A15.html', data)
return jsonify({
"message": "Course Registration Successful!",
"data": data
})
return render_template('A15.html')
@app.route('/academic-research/scholarship-application', methods=['GET', 'POST'])
def scholarship_application():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('A13.html', data)
return jsonify({
"message": "Scholarship Application Submitted Successfully!",
"data": data
})
return render_template('A13.html')
@app.route('/professional-business/startup-funding', methods=['GET', 'POST'])
def startup_funding():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('B11.html', data)
return jsonify({
"message": "Startup Funding Application Submitted Successfully!",
"data": data
})
return render_template('B11.html')
@app.route('/professional-business/rental-application', methods=['GET', 'POST'])
def rental_application():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('B12.html', data)
return jsonify({
"message": "Real Estate Rental Application Submitted Successfully!",
"data": data
})
return render_template('B12.html')
@app.route('/professional-business/workshop-registration', methods=['GET', 'POST'])
def workshop_registration():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('B13.html', data)
return jsonify({
"message": "Workshop Registration Submitted Successfully!",
"data": data
})
return render_template('B13.html')
@app.route('/professional-business/membership-application', methods=['GET', 'POST'])
def membership_application():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('B14.html', data)
return jsonify({
"message": "Membership Application Submitted Successfully!",
"data": data
})
return render_template('B14.html')
@app.route('/arts-creative/exhibition-submission', methods=['GET', 'POST'])
def exhibition_submission():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('C11.html', data)
return jsonify({
"message": "Art Exhibition Submission Successful!",
"data": data
})
return render_template('C11.html')
@app.route('/arts-creative/literary-submission', methods=['GET', 'POST'])
def literary_submission():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('C12.html', data)
return jsonify({
"message": "Literary Work Submission Successful!",
"data": data
})
return render_template('C12.html')
@app.route('/arts-creative/speaker-application', methods=['GET', 'POST'])
def speaker_application():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('C13.html', data)
return jsonify({
"message": "Speaker Application Submitted Successfully!",
"data": data
})
return render_template('C13.html')
@app.route('/tech-software/bug-report', methods=['GET', 'POST'])
def bug_report():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('D11.html', data)
return jsonify({
"message": "Bug Report Submitted Successfully!",
"data": data
})
return render_template('D11.html')
@app.route('/tech-software/support-request', methods=['GET', 'POST'])
def support_request():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('D12.html', data)
return jsonify({
"message": "IT Support Request Submitted Successfully!",
"data": data
})
return render_template('D12.html')
@app.route('/finance-banking/personal-loan', methods=['GET', 'POST'])
def personal_loan():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('E11.html', data)
return jsonify({
"message": "Personal Loan Application Submitted Successfully!",
"data": data
})
return render_template('E11.html')
@app.route('/finance-banking/account-opening', methods=['GET', 'POST'])
def account_opening():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('E12.html', data)
return jsonify({
"message": "Account Opening Application Submitted Successfully!",
"data": data
})
return render_template('E12.html')
@app.route('/finance-banking/financial-planning', methods=['GET', 'POST'])
def financial_planning():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('E13.html', data)
return jsonify({
"message": "Financial Planning Consultation Request Submitted Successfully!",
"data": data
})
return render_template('E13.html')
@app.route('/healthcare-medical/patient-consent', methods=['GET', 'POST'])
def patient_consent():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('F11.html', data)
return jsonify({
"message": "Patient Consent Form Submitted Successfully!",
"data": data
})
return render_template('F11.html')
@app.route('/healthcare-medical/research-enrollment', methods=['GET', 'POST'])
def research_enrollment():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('F12.html', data)
return jsonify({
"message": "Research Study Enrollment Submitted Successfully!",
"data": data
})
return render_template('F12.html')
@app.route('/healthcare-medical/insurance-claim', methods=['GET', 'POST'])
def insurance_claim():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('F13.html', data)
return jsonify({
"message": "Insurance Claim Form Submitted Successfully!",
"data": data
})
return render_template('F13.html')
@app.route('/legal-compliance/nda-submission', methods=['GET', 'POST'])
def nda_submission():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('G11.html', data)
return jsonify({
"message": "NDA Submitted Successfully!",
"data": data
})
return render_template('G11.html')
@app.route('/legal-compliance/background-check', methods=['GET', 'POST'])
def background_check():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('G12.html', data)
return jsonify({
"message": "Background Check Authorization Submitted Successfully!",
"data": data
})
return render_template('G12.html')
@app.route('/legal-compliance/contractor-onboarding', methods=['GET', 'POST'])
def contractor_onboarding():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('G13.html', data)
return jsonify({
"message": "Contractor Onboarding Form Submitted Successfully!",
"data": data
})
return render_template('G13.html')
@app.route('/construction-manufacturing/project-bid', methods=['GET', 'POST'])
def project_bid():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('H11.html', data)
return jsonify({
"message": "Project Bid Submitted Successfully!",
"data": data
})
return render_template('H11.html')
@app.route('/construction-manufacturing/order-request', methods=['GET', 'POST'])
def order_request():
if request.method == 'POST':
data = request.form.to_dict()
save_submission_to_json('H12.html', data)
return jsonify({
"message": "Manufacturing Order Request Submitted Successfully!",
"data": data
})
return render_template('H12.html')
# 添加辅助函数
def save_submission_to_json(template_name, data):
"""将提交的数据保存到对应的JSON文件中"""
# 确保submission文件夹存在
if not os.path.exists('submission'):
os.makedirs('submission')
# 构建JSON文件路径
filename = f"submission/{template_name.replace('.html', '')}.json"
# 添加时间戳
data['submission_time'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# 读取现有数据或创建新的数据列表
submissions = []
if os.path.exists(filename):
with open(filename, 'r', encoding='utf-8') as f:
submissions = json.load(f)
# 添加新提交的数据
submissions.append(data)
# 保存更新后的数据
with open(filename, 'w', encoding='utf-8') as f:
json.dump(submissions, f, ensure_ascii=False, indent=4)
if __name__ == '__main__':
app.run(debug=True)