fix: Restructuring to send course_id and score to edx submission fix: Refactoring of sending information to sent_to_submission fix: Elimination of unnecessary functions fix: Added usage comment to ProblemBlock in XqueueInterface constructor fix: update doc ADR fix: setting for Quality Others test (ubuntu-24.04, 3.11, 20) fix: Deprecation for django-trans-escape-filter-parse-error test: Add @pytest.mark.django_db decorator to test functions test: Fix for pylint being disabled fix: updated changes for pylint disable fix: update error from docs ADR-0005 update: xmodule/docs/decisions/0005-send-data-to-edx-submission.rst Co-authored-by: Sarina Canelake <sarina@axim.org> update: xmodule/docs/decisions/0005-send-data-to-edx-submission.rst Co-authored-by: Sarina Canelake <sarina@axim.org> fix: Adjusted correction fix: update date for docs ADR Revert "fix: update date for docs ADR" This reverts commit 0b4229c51c4937f95cb407872645dd448df45418. fix: replace call created_submission to create_external_grader_detail fix: update test xqueue_submission fix: add docstring in test_xqueue_submission fix: update date doc ADR fix: update version edx-submission 3.8.6 fix: add @pytest.mark.xfail fix: add 20 chances in test_capa_block: fix: increase retry attempts for seed generation in ProblemBlockTest fix: change version to edx-submission lib fix: new version edx-submission in testings fix: replace parameter file to files fix: update variable grader_file_name and points_possible fix: Adjustment in the is_flag_active function to always take the last record edited in the waffle fix: wrap large line of code fix: update function is_flag_active fix: code style adjustment fix: changes for 60 retry feat: use CourseWaffleFlag to determine xqueue callback path fix: Code style adjustment fix: remove deprecated xqueue callback route and simplify callback type logic fix: Deleting a comment in the ADR document fix: add log in self.block is None fix: Code style adjustment in log
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""A registry for finding classes based on tags in the class."""
|
|
|
|
|
|
class TagRegistry(object):
|
|
"""
|
|
A registry mapping tags to handlers.
|
|
|
|
(A dictionary with some extra error checking.)
|
|
"""
|
|
|
|
def __init__(self):
|
|
self._mapping = {}
|
|
|
|
def register(self, cls):
|
|
"""
|
|
Register cls as a supported tag type. It is expected to define cls.tags as a list of tags
|
|
that it implements.
|
|
|
|
If an already-registered type has registered one of those tags, will raise ValueError.
|
|
|
|
If there are no tags in cls.tags, will also raise ValueError.
|
|
"""
|
|
|
|
# Do all checks and complain before changing any state.
|
|
if len(cls.tags) == 0:
|
|
raise ValueError("No tags specified for class {0}".format(cls.__name__))
|
|
|
|
for tag in cls.tags:
|
|
if tag in self._mapping:
|
|
other_cls = self._mapping[tag]
|
|
if cls == other_cls:
|
|
# registering the same class multiple times seems silly, but ok
|
|
continue
|
|
raise ValueError(
|
|
"Tag {0} already registered by class {1}."
|
|
" Can't register for class {2}".format(
|
|
tag,
|
|
other_cls.__name__,
|
|
cls.__name__,
|
|
)
|
|
)
|
|
|
|
# Ok, should be good to change state now.
|
|
for t in cls.tags:
|
|
self._mapping[t] = cls
|
|
|
|
# Returning the cls means we can use this as a decorator.
|
|
return cls
|
|
|
|
def registered_tags(self):
|
|
"""
|
|
Get a list of all the tags that have been registered.
|
|
"""
|
|
return list(self._mapping.keys())
|
|
|
|
def get_class_for_tag(self, tag):
|
|
"""
|
|
For any tag in registered_tags(), returns the corresponding class. Otherwise, will raise
|
|
KeyError.
|
|
"""
|
|
return self._mapping[tag]
|