File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
openedx_tagging/core/tagging Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -593,6 +593,6 @@ def get_tag_options(self) -> Iterator[TagResult]:
593593 break
594594
595595
596- # Register the object tag classes in reverse order for how we want them considered
597- register_object_tag_class (OpenObjectTag )
596+ # We'd rather match closed taxonomies than open ones when casting ObjectTags, so we register ClosedObjectTag first.
598597register_object_tag_class (ClosedObjectTag )
598+ register_object_tag_class (OpenObjectTag )
Original file line number Diff line number Diff line change 1010_OBJECT_TAG_CLASS_REGISTRY = []
1111
1212
13- def register_object_tag_class (cls ):
13+ def register_object_tag_class (cls , index = 0 ):
1414 """
1515 Register a given class as a candidate object tag class.
1616
17+ By default, inserts the given class at the beginning of the list, so that it will be considered before all
18+ previously-registered classes. Adjust ``index`` to change where the class will be considered.
19+
1720 The class must have a `valid_for` class method.
1821 """
1922 assert hasattr (cls , "valid_for" )
20- _OBJECT_TAG_CLASS_REGISTRY .append ( cls )
23+ _OBJECT_TAG_CLASS_REGISTRY .insert ( index , cls )
2124
2225
2326def get_object_tag_class (
@@ -44,8 +47,8 @@ def get_object_tag_class(
4447 # Log error and continue
4548 log .exception (f"Unable to import custom object_tag_class for { taxonomy } " )
4649
47- # Return the most recently-registered, appropriate object tag class
48- for ObjectTagClass in reversed ( _OBJECT_TAG_CLASS_REGISTRY ) :
50+ # Return the first appropriate object tag class
51+ for ObjectTagClass in _OBJECT_TAG_CLASS_REGISTRY :
4952 if ObjectTagClass .valid_for (
5053 taxonomy = taxonomy ,
5154 object_type = object_type ,
You can’t perform that action at this time.
0 commit comments