excel2moodle 0.5.2__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {excel2moodle-0.5.2/excel2moodle.egg-info → excel2moodle-0.6.1}/PKG-INFO +34 -2
  2. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/README.md +32 -0
  3. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/__main__.py +3 -2
  4. excel2moodle-0.6.1/excel2moodle/core/bullets.py +98 -0
  5. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/dataStructure.py +3 -4
  6. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/globals.py +3 -8
  7. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/parser.py +37 -65
  8. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/question.py +144 -76
  9. excel2moodle-0.6.1/excel2moodle/extra/variableGenerator.py +250 -0
  10. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/question_types/cloze.py +156 -125
  11. excel2moodle-0.6.1/excel2moodle/question_types/nfm.py +73 -0
  12. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/UI_mainWindow.py +63 -36
  13. excel2moodle-0.6.1/excel2moodle/ui/UI_variableGenerator.py +197 -0
  14. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/appUi.py +90 -23
  15. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/dialogs.py +44 -77
  16. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/equationChecker.py +2 -2
  17. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/treewidget.py +9 -24
  18. {excel2moodle-0.5.2 → excel2moodle-0.6.1/excel2moodle.egg-info}/PKG-INFO +34 -2
  19. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle.egg-info/SOURCES.txt +4 -2
  20. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle.egg-info/requires.txt +1 -1
  21. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/pyproject.toml +2 -2
  22. excel2moodle-0.6.1/test/test_bullets.py +45 -0
  23. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/test/test_nfmParsing.py +9 -11
  24. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/test/test_parseQuestion.py +0 -1
  25. excel2moodle-0.5.2/excel2moodle/core/numericMultiQ.py +0 -80
  26. excel2moodle-0.5.2/excel2moodle/question_types/nfm.py +0 -135
  27. excel2moodle-0.5.2/excel2moodle/ui/windowDoc.py +0 -27
  28. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/LICENSE +0 -0
  29. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/MANIFEST.in +0 -0
  30. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/__init__.py +0 -0
  31. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/__init__.py +0 -0
  32. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/category.py +0 -0
  33. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/etHelpers.py +0 -0
  34. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/exceptions.py +0 -0
  35. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/settings.py +0 -0
  36. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/stringHelpers.py +0 -0
  37. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/core/validator.py +0 -0
  38. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/extra/__init__.py +0 -0
  39. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/extra/equationVerification.py +0 -0
  40. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/logger.py +0 -0
  41. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/question_types/__init__.py +0 -0
  42. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/question_types/mc.py +0 -0
  43. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/question_types/nf.py +0 -0
  44. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/UI_equationChecker.py +0 -0
  45. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/UI_exportSettingsDialog.py +0 -0
  46. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/UI_variantDialog.py +0 -0
  47. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle/ui/__init__.py +0 -0
  48. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle.egg-info/dependency_links.txt +0 -0
  49. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle.egg-info/entry_points.txt +0 -0
  50. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/excel2moodle.egg-info/top_level.txt +0 -0
  51. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/setup.cfg +0 -0
  52. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/test/test_picture.py +0 -0
  53. {excel2moodle-0.5.2 → excel2moodle-0.6.1}/test/test_questionDataGet.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: excel2moodle
3
- Version: 0.5.2
3
+ Version: 0.6.1
4
4
  Summary: A package for converting questions from a spreadsheet, to valid moodle-xml
5
5
  Author: Jakob Bosse
6
6
  License-Expression: GPL-3.0-or-later
@@ -12,11 +12,11 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.10
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: pyside6>=6.8.0
16
15
  Requires-Dist: pandas>=2.1.3
17
16
  Requires-Dist: lxml>=5.4.0
18
17
  Requires-Dist: asteval>=1.0.6
19
18
  Requires-Dist: python-calamine>=0.3.2
19
+ Requires-Dist: pyside6-essentials>=6.8.0
20
20
  Dynamic: license-file
21
21
 
22
22
  # excel 2 Moodle
@@ -81,6 +81,38 @@ If You want to support my work as well, you can by me a [coffee](https://ko-fi.c
81
81
 
82
82
  # Changelogs
83
83
 
84
+ ## 0.6.1 (2025-07-12)
85
+ Fixing import error caused by dumping pyside meta package
86
+
87
+ ### bugfix (1 change)
88
+
89
+ - [fixing pyside import error](https://gitlab.com/jbosse3/excel2moodle/-/commit/e5e0fc7695caa1a6864785828ff7311fa9624ad4)
90
+
91
+ ## 0.6.0 (2025-07-12)
92
+ Added variable generator and other architechtural improvements
93
+
94
+ ### documentation (1 change)
95
+
96
+ - [Documenting variable generator usage](https://gitlab.com/jbosse3/excel2moodle/-/commit/3e4d3019b29872b5cfddf5539d5ebe7638bca049)
97
+
98
+ ### feature (5 changes)
99
+
100
+ - [Opening spreadsheet file works from within excel2moodle](https://gitlab.com/jbosse3/excel2moodle/-/commit/9470f12ea5f098745a3210b281a5144a938ae8b5)
101
+ - [Variables are copied to clipboard](https://gitlab.com/jbosse3/excel2moodle/-/commit/87a7e5ec75f899b293e89ad3c1742567e3ec1c29)
102
+ - [Removed dependence on pyside6-addons](https://gitlab.com/jbosse3/excel2moodle/-/commit/2b3a7cf48581c14bd9cb570cd61d1d41aa410e11)
103
+ - [Var Generator ready](https://gitlab.com/jbosse3/excel2moodle/-/commit/ea97f0639dc35a4c99a64ae3976ccc8a0ac5d109)
104
+ - [Merge development of BulletsObj, Parametrization and VarGenerator](https://gitlab.com/jbosse3/excel2moodle/-/commit/40b46f3c143e082f1bb985d6c8c4e68bb6b6a7a8)
105
+
106
+ ### improvement (7 changes)
107
+
108
+ - [Adapted Param. Parser to use bullet Obj](https://gitlab.com/jbosse3/excel2moodle/-/commit/194cab7cc6aecb2d25d1cb9c1538ed7d607dd9e1)
109
+ - [Added bulleList Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/4ea982b8d8dc270675d2cb059c59fa980ce38894)
110
+ - [Parametrics in beta stage](https://gitlab.com/jbosse3/excel2moodle/-/commit/7d04d8ef2fc603c1b12b6934c827ce079df5d540)
111
+ - [Refactor parse() method, to construct complete xml-Tree](https://gitlab.com/jbosse3/excel2moodle/-/commit/8dc4bea9aa0673d39357115254dd55b02c04114e)
112
+ - [Refactored question assembly to only update fields.](https://gitlab.com/jbosse3/excel2moodle/-/commit/d7accb69be3b4a1e65f59eeecfb463f2663fabd4)
113
+ - [Adapted NFM Question to parametricResult](https://gitlab.com/jbosse3/excel2moodle/-/commit/fe552cd2b538ca8886415c200e4a2a3ecc1fbb2f) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
114
+ - [Implemented ParametricResult Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/e36d025955f1cab8e0542d66263ab70e3d8980df) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
115
+
84
116
  ## 0.5.2 (2025-06-30)
85
117
  Extended Documentation and bugfix for import Module
86
118
 
@@ -60,6 +60,38 @@ If You want to support my work as well, you can by me a [coffee](https://ko-fi.c
60
60
 
61
61
  # Changelogs
62
62
 
63
+ ## 0.6.1 (2025-07-12)
64
+ Fixing import error caused by dumping pyside meta package
65
+
66
+ ### bugfix (1 change)
67
+
68
+ - [fixing pyside import error](https://gitlab.com/jbosse3/excel2moodle/-/commit/e5e0fc7695caa1a6864785828ff7311fa9624ad4)
69
+
70
+ ## 0.6.0 (2025-07-12)
71
+ Added variable generator and other architechtural improvements
72
+
73
+ ### documentation (1 change)
74
+
75
+ - [Documenting variable generator usage](https://gitlab.com/jbosse3/excel2moodle/-/commit/3e4d3019b29872b5cfddf5539d5ebe7638bca049)
76
+
77
+ ### feature (5 changes)
78
+
79
+ - [Opening spreadsheet file works from within excel2moodle](https://gitlab.com/jbosse3/excel2moodle/-/commit/9470f12ea5f098745a3210b281a5144a938ae8b5)
80
+ - [Variables are copied to clipboard](https://gitlab.com/jbosse3/excel2moodle/-/commit/87a7e5ec75f899b293e89ad3c1742567e3ec1c29)
81
+ - [Removed dependence on pyside6-addons](https://gitlab.com/jbosse3/excel2moodle/-/commit/2b3a7cf48581c14bd9cb570cd61d1d41aa410e11)
82
+ - [Var Generator ready](https://gitlab.com/jbosse3/excel2moodle/-/commit/ea97f0639dc35a4c99a64ae3976ccc8a0ac5d109)
83
+ - [Merge development of BulletsObj, Parametrization and VarGenerator](https://gitlab.com/jbosse3/excel2moodle/-/commit/40b46f3c143e082f1bb985d6c8c4e68bb6b6a7a8)
84
+
85
+ ### improvement (7 changes)
86
+
87
+ - [Adapted Param. Parser to use bullet Obj](https://gitlab.com/jbosse3/excel2moodle/-/commit/194cab7cc6aecb2d25d1cb9c1538ed7d607dd9e1)
88
+ - [Added bulleList Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/4ea982b8d8dc270675d2cb059c59fa980ce38894)
89
+ - [Parametrics in beta stage](https://gitlab.com/jbosse3/excel2moodle/-/commit/7d04d8ef2fc603c1b12b6934c827ce079df5d540)
90
+ - [Refactor parse() method, to construct complete xml-Tree](https://gitlab.com/jbosse3/excel2moodle/-/commit/8dc4bea9aa0673d39357115254dd55b02c04114e)
91
+ - [Refactored question assembly to only update fields.](https://gitlab.com/jbosse3/excel2moodle/-/commit/d7accb69be3b4a1e65f59eeecfb463f2663fabd4)
92
+ - [Adapted NFM Question to parametricResult](https://gitlab.com/jbosse3/excel2moodle/-/commit/fe552cd2b538ca8886415c200e4a2a3ecc1fbb2f) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
93
+ - [Implemented ParametricResult Object](https://gitlab.com/jbosse3/excel2moodle/-/commit/e36d025955f1cab8e0542d66263ab70e3d8980df) ([merge request](https://gitlab.com/jbosse3/excel2moodle/-/merge_requests/5))
94
+
63
95
  ## 0.5.2 (2025-06-30)
64
96
  Extended Documentation and bugfix for import Module
65
97
 
@@ -2,9 +2,10 @@
2
2
 
3
3
  import logging.config as logConfig
4
4
  import signal
5
+ import sys
5
6
  from pathlib import Path
6
7
 
7
- from PySide6 import QtWidgets, sys
8
+ from PySide6.QtWidgets import QApplication
8
9
 
9
10
  import excel2moodle
10
11
  from excel2moodle import e2mMetadata, mainLogger
@@ -23,7 +24,7 @@ def main() -> None:
23
24
  logfile.replace(f"{logfile}.old")
24
25
  logConfig.dictConfig(config=loggerConfig)
25
26
  signal.signal(signal.SIGINT, signal.SIG_DFL)
26
- app = QtWidgets.QApplication(sys.argv)
27
+ app = QApplication(sys.argv)
27
28
  settings = Settings()
28
29
  database: dataStructure.QuestionDB = dataStructure.QuestionDB(settings)
29
30
  window = ui.MainWindow(settings, database)
@@ -0,0 +1,98 @@
1
+ import logging
2
+ import re
3
+
4
+ import lxml.etree as ET
5
+
6
+ from excel2moodle.core import stringHelpers
7
+ from excel2moodle.core.globals import TextElements
8
+ from excel2moodle.core.question import ParametricQuestion
9
+ from excel2moodle.logger import LogAdapterQuestionID
10
+
11
+ loggerObj = logging.getLogger(__name__)
12
+
13
+
14
+ class BulletList:
15
+ def __init__(self, rawBullets: list[str], qID: str) -> None:
16
+ self.rawBullets: list[str] = rawBullets
17
+ self.element: ET.Element = ET.Element("ul")
18
+ self.bullets: dict[str, BulletP] = {}
19
+ self.id = qID
20
+ self.logger = LogAdapterQuestionID(loggerObj, {"qID": self.id})
21
+ self._setupBullets(rawBullets)
22
+
23
+ def updateBullets(
24
+ self, variables: dict[str, list[float]], variant: int = 1
25
+ ) -> None:
26
+ for var, bullet in self.bullets.items():
27
+ bullet.update(value=variables[var][variant - 1])
28
+
29
+ def getVariablesDict(self, question: ParametricQuestion) -> dict[str, list[float]]:
30
+ """Read variabel values for vars in `question.rawData`.
31
+
32
+ Returns
33
+ -------
34
+ A dictionary containing a list of values for each variable name
35
+
36
+ """
37
+ keyList = self.varNames
38
+ dic: dict = {}
39
+ for k in keyList:
40
+ val = question.rawData[k.lower()]
41
+ if isinstance(val, str):
42
+ li = stringHelpers.getListFromStr(val)
43
+ variables: list[float] = [float(i.replace(",", ".")) for i in li]
44
+ dic[str(k)] = variables
45
+ else:
46
+ dic[str(k)] = [str(val)]
47
+ loggerObj.debug("The following variables were provided: %s", dic)
48
+ return dic
49
+
50
+ @property
51
+ def varNames(self) -> list[str]:
52
+ names = [i for i in self.bullets if isinstance(i, str)]
53
+ if len(names) > 0:
54
+ self.logger.debug("returning Var names: %s", names)
55
+ return names
56
+ msg = "Bullet variable names not given."
57
+ raise ValueError(msg)
58
+
59
+ def _setupBullets(self, bps: list[str]) -> ET.Element:
60
+ self.logger.debug("Formatting the bulletpoint list")
61
+ varFinder = re.compile(r"=\s*\{(\w+)\}")
62
+ for i, item in enumerate(bps):
63
+ sc_split = item.split()
64
+ name = sc_split[0]
65
+ var = sc_split[1]
66
+ quant = sc_split[3]
67
+ unit = sc_split[4]
68
+
69
+ match = re.search(varFinder, item)
70
+ if match is None:
71
+ self.logger.debug("Got a normal bulletItem")
72
+ num: float = float(quant.replace(",", "."))
73
+ bulletName: str = str(i + 1)
74
+ else:
75
+ bulletName = match.group(1)
76
+ num: float = 0.0
77
+ self.logger.debug("Got an variable bulletItem, match: %s", match)
78
+
79
+ self.bullets[bulletName] = BulletP(name=name, var=var, unit=unit, value=num)
80
+ self.element.append(self.bullets[bulletName].element)
81
+ return self.element
82
+
83
+
84
+ class BulletP:
85
+ def __init__(self, name: str, var: str, unit: str, value: float = 0.0) -> None:
86
+ self.name: str = name
87
+ self.var: str = var
88
+ self.unit: str = unit
89
+ self.element: ET.Element
90
+ self.update(value=value)
91
+
92
+ def update(self, value: float = 1) -> None:
93
+ if not hasattr(self, "element"):
94
+ self.element = TextElements.LISTITEM.create()
95
+ valuestr = str(value).replace(".", r",\!")
96
+ self.element.text = (
97
+ f"{self.name} \\( {self.var} = {valuestr} \\mathrm{{ {self.unit} }} \\)"
98
+ )
@@ -11,8 +11,8 @@ from typing import TYPE_CHECKING
11
11
 
12
12
  import lxml.etree as ET # noqa: N812
13
13
  import pandas as pd
14
- from PySide6 import QtWidgets
15
14
  from PySide6.QtCore import QObject, Signal
15
+ from PySide6.QtWidgets import QDialog
16
16
 
17
17
  from excel2moodle.core import stringHelpers
18
18
  from excel2moodle.core.category import Category
@@ -381,10 +381,9 @@ class QuestionDB:
381
381
  if hasattr(q, "variants") and q.variants is not None:
382
382
  if variant == 0 or variant > q.variants:
383
383
  dialog = QuestionVariantDialog(self.window, q)
384
- if dialog.exec() == QtWidgets.QDialog.Accepted:
384
+ if dialog.exec() == QDialog.Accepted:
385
385
  variant = dialog.variant
386
386
  logger.debug("Die Fragen-Variante %s wurde gewählt", variant)
387
387
  else:
388
388
  logger.warning("Keine Fragenvariante wurde gewählt.")
389
- q.assemble(variant=variant)
390
- tree.append(q.element)
389
+ tree.append(q.getUpdatedElement(variant=variant))
@@ -17,14 +17,9 @@ class TextElements(Enum):
17
17
  SPANRED = "span", "color: rgb(239, 69, 64)"
18
18
  SPANGREEN = "span", "color: rgb(152, 202, 62)"
19
19
  SPANORANGE = "span", "color: rgb(152, 100, 100)"
20
- ULIST = (
21
- "ul",
22
- "",
23
- )
24
- LISTITEM = (
25
- "li",
26
- "text-align: left;",
27
- )
20
+ ULIST = "ul", ""
21
+ LISTITEM = "li", "text-align: left;"
22
+ DIV = "div", ""
28
23
 
29
24
  def create(self, tag: str | None = None):
30
25
  if tag is None:
@@ -1,9 +1,9 @@
1
1
  import logging
2
- import re
3
2
 
4
3
  import lxml.etree as ET
5
4
 
6
5
  import excel2moodle.core.etHelpers as eth
6
+ from excel2moodle.core.bullets import BulletList
7
7
  from excel2moodle.core.exceptions import QNotParsedException
8
8
  from excel2moodle.core.globals import (
9
9
  Tags,
@@ -58,65 +58,19 @@ class QuestionParser:
58
58
  )
59
59
  return bool(self.question.picture.ready)
60
60
 
61
- def setMainText(self) -> None:
62
- paragraphs: list[ET._Element] = [TextElements.PLEFT.create()]
63
- ET.SubElement(paragraphs[0], "b").text = f"ID {self.question.id}"
61
+ def getMainTextElement(self) -> ET.Element:
62
+ """Get the root question Text with the question paragraphs."""
63
+ textHTMLroot: ET._Element = ET.Element("div")
64
+ ET.SubElement(
65
+ ET.SubElement(textHTMLroot, "p"), "b"
66
+ ).text = f"ID {self.question.id}"
64
67
  text = self.rawInput[Tags.TEXT]
65
68
  for t in text:
66
- paragraphs.append(TextElements.PLEFT.create())
67
- paragraphs[-1].text = t
68
- self.question.qtextParagraphs = paragraphs
69
+ par = TextElements.PLEFT.create()
70
+ par.text = t
71
+ textHTMLroot.append(par)
69
72
  self.logger.debug("Created main Text with: %s paragraphs", len(text))
70
-
71
- def setBPoints(self) -> None:
72
- """If there bulletPoints are set in the Spreadsheet it creates an unordered List-Element in ``Question.bulletList``."""
73
- if Tags.BPOINTS in self.rawInput:
74
- bps: list[str] = self.rawInput[Tags.BPOINTS]
75
- try:
76
- bulletList = self.formatBulletList(bps)
77
- except IndexError:
78
- msg = f"konnt Bullet Liste {self.question.id} nicht generieren"
79
- raise QNotParsedException(
80
- msg,
81
- self.question.id,
82
- # exc_info=e,
83
- )
84
- self.logger.debug(
85
- "Generated BPoint List: \n %s",
86
- ET.tostring(bulletList, encoding="unicode"),
87
- )
88
- self.question.bulletList = bulletList
89
-
90
- def formatBulletList(self, bps: list[str]) -> ET.Element:
91
- self.logger.debug("Formatting the bulletpoint list")
92
- name = []
93
- var = []
94
- quant = []
95
- unit = []
96
- unorderedList = TextElements.ULIST.create()
97
- for item in bps:
98
- sc_split = item.split()
99
- name.append(sc_split[0])
100
- var.append(sc_split[1])
101
- quant.append(sc_split[3])
102
- unit.append(sc_split[4])
103
- for i in range(len(name)):
104
- if re.fullmatch(r"{\w+}", quant[i]):
105
- self.logger.debug("Got an variable bulletItem")
106
- num_s = quant[i]
107
- else:
108
- self.logger.debug("Got a normal bulletItem")
109
- num = quant[i].split(",")
110
- if len(num) == 2:
111
- num_s = f"{num[0]!s},\\!{num[1]!s}~"
112
- else:
113
- num_s = f"{num[0]!s},\\!0~"
114
- bullet = TextElements.LISTITEM.create()
115
- bullet.text = (
116
- f"{name[i]}: \\( {var[i]} = {num_s} \\mathrm{{ {unit[i]} }}\\)\n"
117
- )
118
- unorderedList.append(bullet)
119
- return unorderedList
73
+ return textHTMLroot
120
74
 
121
75
  def appendToTmpEle(
122
76
  self,
@@ -148,7 +102,7 @@ class QuestionParser:
148
102
  """Parse the Question.
149
103
 
150
104
  Generates an new Question Element stored as ``self.tmpEle:ET.Element``
151
- if no Exceptions are raised, ``self.tmpEle`` is passed to ``self.question.element``
105
+ if no Exceptions are raised, ``self.tmpEle`` is passed to ``question.element``
152
106
  """
153
107
  self.logger.info("Starting to parse")
154
108
  self.tmpEle: ET.Elemnt = ET.Element(
@@ -156,21 +110,39 @@ class QuestionParser:
156
110
  )
157
111
  self.appendToTmpEle(XMLTags.NAME, text=Tags.NAME, txtEle=True)
158
112
  self.appendToTmpEle(XMLTags.ID, text=self.question.id)
159
- if self.hasPicture():
160
- self.tmpEle.append(self.question.picture.element)
161
- self.tmpEle.append(ET.Element(XMLTags.QTEXT, format="html"))
113
+ textRootElem = ET.Element(XMLTags.QTEXT, format="html")
114
+ mainTextEle = ET.SubElement(textRootElem, "text")
115
+ self.tmpEle.append(textRootElem)
162
116
  self.appendToTmpEle(XMLTags.POINTS, text=str(self.question.points))
163
117
  self._appendStandardTags()
164
118
  for feedb in self.genFeedbacks:
165
119
  self.tmpEle.append(eth.getFeedBEle(feedb))
120
+
121
+ self.htmlRoot = ET.Element("div")
122
+ self.htmlRoot.append(self.getMainTextElement())
123
+ if Tags.BPOINTS in self.rawInput:
124
+ bps: list[str] = self.rawInput[Tags.BPOINTS]
125
+ try:
126
+ bullets: BulletList = BulletList(bps, self.question.id)
127
+ except IndexError:
128
+ msg = f"konnt Bullet Liste {self.question.id} nicht generieren"
129
+ raise QNotParsedException(
130
+ msg,
131
+ self.question.id,
132
+ )
133
+ self.htmlRoot.append(bullets.element)
134
+ self.question.bulletList = bullets
135
+ if self.hasPicture():
136
+ self.htmlRoot.append(self.question.picture.htmlTag)
137
+ textRootElem.append(self.question.picture.element)
166
138
  ansList = self._parseAnswers()
167
- self.setMainText()
168
- self.setBPoints()
169
139
  if ansList is not None:
170
140
  for ele in ansList:
171
141
  self.tmpEle.append(ele)
172
- self.question.element = self.tmpEle
142
+ self.question._element = self.tmpEle
143
+ self.question.htmlRoot = self.htmlRoot
173
144
  self.question.isParsed = True
145
+ self.question.textElement = mainTextEle
174
146
  self.logger.info("Sucessfully parsed")
175
147
 
176
148
  def getFeedBEle(
@@ -195,7 +167,7 @@ class QuestionParser:
195
167
 
196
168
  def getNumericAnsElement(
197
169
  self,
198
- result: float,
170
+ result: float = 0.0,
199
171
  fraction: float = 100,
200
172
  format: str = "moodle_auto_format",
201
173
  ) -> ET.Element: