Skip to content

Commit 69d603a

Browse files
committed
Refactor code to improve maintainability
1 parent 0122c7b commit 69d603a

File tree

10 files changed

+3691
-15739
lines changed

10 files changed

+3691
-15739
lines changed

jupyterquiz/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
All files in the package are distributed under the MIT License
1212
'''
1313

14-
__version__ = '2.9.2.1'
14+
__version__ = '2.9.3'
1515
from .dynamic import display_quiz, capture_responses

jupyterquiz/dynamic.py

Lines changed: 0 additions & 328 deletions
This file was deleted.

jupyterquiz/dynamic/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
dynamic subpackage splitting responsibilities of dynamic.py.
3+
"""
4+
from .display import display_quiz
5+
from .capture import capture_responses
6+
7+
__all__ = ["display_quiz", "capture_responses"]

jupyterquiz/dynamic/capture.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Module for capturing user responses to quizzes.
3+
"""
4+
import string
5+
import random
6+
from IPython.display import display, Javascript, HTML
7+
8+
def capture_responses(prev_div_id):
9+
"""
10+
Attempt to capture and display responses from a previous quiz container.
11+
"""
12+
letters = string.ascii_letters
13+
div_id = ''.join(random.choice(letters) for _ in range(12))
14+
15+
mydiv = f'<div id="{div_id}"></div>'
16+
javascript = f"""
17+
{{
18+
var prev = {prev_div_id};
19+
var container = document.getElementById("{div_id}");
20+
var responses = prev.querySelector('.JCResponses');
21+
if (responses) {{
22+
var respStr = responses.dataset.responses;
23+
container.setAttribute('data-responses', respStr);
24+
var iDiv = document.createElement('div');
25+
iDiv.id = 'responses' + '{div_id}';
26+
iDiv.innerText = respStr;
27+
container.appendChild(iDiv);
28+
}} else {{
29+
container.innerText = 'No Responses Found';
30+
}}
31+
}}
32+
"""
33+
display(HTML(mydiv))
34+
display(Javascript(javascript))

0 commit comments

Comments
 (0)