"
+ for checklist in config["checklists"]:
+ label = checklist["name"]
+ url_name = label.replace(" ", "_")
+ content += f' {label} '
+ return content
+
+@app.route('/checklist/')
+def show_checklist(checklist_name):
+ checklist = None
+ for c in config["checklists"]:
+ if checklist_name == c["name"].replace(" ", "_"):
+ checklist = c
+ if checklist is None:
+ return f'Checklist for {checklist_name} not found. Go back to start page'
+
+ content = """
+
{title}
+
+
+
+ """
+ title = checklist['name']
+ questions = ""
+ checkbox_script = ""
+
+ for i, question in enumerate(checklist["questions"]):
+ if question["type"] == "text":
+ if "label_checklist_pre" in question.keys():
+ questions += f'{question["label_checklist_pre"]}: '
+ questions += f''
+ if "label_checklist_post" in question.keys():
+ questions += f''
+ elif question["type"] == "checkbox":
+ label = f"{i}"
+ questions += f' '
+ if "label_checklist" in question.keys():
+ questions += f''
+ checkbox_script += f"""const checkbox_{i} = document.getElementById("question_{i}");
+ const hidden_{i} = document.getElementById("hidden_{i}"); """
+ checkbox_script += "button.addEventListener('click', () => { hidden_%d.value = checkbox_%d.checked ? 'True' : 'False'; }); "%(i,i)
+ if "link_page" in question.keys():
+ questions += f'Check on this page.'
+ questions += '
'
+ return content.format(title=title, checklist_name=checklist_name, questions=questions, checkbox_script=checkbox_script)
+
+
+@app.route('/submit/', methods=["GET",'POST'])
+def submit_checklist(checklist_name):
+ # This function is called with the result of the check list.
+ # Use the request.form content to generate a nice ELOG message
+ # That elog message will be posted to the elog
+
+ checklist = None
+ for c in config["checklists"]:
+ if checklist_name == c["name"].replace(" ", "_"):
+ checklist = c
+ if checklist is None:
+ return f'Checklist for {checklist_name} not found. Go back to start page'
+
+
+ report = ""
+ try:
+ report += f"Timestamp: %s\n"%(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
+ report += f"User: {request.form['user']}\n"
+ for i, question in enumerate(checklist["questions"]):
+ if question["type"] == "text":
+ report = report + question["label_elog"] + ": " + request.form.get(f"question_{i}") + "\n"
+ elif question["type"] == "checkbox":
+ if request.form.get(f"hidden_{i}") == 'True':
+ report += f"[x] {question['label_elog']}\n"
+ else:
+ report += f"[ ] {question['label_elog']}\n"
+ except Exception as e:
+ print(e, flush=True)
+
+ print(report, flush=True)
+ send_to_elog(report, subject=checklist_name, author=config["username"], category="Slow controls", msg_id=None, password=config["password"])
+
+ # Tell the user that checklist is done.
+ return '
Checklist successfully submitted. You can go back to the start page .