Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle to amc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathieu Loiseau
moodle to amc
Commits
b0d8e1ca
Commit
b0d8e1ca
authored
3 years ago
by
Mathieu Loiseau
Browse files
Options
Downloads
Patches
Plain Diff
multiling + listing
parent
db0f29d0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+2
-0
2 additions, 0 deletions
README.md
XML_Moodle.py
+8
-10
8 additions, 10 deletions
XML_Moodle.py
utils.py
+9
-3
9 additions, 3 deletions
utils.py
with
19 additions
and
13 deletions
README.md
+
2
−
0
View file @
b0d8e1ca
...
@@ -25,3 +25,5 @@ Ce module marche pour MA feuille de style AMC, qui contient :
...
@@ -25,3 +25,5 @@ Ce module marche pour MA feuille de style AMC, qui contient :
}
}
```
```
et où
``{mlang en}``
et
``{mlang other}``
sont utilisés dans moodle.
et où
``{mlang en}``
et
``{mlang other}``
sont utilisés dans moodle.
Mettre
``unsafe``
à
``False``
pour ne pas remplacer les
``<span>``
(
`utils.py`
)
This diff is collapsed.
Click to expand it.
XML_Moodle.py
+
8
−
10
View file @
b0d8e1ca
...
@@ -56,7 +56,7 @@ class Quizz:
...
@@ -56,7 +56,7 @@ class Quizz:
class
Question
:
class
Question
:
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
def
__init__
(
self
,
xmlQ
,
c
,
n
,
f
):
self
.
folder
=
f
self
.
folder
=
f
self
.
q
=
mlang_2_multiling
(
strip_tags
(
xmlQ
.
find
(
"
questiontext/text
"
).
text
,
self
.
folder
)
)
self
.
q
=
strip_tags
(
mlang_2_multiling
(
xmlQ
.
find
(
"
questiontext/text
"
).
text
)
,
self
.
folder
)
self
.
category
=
c
self
.
category
=
c
self
.
id
=
f
"
{
c
[
c
.
rfind
(
'
:
'
)+1
:
]
}
_
{
n
}
"
self
.
id
=
f
"
{
c
[
c
.
rfind
(
'
:
'
)+1
:
]
}
_
{
n
}
"
self
.
env
=
"
todo:
"
+
xmlQ
.
attrib
[
"
type
"
]
self
.
env
=
"
todo:
"
+
xmlQ
.
attrib
[
"
type
"
]
...
@@ -66,15 +66,13 @@ class Question:
...
@@ -66,15 +66,13 @@ class Question:
def
parseImages
(
self
,
file_elements
):
def
parseImages
(
self
,
file_elements
):
for
i
in
file_elements
:
for
i
in
file_elements
:
name
=
i
.
attrib
[
"
name
"
]
name
=
i
.
attrib
[
"
name
"
]
print
(
name
)
im
=
Image
.
open
(
BytesIO
(
base64
.
b64decode
(
i
.
text
)))
im
=
Image
.
open
(
BytesIO
(
base64
.
b64decode
(
i
.
text
)))
ext
=
name
[
name
.
rfind
(
'
.
'
)
+
1
:].
upper
()
ext
=
name
[
name
.
rfind
(
'
.
'
)
+
1
:].
upper
()
im
.
save
(
self
.
folder
+
"
/
"
+
name
,
ext
)
im
.
save
(
self
.
folder
+
"
/
"
+
name
,
ext
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"""
\\
element{
"""
+
self
.
category
+
"""
}{
#return "\\element{" + self.category + "}{\n\t\\begin{" + self.env + "}{" + self.id + "}\\nbpoints{" + score_2_str(self.max) + "}\n\t\t" + self.q + "\\end{" + self.env + "}\n"
\\
begin{
"""
+
self
.
env
+
"""
}{
"""
+
self
.
id
+
"""
}
\\
nbpoints{
"""
+
score_2_str
(
self
.
max
)
+
"""
}
return
""
"""
+
self
.
q
+
"
\\
end{
"
+
self
.
env
+
"
}
\n
"
class
Answer
:
class
Answer
:
def
__init__
(
self
,
t
,
b
,
max
,
fb
):
def
__init__
(
self
,
t
,
b
,
max
,
fb
):
...
@@ -116,8 +114,8 @@ class MCQ(Question):
...
@@ -116,8 +114,8 @@ class MCQ(Question):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
fb
=
a
.
find
(
"
feedback/text
"
).
text
fb
=
a
.
find
(
"
feedback/text
"
).
text
if
fb
!=
None
:
if
fb
!=
None
:
fb
=
mlang_2_multiling
(
strip_tags
(
fb
,
self
.
folder
)
)
fb
=
strip_tags
(
mlang_2_multiling
(
fb
)
,
self
.
folder
)
self
.
choices
.
append
(
Answer
(
mlang_2_multiling
(
strip_tags
(
a
.
find
(
"
text
"
).
text
,
self
.
folder
)
)
,
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
self
.
choices
.
append
(
Answer
(
strip_tags
(
mlang_2_multiling
(
a
.
find
(
"
text
"
).
text
)
,
self
.
folder
),
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
def
get_choice_env
(
self
):
def
get_choice_env
(
self
):
if
self
.
choice_type
==
MCQ
.
VERTICAL
:
if
self
.
choice_type
==
MCQ
.
VERTICAL
:
...
@@ -134,7 +132,7 @@ class MCQ(Question):
...
@@ -134,7 +132,7 @@ class MCQ(Question):
res
+=
"
\n
"
res
+=
"
\n
"
for
c
in
self
.
choices
:
for
c
in
self
.
choices
:
res
+=
str
(
c
)
res
+=
str
(
c
)
res
+=
"
\
n\
t\t\\
end{
"
+
self
.
get_choice_env
()
+
"
}
\n\t\\
end{
"
+
self
.
env
+
"
}
\n
}
\n\n
"
res
+=
"
\t\t\\
end{
"
+
self
.
get_choice_env
()
+
"
}
\n\t\\
end{
"
+
self
.
env
+
"
}
\n
}
\n\n
"
return
res
return
res
class
TF
(
MCQ
):
class
TF
(
MCQ
):
...
@@ -143,14 +141,14 @@ class TF(MCQ):
...
@@ -143,14 +141,14 @@ class TF(MCQ):
self
.
choices
=
[]
self
.
choices
=
[]
self
.
env
=
"
question
"
self
.
env
=
"
question
"
self
.
shuffle
=
False
self
.
shuffle
=
False
if
self
.
__class__
.
__name__
==
"
MCQ
"
:
if
self
.
__class__
.
__name__
==
"
TF
"
:
self
.
__parseAnswers
(
xmlQ
)
self
.
__parseAnswers
(
xmlQ
)
def
__parseAnswers
(
self
,
xmlQ
):
def
__parseAnswers
(
self
,
xmlQ
):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
for
a
in
xmlQ
.
findall
(
"
answer
"
):
fb
=
a
.
find
(
"
feedback/text
"
).
text
fb
=
a
.
find
(
"
feedback/text
"
).
text
if
fb
!=
None
:
if
fb
!=
None
:
fb
=
mlang_2_multiling
(
strip_tags
(
fb
,
self
.
folder
)
)
fb
=
strip_tags
(
mlang_2_multiling
(
fb
)
,
self
.
folder
)
if
a
.
find
(
"
text
"
).
text
==
"
true
"
:
if
a
.
find
(
"
text
"
).
text
==
"
true
"
:
self
.
choices
.
append
(
Answer
(
"
\\
multiling{vrai}{true}
"
,
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
self
.
choices
.
append
(
Answer
(
"
\\
multiling{vrai}{true}
"
,
a
.
attrib
[
'
fraction
'
],
self
.
max
,
fb
))
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
9
−
3
View file @
b0d8e1ca
...
@@ -3,6 +3,8 @@ from re import compile,sub,escape
...
@@ -3,6 +3,8 @@ from re import compile,sub,escape
from
html
import
unescape
from
html
import
unescape
from
urllib.parse
import
unquote
from
urllib.parse
import
unquote
unsafe
=
True
def
html_2_tex
(
text
):
def
html_2_tex
(
text
):
#https://code.activestate.com/recipes/81330-single-pass-multiple-replace/
#https://code.activestate.com/recipes/81330-single-pass-multiple-replace/
# dict = {' ': '~', '>':'>', '<': '<'}
# dict = {' ': '~', '>':'>', '<': '<'}
...
@@ -17,19 +19,23 @@ def html_2_tex(text):
...
@@ -17,19 +19,23 @@ def html_2_tex(text):
def
remove_moodle_cdata
(
txt
,
folder
):
def
remove_moodle_cdata
(
txt
,
folder
):
return
sub
(
r
'
<img src=
"
[^/]*/([^
"
]*)
"
(alt=
"
([^
"
]*)
"
)?[^>]*>
'
,
r
"""
\\begin{figure}[h!]
global
unsafe
res
=
sub
(
r
'
<img src=
"
[^/]*/([^
"
]*)
"
(alt=
"
([^
"
]*)
"
)?[^>]*>
'
,
r
"""
\\begin{figure}[h!]
\\begin{center}
\\begin{center}
\\includegraphics[width=0.8\\linewidth]{$$$$folder$$$$/\1}
\\includegraphics[width=0.8\\linewidth]{$$$$folder$$$$/\1}
\\end{center}
\\end{center}
\\caption{\3}
\\caption{\3}
\\end{figure}
\\end{figure}
"""
,
txt
).
replace
(
"
<![CDATA[
"
,
""
).
replace
(
"
]]>
"
,
""
).
replace
(
"
$$$$folder$$$$
"
,
folder
)
"""
,
txt
).
replace
(
"
<![CDATA[
"
,
""
).
replace
(
"
]]>
"
,
""
).
replace
(
"
$$$$folder$$$$
"
,
folder
).
replace
(
"
<strong>
"
,
"
\\
emph{
"
).
replace
(
"
</strong>
"
,
"
}
"
).
replace
(
"
<pre>
"
,
"
\\
begin{lstlisting}[language=Python]
\n
"
).
replace
(
"
</pre>
"
,
"
\\
end{lstlisting}
\n
"
)
if
unsafe
:
res
=
res
.
replace
(
'
<span style=
"
font:monospace
"
>
'
,
"
\lstinline[language=python]|
"
).
replace
(
'
<span style=
"
font-family:monospace
"
>
'
,
"
\lstinline[language=python]|
"
).
replace
(
"
</span>
"
,
"
|
"
)
return
res
def
strip_tags
(
txt
,
folder
):
def
strip_tags
(
txt
,
folder
):
return
html_2_tex
(
sub
(
compile
(
'
<.*?>
'
),
''
,
remove_moodle_cdata
(
unquote
(
txt
),
folder
)))
return
html_2_tex
(
sub
(
compile
(
'
<.*?>
'
),
''
,
remove_moodle_cdata
(
unquote
(
txt
),
folder
)))
def
mlang_2_multiling
(
txt
):
def
mlang_2_multiling
(
txt
):
return
sub
(
r
"
\{mlang
en\}(
.
*?)\{mlang\}((\{mlang
other\})|(\{mlang
fr\})
)(.*?
)\{mlang\}
"
,
r
"
\\multiling{\
5
}{\1}
"
,
txt
)
return
sub
(
r
"
\{mlang
\s*
en\}(
[^\{]
*?)\{mlang\}
\s*
((\{mlang
\s*
other\})|(\{mlang
\s*
fr\})
|(\{mlang\}))([^\{]*
)\{mlang\}
"
,
r
"
\\multiling{\
6
}{\1}
"
,
txt
)
def
score_2_str
(
v
):
def
score_2_str
(
v
):
if
int
(
v
)
==
float
(
v
):
if
int
(
v
)
==
float
(
v
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment