Skip to content

Commit

Permalink
añadido soporte para preguntas de tipo essay
Browse files Browse the repository at this point in the history
  • Loading branch information
fvarrui committed Feb 18, 2024
1 parent 30cd0d7 commit e2fc4f5
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 63 deletions.
25 changes: 22 additions & 3 deletions .actirepo/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def _drop_text_size(text):
"""
return htmlsize(html)

# format bytes to human readable format
def _format_bytes(size):
power = 2**10
n = 0
power_labels = { 0 : 'B', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB' }
while size > power:
size /= power
n += 1
return f"{size:.0f} {power_labels[n]}"

# render question as image
def _render_image(question, destination_dir):
type = question.get("type")
Expand Down Expand Up @@ -191,7 +201,6 @@ def _render_image(question, destination_dir):
} for drag in question.findall('drag')
],
"background": f"data:{_get_mimetype(background_file)};{background_file.get('encoding')},{background_file.text}",
"icon": f"{__icons_url__}/crosshairs.png"
}
)
case "ddimageortext":
Expand Down Expand Up @@ -220,15 +229,25 @@ def _render_image(question, destination_dir):
}
}
)
pprint(question_data)
case "essay":
question_data.update(
{
"editor": question.find('responseformat').text != 'noinline',
"response_lines": int(question.find('responsefieldlines').text),
"file_upload": int(question.find('attachments').text) > 0,
"max_size": _format_bytes(int(question.find('maxbytes').text)) if int(question.find('maxbytes').text) > 0 else "Por defecto",
"max_files": int(question.find('attachments').text),
"file_types": question.find('filetypeslist').text.split(',') if not question.find('filetypeslist').text is None else []
}
)
case _:
return

# render html from template
templates_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
env = Environment(loader = FileSystemLoader(templates_path, encoding='utf8'))
template = env.get_template(f'{question_data['type']}.template.html')
html = template.render(question = question_data)
html = template.render(question = question_data, icons_url = __icons_url__)

# html to image
image_filename = _get_valid_image_filename(destination_dir, question_data['name'])
Expand Down
4 changes: 2 additions & 2 deletions .actirepo/templates/ddmarker.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span tabindex="0" style="box-sizing:border-box;display:none;position:relative;margin:10px;vertical-align:top;cursor:move;">
<img
alt="" aria-hidden="true"
src="{{ question.icon }}"
src="{{ icons_url }}/crosshairs.png"
style="font-size:16px;width: 16px;height:16px;margin:0px 8px 0px 0px;padding:0px;box-sizing:content-box;vertical-align:middle;border-style:none;position:absolute;left:-7px;top:-7px;" />
<span
style="box-sizing:border-box;white-space:nowrap;margin:0px 5px;z-index:3;background-color:rgb(255, 255, 255);border:2px solid rgb(0, 0, 0);padding:5px;display:inline-block;zoom:1;border-radius:10px;color:rgb(0, 0, 0);opacity:0.6;">
Expand All @@ -22,7 +22,7 @@
<span tabindex="0" style="user-select:none;box-sizing:border-box;position:relative;display:inline-block;margin:10px;vertical-align:top;cursor:move;">
<img
alt="" aria-hidden="true"
src="{{ question.icon }}"
src="{{ icons_url }}/crosshairs.png"
style="font-size:16px;width: 16px;height:16px;margin:0px 8px 0px 0px;padding:0px;box-sizing:content-box;vertical-align:middle;border-style:none;position:absolute;left:-7px;top:-7px;" />
<span
style="box-sizing:border-box;white-space:nowrap;margin:0px 5px;z-index:3;background-color:rgb(255, 255, 255);border:2px solid rgb(0, 0, 0);padding:5px;display:inline-block;zoom:1;border-radius:10px;color:rgb(0, 0, 0);opacity:0.6;">
Expand Down
87 changes: 31 additions & 56 deletions .actirepo/templates/essay.template.html

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions .actirepo/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Ficheros de preguntas disponibles en esta actividad:



#### Ensayo


![ensayo-adjunto-y-texto_0.png](images/ensayo-adjunto-y-texto_0.png)

![ensayo-fichero-adjunto_0.png](images/ensayo-fichero-adjunto_0.png)

![ensayo-texto_0.png](images/ensayo-texto_0.png)



#### Opción múltiple


Expand Down
Binary file modified .actirepo/test/images/arrastrar-y-soltar-marcadores_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .actirepo/test/images/ensayo-texto_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions .actirepo/test/questions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
<maxwordlimit></maxwordlimit>
<attachments>1</attachments>
<attachmentsrequired>1</attachmentsrequired>
<maxbytes>0</maxbytes>
<filetypeslist></filetypeslist>
<maxbytes>5242880</maxbytes>
<filetypeslist>.pdf,.odt</filetypeslist>
<graderinfo format="html">
<text></text>
</graderinfo>
Expand Down

0 comments on commit e2fc4f5

Please sign in to comment.