-
Notifications
You must be signed in to change notification settings - Fork 4
feat: migrate xblock-free-text-response to xblocks-extra #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| Free Text Response XBlock | ||
| ================================ | ||
|
|
||
| XBlock to capture a free-text response. | ||
|
|
||
| |badge-ci| | ||
| |badge-coveralls| | ||
|
|
||
| This package provides an XBlock for use with the EdX Platform and makes | ||
| it possible for instructors to create questions that expect a | ||
| free-text response. | ||
|
|
||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
|
|
||
| System Administrator | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To install the XBlock on your platform, | ||
| add the following to your `requirements.txt` file: | ||
|
|
||
| xblock-free-text-response | ||
|
|
||
| You'll also need to add this to your `INSTALLED_APPS`: | ||
|
|
||
| freetextresponse | ||
|
|
||
|
|
||
| Course Staff | ||
| ~~~~~~~~~~~~ | ||
|
|
||
| To install the XBlock in your course, | ||
| access your `Advanced Module List`: | ||
|
|
||
| Settings -> Advanced Settings -> Advanced Module List | ||
|
|
||
| and add the following: | ||
|
|
||
| freetextresponse | ||
|
|
||
|
|
||
|
|
||
| .. |badge-coveralls| image:: https://coveralls.io/repos/github/Stanford-Online/xblock-free-text-response/badge.svg?branch=master | ||
| :target: https://coveralls.io/github/Stanford-Online/xblock-free-text-response?branch=master | ||
| .. |badge-ci| image:: https://github.com/openedx/xblock-free-text-response/workflows/Python%20CI/badge.svg?branch=master | ||
| :target: https://github.com/openedx/xblock-free-text-response/actions?query=workflow%3A%22Python+CI%22 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """ | ||
| This is an XBlock that accepts a free-text response from students. | ||
| Instructors can specify a list of phrases, of which one must be | ||
| present in order for the student to receive credit. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Configuration for i18n workflow. | ||
|
|
||
| locales: | ||
| - en # English - Source Language | ||
|
|
||
| # The locales used for fake-accented English, for testing. | ||
| dummy_locales: | ||
| - eo # Esperanto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """ | ||
| Mixin behavior to XBlocks | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| """ | ||
| Extend XBlocks with datetime helpers | ||
| """ | ||
|
|
||
| import datetime | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class EnforceDueDates: | ||
| """ | ||
| xBlock Mixin to allow xblocks to check the due date | ||
| (taking the graceperiod into account) of the | ||
| subsection in which they are placed | ||
| """ | ||
|
|
||
| def is_past_due(self): | ||
| """ | ||
| Determine if component is past-due | ||
| """ | ||
| # These values are pulled from platform. | ||
| # They are defaulted to None for tests. | ||
| due = getattr(self, "due", None) | ||
| graceperiod = getattr(self, "graceperiod", None) | ||
| # Calculate the current UTC datetime as a timezone-naive object for comparison. | ||
| now = datetime.datetime.now(datetime.UTC).replace(tzinfo=None) | ||
| if due is not None: | ||
| # Remove timezone information from platform provided due date. | ||
| # Dates are stored as UTC timezone aware objects on platform. | ||
| due = due.replace(tzinfo=None) | ||
| if graceperiod is not None: | ||
| # Compare the datetime objects (both have to be timezone naive) | ||
| due = due + graceperiod | ||
| return now > due | ||
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """ | ||
| Mixin fragment/html behavior into XBlocks | ||
|
|
||
| Note: We should resume test coverage for all lines in this file once | ||
| split into its own library. | ||
| """ | ||
|
|
||
| from web_fragments.fragment import Fragment | ||
| from xblock.core import XBlock | ||
|
|
||
| try: | ||
| from xblock.utils.resources import ResourceLoader | ||
| except ModuleNotFoundError: # pragma: no cover | ||
| from xblockutils.resources import ResourceLoader | ||
|
|
||
| loader = ResourceLoader(__name__) | ||
|
irfanuddinahmad marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class XBlockFragmentBuilderMixin: | ||
| """ | ||
| Create a default XBlock fragment builder | ||
| """ | ||
|
|
||
| static_css = [ | ||
| "view.css", | ||
| ] | ||
| static_js = [ | ||
| "view.js", | ||
| ] | ||
| static_js_init = None | ||
| template = "view.html" | ||
|
|
||
| def provide_context(self, context): # pragma: no cover | ||
| """ | ||
| Build a context dictionary to render the student view | ||
|
|
||
| This should generally be overridden by child classes. | ||
| """ | ||
| context = context or {} | ||
| context = dict(context) | ||
| return context | ||
|
|
||
| @XBlock.supports("multi_device") | ||
| def student_view(self, context=None): | ||
| """ | ||
| Build the fragment for the default student view | ||
| """ | ||
| template = self.template | ||
| context = self.provide_context(context) | ||
| static_css = self.static_css or [] | ||
| static_js = self.static_js or [] | ||
| js_init = self.static_js_init | ||
| fragment = self.build_fragment( | ||
| template=template, | ||
| context=context, | ||
| css=static_css, | ||
| js=static_js, | ||
| js_init=js_init, | ||
| ) | ||
| return fragment | ||
|
|
||
| # pylint: disable=too-many-positional-arguments | ||
| def build_fragment( | ||
| self, | ||
| template="", | ||
| context=None, | ||
| css=None, | ||
| js=None, | ||
| js_init=None, | ||
| ): | ||
| """ | ||
| Creates a fragment for display. | ||
| """ | ||
| context = context or {} | ||
| css = css or [] | ||
| js = js or [] | ||
| rendered_template = "" | ||
| if template: # pragma: no cover | ||
| template = "templates/" + template | ||
| rendered_template = self.loader.render_django_template( | ||
|
irfanuddinahmad marked this conversation as resolved.
|
||
| template, | ||
| context=context, | ||
| i18n_service=self._i18n_service(), | ||
| ) | ||
| fragment = Fragment(rendered_template) | ||
| for item in css: | ||
| if item.startswith("/"): | ||
| url = item | ||
| else: | ||
| url = self.runtime.local_resource_url(self, "public/" + item) | ||
| fragment.add_css_url(url) | ||
| for item in js: | ||
| item = "public/" + item | ||
| url = self.runtime.local_resource_url(self, item) | ||
| fragment.add_javascript_url(url) | ||
|
irfanuddinahmad marked this conversation as resolved.
|
||
| if js_init: # pragma: no cover | ||
| fragment.initialize_js(js_init) | ||
| return fragment | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """ | ||
| Mixin i18n logic | ||
| """ | ||
|
|
||
|
|
||
| class I18nXBlockMixin: | ||
| """ | ||
| Make an XBlock translation-aware | ||
| """ | ||
|
|
||
| def _i18n_service(self): | ||
| """ | ||
| Provide the XBlock runtime's i18n service | ||
| """ | ||
| service = self.runtime.service(self, "i18n") | ||
| return service | ||
|
|
||
| def gettext(self, text): | ||
| """ | ||
| Call gettext from the XBlock i18n service | ||
| """ | ||
| text = self._i18n_service().gettext(text) | ||
| return text | ||
|
|
||
| def ngettext(self, *args, **kwargs): | ||
| """ | ||
| Call ngettext from the XBlock i18n service | ||
| """ | ||
| text = self._i18n_service().ngettext(*args, **kwargs) | ||
| return text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
| Mixin workbench behavior into XBlocks | ||
| """ | ||
|
|
||
| try: | ||
| from xblock.utils.resources import ResourceLoader | ||
| except ModuleNotFoundError: | ||
| from xblockutils.resources import ResourceLoader | ||
|
|
||
|
|
||
| loader = ResourceLoader(__name__) | ||
|
|
||
|
|
||
| def _parse_title(title): | ||
| """ | ||
| Parse the title of the scenario | ||
| """ | ||
| title = title.split("-") | ||
| title = " ".join(title) | ||
|
irfanuddinahmad marked this conversation as resolved.
|
||
| return title.title() | ||
|
|
||
|
|
||
| def _parse_scenarios(scenarios): | ||
| """ | ||
| Parse the content of the scenario files | ||
| """ | ||
| parsed_scenarios = [] | ||
| for scenario in scenarios: | ||
| title = _parse_title(scenario[0]) | ||
| parsed_scenarios.append((title, scenario[1])) | ||
| return parsed_scenarios | ||
|
|
||
|
|
||
| class XBlockWorkbenchMixin: | ||
| """ | ||
| Provide a default test workbench for the XBlock | ||
| """ | ||
|
|
||
| @classmethod | ||
| def workbench_scenarios(cls): | ||
| """ | ||
| Gather scenarios to be displayed in the workbench | ||
| """ | ||
| scenarios = loader.load_scenarios_from_path("../scenarios") | ||
| return _parse_scenarios(scenarios) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """ | ||
| Extend XBlock with additional user functionality | ||
| """ | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class MissingDataFetcherMixin: | ||
| """ | ||
| The mixin used for getting the student_id of the current user. | ||
| """ | ||
|
|
||
| def get_student_id(self): | ||
| """ | ||
| Get the student id. | ||
| """ | ||
| if hasattr(self, "xmodule_runtime"): | ||
| student_id = self.xmodule_runtime.anonymous_student_id | ||
| # pylint:disable=E1101 | ||
| else: | ||
| student_id = str(self.scope_ids.user_id or "") | ||
| return student_id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.