FlashcardsXBlock 1.0.0rc1__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.
@@ -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,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ FlashcardsXBlock.egg-info/PKG-INFO
5
+ FlashcardsXBlock.egg-info/SOURCES.txt
6
+ FlashcardsXBlock.egg-info/dependency_links.txt
7
+ FlashcardsXBlock.egg-info/entry_points.txt
8
+ FlashcardsXBlock.egg-info/requires.txt
9
+ FlashcardsXBlock.egg-info/top_level.txt
10
+ flashcards/__init__.py
11
+ flashcards/flashcards.py
12
+ flashcards/static/html/studio.html
13
+ flashcards/static/js/student.js
14
+ flashcards/static/js/studio.js
@@ -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,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,23 @@
1
+ # FlashcardsXBlock
2
+ An Open edX platform XBlock to create and display flashcards.
3
+
4
+ The flashcards are added like this:
5
+
6
+ ```html
7
+ <flashcards title="Capital cities">
8
+ <flashcard front="Croatia" back="Zagreb" />
9
+ <flashcard front="France" back="Paris" />
10
+ </flashcards>
11
+ ```
12
+
13
+ The XBlock in Studio looks like this:
14
+ ![Flashcard_edit](flashcardsxblock_edit.png)
15
+
16
+ Output looks like this:
17
+
18
+ ![Flashcard](flashcardsxblock.png)
19
+
20
+ ## Want to contribute?
21
+ If you have a suggestion, question or found a bug, please [open an issue](https://github.com/vkaracic/FlashcardsXBlock/issues/new) for it.
22
+
23
+ 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,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,170 @@
1
+ [project]
2
+ name = "FlashcardsXBlock"
3
+ version = "1.0.0-rc1"
4
+ description = "A Flashcards XBlock for Open edX."
5
+ readme = {file = "README.md", content-type = "text/markdown"}
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ classifiers = [
10
+ "Development Status :: 5 - Production/Stable",
11
+ "Framework :: Django",
12
+ "Framework :: Django :: 4.2",
13
+ "Intended Audience :: Developers",
14
+ "Natural Language :: English",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.11",
17
+ ]
18
+ keywords = ["Python", "edx"]
19
+ dependencies = [
20
+ "XBlock", # XBlock framework
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/open-craft/FlashcardsXBlock"
25
+
26
+ [project.entry-points."xblock.v1"]
27
+ flashcards = "flashcards:FlashcardsXBlock"
28
+
29
+ [tool.setuptools.packages.find]
30
+ include = ["flashcards", "flashcards.*"]
31
+ exclude = ["*tests"]
32
+
33
+ [tool.setuptools.package-data]
34
+ flashcards = ["*.css", "*.js", "*.html", "static/**/*", "templates/**/*"]
35
+
36
+ [dependency-groups]
37
+ test = [
38
+ "pytest-cov", # pytest extension for code coverage statistics
39
+ "code-annotations", # provides commands used by the pii_check make target
40
+ "xblock-sdk", # provides workbench settings for testing
41
+ ]
42
+ ci = [
43
+ "tox", # Virtualenv management for tests
44
+ "tox-uv", # Replace pip with uv in tox
45
+ ]
46
+ quality = [
47
+ "ruff", # Linter and formatter
48
+ ]
49
+ dev = [
50
+ {include-group = "test"},
51
+ {include-group = "ci"},
52
+ {include-group = "quality"},
53
+ "diff-cover", # Changeset diff test coverage
54
+ "edx-i18n-tools", # For i18n_tool dummy
55
+ ]
56
+
57
+ [tool.uv]
58
+ constraint-dependencies = [
59
+ # External constraints (DO NOT REMOVE THIS LINE)
60
+ "Django<5.0",
61
+ "elasticsearch<7.14.0",
62
+ "django-simple-history==3.0.0",
63
+ "pip<24.3",
64
+ "urllib3<2.3.0"
65
+ ]
66
+
67
+ [tool.coverage.run]
68
+ include = ['flashcards/**']
69
+ omit = ['tests/*']
70
+
71
+ [tool.ruff]
72
+ line-length = 120
73
+ exclude = ['migrations', 'docs', 'manage.py']
74
+ target-version = 'py311'
75
+
76
+ [tool.ruff.lint]
77
+ select = [
78
+ 'F', # Pyflakes
79
+ 'E', # Pycodestyle (errors)
80
+ 'W', # Pycodestyle (warnings)
81
+ 'C90', # mccabe
82
+ 'I', # isort
83
+ 'N', # pep8-naming
84
+ 'D', # pydocstyle
85
+ 'UP', # pyupgrade
86
+ 'YTT', # flake8-2020
87
+ 'ANN', # flake8-annotations
88
+ 'ASYNC',# flake8-async
89
+ 'S', # flake8-bandit
90
+ 'BLE', # flake8-blind-except
91
+ 'FBT', # flake8-boolean-trap
92
+ 'B', # flake8-bugbear
93
+ 'A', # flake8-builtins
94
+ 'COM', # flake8-commas
95
+ 'C4', # flake8-comprehensions
96
+ 'DTZ', # flake8-datetimez
97
+ 'T10', # flake8-debugger
98
+ 'DJ', # flake8-django
99
+ 'EM', # flake8-errmsg
100
+ 'EXE', # flake8-executable
101
+ 'FA', # flake8-future-annotations
102
+ 'ISC', # flake8-implicit-str-concat
103
+ 'ICN', # flake8-import-conventions
104
+ 'LOG', # flake8-logging
105
+ 'G', # flake8-logging-format
106
+ 'INP', # flake8-no-pep420
107
+ 'PIE', # flake8-pie
108
+ 'T20', # flake8-print
109
+ 'PYI', # flake8-pyi
110
+ 'PT', # flake8-pytest-style
111
+ 'Q', # flake8-quotes
112
+ 'RSE', # flake8-raise
113
+ 'RET', # flake8-return
114
+ 'SLF', # flake8-self
115
+ 'SLOT', # flake8-slots
116
+ 'SIM', # flake8-simplify
117
+ 'TID', # flake8-tidy-imports
118
+ 'TC', # flake8-type-checking
119
+ 'INT', # flake8-gettext
120
+ 'ARG', # flake8-unused-arguments
121
+ 'PTH', # flake8-use-pathlib
122
+ 'TD', # flake8-todos
123
+ 'ERA', # eradicate
124
+ 'PD', # pandas-vet
125
+ 'PGH', # pygrep-hooks
126
+ 'PL', # Pylint
127
+ 'TRY', # tryceratops
128
+ 'FLY', # flynt
129
+ 'NPY', # NumPy-specific rules
130
+ 'AIR', # Airflow
131
+ 'PERF', # Perflint
132
+ 'FURB', # refurb
133
+ # TODO: Enable preview.
134
+ # 'DOC', # pydoclint
135
+ 'RUF', # Ruff-specific rules
136
+ ]
137
+ ignore = [
138
+ 'ANN002', # missing-type-args
139
+ 'ANN003', # missing-type-kwargs
140
+ 'ANN204', # missing-return-type-special-method
141
+ 'D203', # one-blank-line-before-class
142
+ 'D212', # multi-line-summary-first-line (incompatible with D213)
143
+ 'Q000', # bad-quotes-inline-string
144
+ 'TD002', # missing-t\odo-author
145
+ 'TD003', # missing-t\odo-link
146
+ 'TRY003', # raise-vanilla-args
147
+ ]
148
+
149
+ [tool.ruff.lint.per-file-ignores]
150
+ 'tests/*' = [
151
+ 'S101', # assert
152
+ 'INP001', # implicit-namespace-package
153
+ 'SLF001', # private-member-access
154
+ 'RUF018', # assignment-in-assert
155
+ ]
156
+
157
+ [tool.ruff.lint.flake8-annotations]
158
+ suppress-none-returning = true
159
+
160
+ [tool.ruff.lint.pydocstyle]
161
+ convention = "google"
162
+
163
+ [tool.ruff.lint.pylint]
164
+ allow-magic-value-types = ['int', 'str']
165
+
166
+
167
+ [tool.pytest.ini_options]
168
+ DJANGO_SETTINGS_MODULE = "workbench.settings"
169
+ addopts = "--cov flashcards --cov tests --cov-report term-missing --cov-report xml"
170
+ norecursedirs = ".* docs requirements site-packages"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+