Commit ef5d7e48 authored by Jérémie Passerat's avatar Jérémie Passerat

Cycle complet xml numerique

parent 9339d9c6
...@@ -985,21 +985,21 @@ class ContenuDao: ...@@ -985,21 +985,21 @@ class ContenuDao:
i += 1 i += 1
print ("A la sortie, i = ", i) print("A la sortie, i = ", i)
print ("J'ai ", len(elements_contenu["liste_reponse"]), " reponses") print("J'ai ", len(elements_contenu["liste_reponse"]), " reponses")
if i < len(elements_contenu["liste_reponse"]): if i < len(elements_contenu["liste_reponse"]):
print("Je le ai ", len(elements_contenu["liste_reponse"]) - i, " nouveaux contenus") print("Je le ai ", len(elements_contenu["liste_reponse"]) - i, " nouveaux contenus")
for question in root.iter('question'): for question in root.iter('question'):
# eltQuestion = root.iter("question") # eltQuestion = root.iter("question")
newAnswer = SubElement(question, "answer") new_answer = SubElement(question, "answer")
newAnswer.attrib["fraction"] = elements_contenu["liste_note"][i] new_answer.attrib["fraction"] = elements_contenu["liste_note"][i]
newAnswer.attrib["format"] = "moodle_auto_format" new_answer.attrib["format"] = "moodle_auto_format"
text = SubElement(newAnswer, "text") text = SubElement(new_answer, "text")
text.text = elements_contenu["liste_reponse"][i] text.text = elements_contenu["liste_reponse"][i]
feedback = SubElement(newAnswer, "feedback") feedback = SubElement(new_answer, "feedback")
textFeedback = SubElement(feedback, "text") text_feedback = SubElement(feedback, "text")
textFeedback.text = elements_contenu["liste_feedback"][i] text_feedback.text = elements_contenu["liste_feedback"][i]
i += 1 i += 1
# # for k in range(3): # # for k in range(3):
...@@ -1028,74 +1028,95 @@ class ContenuDao: ...@@ -1028,74 +1028,95 @@ class ContenuDao:
answer.attrib["fraction"] = elements_contenu["liste_note"][i] answer.attrib["fraction"] = elements_contenu["liste_note"][i]
for question in answer.iter('text'): for question in answer.iter('text'):
if question.text is not None: if question.text is not None:
question.text = elements_contenu["liste_question"][i] question.text = elements_contenu["liste_reponse"][i]
for feedback in answer.iter('feedback'): for feedback in answer.iter('feedback'):
for feed in feedback.iter('text'): for feed in feedback.iter('text'):
feed.text = elements_contenu["liste_feedback"][0] feed.text = elements_contenu["liste_feedback"][i]
i += 1
if i < len(elements_contenu["liste_reponse"]): if i < len(elements_contenu["liste_reponse"]):
print("Je le ai ", len(elements_contenu["liste_reponse"]) - i, " nouveaux contenus") print("Je le ai ", len(elements_contenu["liste_reponse"]) - i, " nouveaux contenus")
for question in root.iter('question'): for question in root.iter('question'):
# eltQuestion = root.iter("question") # eltQuestion = root.iter("question")
newAnswer = SubElement(question, "answer") new_answer = SubElement(question, "answer")
newAnswer.attrib["fraction"] = elements_contenu["liste_note"][i] new_answer.attrib["fraction"] = elements_contenu["liste_note"][i]
newAnswer.attrib["format"] = "html" new_answer.attrib["format"] = "html"
text = SubElement(newAnswer, "text") text = SubElement(new_answer, "text")
text.text = elements_contenu["liste_reponse"][i] text.text = elements_contenu["liste_reponse"][i]
feedback = SubElement(newAnswer, "feedback") feedback = SubElement(new_answer, "feedback")
textFeedback = SubElement(feedback, "text") text_feedback = SubElement(feedback, "text")
textFeedback.text = elements_contenu["liste_feedback"][i] text_feedback.text = elements_contenu["liste_feedback"][i]
i += 1 i += 1
elif elements_contenu["type_question"] == "numerical" or \ elif elements_contenu["type_question"] == "numerical" or \
elements_contenu["type_question"] == "calculatedsimple": elements_contenu["type_question"] == "calculatedsimple":
pass pass
# for unit in root.iter('unitgradingtype'): for unit in root.iter('unitgradingtype'):
# elements_question["traitement_unite"] = unit.text unit.text = elements_contenu["traitement_unite"]
#
# for showunits in root.iter('showunits'): for showunits in root.iter('showunits'):
# elements_question["saisie_unite"] = showunits.text showunits.text = elements_contenu["saisie_unite"]
#
# for unitsleft in root.iter('unitsleft'): for unitsleft in root.iter('unitsleft'):
# elements_question["position_unite"] = unitsleft.text unitsleft.text = elements_contenu["position_unite"]
#
# liste_unite_nom = [] i = 0
# for unit_name in root.iter('unit_name'): for unit_name in root.iter('unit_name'):
# liste_unite_nom.append(unit_name.text) if unit_name is not None:
# for k in range(3): unit_name.text = elements_contenu["liste_unite_nom"][i]
# liste_unite_nom.append('') i += 1
#
# liste_unite_coef = [] i = 0
# for multiplier in root.iter('multiplier'): for multiplier in root.iter('multiplier'):
# liste_unite_coef.append(multiplier.text) if multiplier is not None:
# for k in range(3): multiplier.text = elements_contenu["liste_unite_coef"][i]
# liste_unite_coef.append('') i += 1
#
# elements_question["liste_unite_nom"] = liste_unite_nom # on ajoute les éventuelles nouvelles unités
# elements_question["liste_unite_coef"] = liste_unite_coef if i < len(elements_contenu["liste_unite_nom"]):
# for question in root.iter('question'):
# liste_reponse = [] for unit in question.iter('units'):
# liste_note = [] print("1. : ", str(ET.tostring(unit)))
# liste_feedback = [] new_unit = SubElement(unit, "unit")
# liste_tolerance = [] multiplier = SubElement(new_unit, "multiplier")
# for answer in root.iter('answer'): multiplier.text = elements_contenu["liste_unite_coef"][i]
# liste_note.append(answer.attrib["fraction"]) unit_name = SubElement(new_unit, "unit_name")
# for question in answer.iter('text'): unit_name.text = elements_contenu["liste_unite_nom"][i]
# if question.text is not None:
# liste_reponse.append(question.text) # print("Je le ai ", len(elements_contenu["liste_note"]), " notes, ", len(elements_contenu["liste_feedback"]), " feedbacks, ",
# for feedback in answer.iter('feedback'): # len(elements_contenu["liste_reponse"]), " reponses et ", len(elements_contenu["liste_tolerance"]), "tolerances")
# for feed in feedback.iter('text'):
# liste_feedback.append(feed.text) i = 0
# for tolerance in answer.iter('tolerance'): for answer in root.iter('answer'):
# #print ("tolerance : ", tolerance.text) answer.attrib["fraction"] = elements_contenu["liste_note"][i]
# if tolerance.text is not None: for question in answer.iter('text'):
# liste_tolerance.append(tolerance.text) if question.text is not None:
# question.text = elements_contenu["liste_reponse"][i]
# elements_question["liste_reponse"] = liste_reponse for feedback in answer.iter('feedback'):
# elements_question["liste_note"] = liste_note for feed in feedback.iter('text'):
# elements_question["liste_feedback"] = liste_feedback feed.text = elements_contenu["liste_feedback"][i]
# elements_question["liste_tolerance"] = liste_tolerance for tolerance in answer.iter('tolerance'):
if tolerance.text is not None:
tolerance.text = elements_contenu["liste_tolerance"][i]
i += 1
# on ajoute les éventuelles nouvelles réponses
if i < len(elements_contenu["liste_reponse"]):
for question in root.iter('question'):
# eltQuestion = root.iter("question")
new_answer = SubElement(question, "answer")
new_answer.attrib["fraction"] = elements_contenu["liste_note"][i]
new_answer.attrib["format"] = "moodle_auto_format"
text = SubElement(new_answer, "text")
text.text = elements_contenu["liste_reponse"][i]
feedback = SubElement(new_answer, "feedback")
feedback.attrib["format"] = "html"
text_feedback = SubElement(feedback, "text")
text_feedback.text = elements_contenu["liste_feedback"][i]
tolerance = SubElement(new_answer, "tolerance")
tolerance.text = elements_contenu["liste_tolerance"][i]
i += 1
# on maj le fichier du contenu # on maj le fichier du contenu
Utils().changer_texte_fichier(ObjectId(id_contenu), ET.tostring(root).decode("utf-8"), Utils().changer_texte_fichier(ObjectId(id_contenu), ET.tostring(root).decode("utf-8"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment