Skip to content

Commit

Permalink
fix: implement ItemBankBlock validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Oct 18, 2024
1 parent 546fb28 commit 816a450
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions xmodule/item_bank_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,6 @@ def get_user_id(self):
user_id = None
return user_id

def _set_validation_error_if_empty(self, validation, summary):
""" Helper method to only set validation summary if it's empty """
if validation.empty:
validation.set_summary(summary)

def has_dynamic_children(self):
"""
Inform the runtime that our children vary per-user.
Expand All @@ -390,7 +385,7 @@ def get_content_titles(self):
@classmethod
def definition_from_xml(cls, xml_object, system):
"""
@@TODO
@@TODO docstring
"""
children = []

Expand Down Expand Up @@ -444,8 +439,31 @@ def validate(self):
@@TODO implement
"""
validation = super().validate()
_ = StudioValidation
__ = StudioValidationMessage
if not isinstance(validation, StudioValidation):
validation = StudioValidation.copy(validation)
if not validation.empty:
pass # If there's already a validation error, leave it there.
elif not self.children:
validation.set_summary(
StudioValidationMessage(
StudioValidationMessage.WARNING,
(_('No problems have been selected.')),
action_class='edit-button',
action_label=_("Select problems to randomize.")
)
)
elif len(self.children) < self.max_count:
validation.set_summary(
StudioValidationMessage(
StudioValidationMessage.WARNING,
_(
"The problem bank has been configured to show {count} problems, "
"but only {actual} have been selected."
).format(count=self.max_count, actual=len(self.children)),
action_class='edit-button',
action_label=_("Edit the problem bank configuration.")
)
)
return validation

def author_view(self, context):
Expand Down

0 comments on commit 816a450

Please sign in to comment.