FlashcardsXBlock 1.0.0rc1__py3-none-any.whl

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.
flashcards/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """The FlashcardsXBlock package."""
2
+
3
+ from .flashcards import FlashcardsXBlock
4
+
5
+ __all__ = ["FlashcardsXBlock"]
@@ -0,0 +1,121 @@
1
+ """
2
+ An XBlock for displaying flashcards.
3
+
4
+ Flashcards XBlock allows the editor to add a list of questions and
5
+ answers (separated by a semicolon) which are then displayed as flashcards.
6
+ """
7
+
8
+ from web_fragments.fragment import Fragment
9
+ from xblock.core import XBlock
10
+ from xblock.fields import List, Scope, String
11
+ from xblock.utils.resources import ResourceLoader
12
+
13
+
14
+ class FlashcardsXBlock(XBlock):
15
+ """
16
+ The FlashcardsXBlock class.
17
+
18
+ The content (the values between the <flashcards> tags) is saved as a
19
+ list of flashcard objects and passed as an array to the HTML template.
20
+ """
21
+
22
+ loader = ResourceLoader(__name__)
23
+ display_name = String(
24
+ display_name="Display Name",
25
+ default="Flashcards", # type: ignore[assignment]
26
+ scope=Scope.settings,
27
+ help="The title of the XBlock. It is displayed to the learners.",
28
+ )
29
+
30
+ content = List(default=[], scope=Scope.settings, help="List of items") # type: ignore[assignment]
31
+
32
+ def student_view(self, context: dict | None = None) -> Fragment:
33
+ """Create fragment and send the appropriate context."""
34
+ styling = {
35
+ "fontSize": "16px",
36
+ "backgroundColor": "#f8f9fa",
37
+ "textColor": "#212529",
38
+ "borderColor": "#dee2e6",
39
+ }
40
+
41
+ context = {
42
+ "title": self.display_name,
43
+ "flashcards": self.content,
44
+ "styling": styling,
45
+ "url": self.runtime.local_resource_url(self, "public/student-ui.js"),
46
+ }
47
+
48
+ frag = Fragment()
49
+ frag.add_javascript(self.loader.load_unicode("static/js/student.js"))
50
+ frag.add_css_url(self.runtime.local_resource_url(self, "public/student-ui.css"))
51
+ frag.initialize_js("FlashcardsBlock", context)
52
+ return frag
53
+
54
+ @classmethod
55
+ def parse_xml(cls, node, runtime, keys, id_generator) -> XBlock: # noqa: ANN001, ARG003
56
+ """
57
+ Parse the XML for an HTML block.
58
+
59
+ The entire subtree under `node` is re-serialized, and set as the
60
+ content of the XBlock.
61
+
62
+ The content between the <flashcards> blocks is being transformed
63
+ into a list of flashcard objects, and as such saved into the content class variable
64
+ (which is accessible with self.content)
65
+ """
66
+ block = runtime.construct_xblock_from_class(cls, keys)
67
+ flashcards = []
68
+
69
+ flashcards = [
70
+ {"front": element.attrib["front"], "back": element.attrib["back"]}
71
+ for element in node.iter("flashcard")
72
+ ]
73
+
74
+ block.content = flashcards
75
+ block.title = node.attrib["title"]
76
+ return block
77
+
78
+ @staticmethod
79
+ def workbench_scenarios() -> list[tuple[str, str]]:
80
+ """A canned scenario for display in the workbench."""
81
+ return [
82
+ (
83
+ "FlashcardsXBlock",
84
+ """<vertical_demo>
85
+ <flashcards title="Capital cities">
86
+ <flashcard front="Croatia" back="Zagreb" />
87
+ <flashcard front="France" back="Paris" />
88
+ </flashcards>
89
+ </vertical_demo>
90
+ """,
91
+ ),
92
+ ]
93
+
94
+ def studio_view(self, context: dict) -> Fragment:
95
+ """Create a fragment used to display the edit view in the Studio."""
96
+ styling = {
97
+ "fontSize": "16px",
98
+ "backgroundColor": "#f8f9fa",
99
+ "textColor": "#212529",
100
+ "borderColor": "#dee2e6",
101
+ }
102
+
103
+ context = {
104
+ "title": self.display_name,
105
+ "flashcards": self.content,
106
+ "styling": styling,
107
+ "url": self.runtime.local_resource_url(self, "public/studio-ui.js"),
108
+ }
109
+
110
+ frag = Fragment(self.loader.render_django_template("static/html/studio.html", context=context))
111
+ frag.add_javascript(self.loader.load_unicode("static/js/studio.js"))
112
+ frag.add_css_url(self.runtime.local_resource_url(self, "public/studio-ui.css"))
113
+ frag.initialize_js("FlashcardsEditor", context)
114
+ return frag
115
+
116
+ @XBlock.json_handler
117
+ def studio_submit(self, data: dict, suffix: str = "") -> dict[str, str]: # noqa: ARG002
118
+ """Called when submitting the form in Studio."""
119
+ self.display_name = data.get("title")
120
+ self.content = data.get("flashcards")
121
+ return {"result": "success"}
@@ -0,0 +1 @@
1
+ <div class="flashcards_studio" id="flashcards-studio-ui"></div>
@@ -0,0 +1,6 @@
1
+ function FlashcardsBlock(runtime, element, data) {
2
+ (async () => {
3
+ const {renderBlock} = await import(data.url);
4
+ renderBlock(element, data);
5
+ })();
6
+ }
@@ -0,0 +1,6 @@
1
+ function FlashcardsEditor(runtime, element, data) {
2
+ (async () => {
3
+ const {renderEditor} = await import(data.url);
4
+ renderEditor(runtime, element[0], data);
5
+ })();
6
+ }
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: FlashcardsXBlock
3
+ Version: 1.0.0rc1
4
+ Summary: A Flashcards XBlock for Open edX.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/open-craft/FlashcardsXBlock
7
+ Keywords: Python,edx
8
+ Classifier: Development Status :: 5 - Production/Stable
9
+ Classifier: Framework :: Django
10
+ Classifier: Framework :: Django :: 4.2
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: XBlock
19
+ Dynamic: license-file
20
+
21
+ # FlashcardsXBlock
22
+ An Open edX platform XBlock to create and display flashcards.
23
+
24
+ The flashcards are added like this:
25
+
26
+ ```html
27
+ <flashcards title="Capital cities">
28
+ <flashcard front="Croatia" back="Zagreb" />
29
+ <flashcard front="France" back="Paris" />
30
+ </flashcards>
31
+ ```
32
+
33
+ The XBlock in Studio looks like this:
34
+ ![Flashcard_edit](flashcardsxblock_edit.png)
35
+
36
+ Output looks like this:
37
+
38
+ ![Flashcard](flashcardsxblock.png)
39
+
40
+ ## Want to contribute?
41
+ If you have a suggestion, question or found a bug, please [open an issue](https://github.com/vkaracic/FlashcardsXBlock/issues/new) for it.
42
+
43
+ If you want to contribute code then you're awesome, and please open a pull request with details about the changes that you propose.
@@ -0,0 +1,11 @@
1
+ flashcards/__init__.py,sha256=dg51VfSGQZbgK6pDLCpa-9maZHMxzFOBGv8y9jBYXC0,110
2
+ flashcards/flashcards.py,sha256=PcKoLBys_JeOiA0GBgtb0V9Fr0eRuGgaAc55M--3R5E,4284
3
+ flashcards/static/html/studio.html,sha256=PMRqbAdU3YyMrN5VYTXEjinBHde8ejV0Y3qazlGBGDU,64
4
+ flashcards/static/js/student.js,sha256=Bq_EgK7telZUqnBrC2KVQ_CSmw0ETbSBvAmMX-hCxr0,160
5
+ flashcards/static/js/studio.js,sha256=Kls8y1EJ5niZr7iAwjoxqfi1FmWyEwTE4KrpT8F6NeE,175
6
+ flashcardsxblock-1.0.0rc1.dist-info/licenses/LICENSE,sha256=myvkJeoIF-3SOyL2XBnn3EBoQGc75jOnEapU6qC7Aa0,1073
7
+ flashcardsxblock-1.0.0rc1.dist-info/METADATA,sha256=UACMDEhq_XITkS9Dqz7DLaaogt7O0rdawXXNV3chXFQ,1370
8
+ flashcardsxblock-1.0.0rc1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ flashcardsxblock-1.0.0rc1.dist-info/entry_points.txt,sha256=adWsUbz4i8AJTwoqq_EULWSQT6YfukJZb2olFa6-6Js,53
10
+ flashcardsxblock-1.0.0rc1.dist-info/top_level.txt,sha256=1j-1IPsI5ozT1YqHDZuMFzGsndw-dB2oh7tzi5YGOS0,11
11
+ flashcardsxblock-1.0.0rc1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [xblock.v1]
2
+ flashcards = flashcards:FlashcardsXBlock
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Vedran Karačić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ flashcards