forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: [AXIMST-490] display render errors #2506
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2149,11 +2149,51 @@ def get_validation_messages(xblock): | |||||||||||||||||||||||||||||||||||||||
xblock: The xblock object to validate. | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||
tuple: | ||||||||||||||||||||||||||||||||||||||||
- validation_errors (list): A list of validation error messages. | ||||||||||||||||||||||||||||||||||||||||
- has_validation_error (bool): True if there are validation errors, False otherwise. | ||||||||||||||||||||||||||||||||||||||||
list: A list of validation error messages. | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
validation_json = xblock.validate().to_json() | ||||||||||||||||||||||||||||||||||||||||
validation_errors = validation_json['messages'] | ||||||||||||||||||||||||||||||||||||||||
has_validation_error = bool(validation_errors) | ||||||||||||||||||||||||||||||||||||||||
return validation_errors, has_validation_error | ||||||||||||||||||||||||||||||||||||||||
return validation_json['messages'] | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def get_render_error(request, xblock): | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
Checks if there are any rendering errors for a given block and return these. | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Args: | ||||||||||||||||||||||||||||||||||||||||
request: WSGI request object | ||||||||||||||||||||||||||||||||||||||||
xblock: The xblock object to rendering. | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||
str: Error message which happened while rendering of xblock. | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
from cms.djangoapps.contentstore.views.preview import _load_preview_block | ||||||||||||||||||||||||||||||||||||||||
from xmodule.studio_editable import has_author_view | ||||||||||||||||||||||||||||||||||||||||
from xmodule.x_module import AUTHOR_VIEW, STUDENT_VIEW | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def get_render_context(request, block): | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
Return a dict of the data needs for render of each block. | ||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
can_edit = has_studio_write_access(request.user, block.usage_key.course_key) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||
"is_unit_page": False, | ||||||||||||||||||||||||||||||||||||||||
"can_edit": can_edit, | ||||||||||||||||||||||||||||||||||||||||
"root_xblock": xblock, | ||||||||||||||||||||||||||||||||||||||||
"reorderable_items": set(), | ||||||||||||||||||||||||||||||||||||||||
"paging": None, | ||||||||||||||||||||||||||||||||||||||||
"force_render": None, | ||||||||||||||||||||||||||||||||||||||||
"item_url": "/container/{block.location}", | ||||||||||||||||||||||||||||||||||||||||
"tags_count_map": {}, | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
render_error = "" | ||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||
block = _load_preview_block(request, xblock) | ||||||||||||||||||||||||||||||||||||||||
preview_view = AUTHOR_VIEW if has_author_view(block) else STUDENT_VIEW | ||||||||||||||||||||||||||||||||||||||||
render_context = get_render_context(request, block) | ||||||||||||||||||||||||||||||||||||||||
block.render(preview_view, render_context) | ||||||||||||||||||||||||||||||||||||||||
except Exception as exc: # pylint: disable=broad-except | ||||||||||||||||||||||||||||||||||||||||
render_error = str(exc) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
return render_error | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, thanks! |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can call it
get_xblock_render_error
and the function that is inside will be calledget_xblock_render_error_context
.This will allow to put the inner function outside and clarify the idea behind these two functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we need to move out this function, it will be used only here.
Renamed