diff --git a/apps/common/management/commands/load_dummy_data.py b/apps/common/management/commands/load_dummy_data.py index 1ebac0e..158d330 100644 --- a/apps/common/management/commands/load_dummy_data.py +++ b/apps/common/management/commands/load_dummy_data.py @@ -73,6 +73,10 @@ def process_qbank(self, qbank: QuestionBank): category_3=categories[2], category_4=categories[3], order=group_order_by_type[_type], + hide_in_framework=QBLeafGroup.check_if_hidden_in_framework( + _type, + *categories, + ), ) group_order_by_type[_type] += 1 # Questions diff --git a/apps/qbank/admin.py b/apps/qbank/admin.py index 802017b..c365fd0 100644 --- a/apps/qbank/admin.py +++ b/apps/qbank/admin.py @@ -97,6 +97,7 @@ class QBLeafGroupAdmin(ReadOnlyMixin, admin.ModelAdmin): list_filter = ( AutocompleteFilterFactory('QuestionBank', 'qbank'), 'type', + 'hide_in_framework', 'category_1', 'category_2', 'category_3', diff --git a/apps/qbank/importer/xlsxform.py b/apps/qbank/importer/xlsxform.py index 8132c63..72ece38 100644 --- a/apps/qbank/importer/xlsxform.py +++ b/apps/qbank/importer/xlsxform.py @@ -207,8 +207,9 @@ def create_leaf_groups(self): type=QBLeafGroup.Type.MATRIX_1D, category_1=c1, category_2=c2, - hide_in_framework=( - c2 in QBLeafGroup.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP[QBLeafGroup.Type.MATRIX_1D].get(c1, {}) + hide_in_framework=QBLeafGroup.check_if_hidden_in_framework( + QBLeafGroup.Type.MATRIX_1D, + c1, c2, None, None ) ) for c1, c2_list in QBLeafGroup.TYPE_CATEGORY_MAP[QBLeafGroup.Type.MATRIX_1D].items() @@ -224,9 +225,9 @@ def create_leaf_groups(self): category_2=c2, category_3=c3, category_4=c4, - hide_in_framework=( - c2 in QBLeafGroup.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP[QBLeafGroup.Type.MATRIX_2D]['rows'].get(c1, {}) or - c4 in QBLeafGroup.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP[QBLeafGroup.Type.MATRIX_2D]['columns'].get(c3, {}) + hide_in_framework=QBLeafGroup.check_if_hidden_in_framework( + QBLeafGroup.Type.MATRIX_2D, + c1, c2, c3, c4 ) ) for c1, c2_list in QBLeafGroup.TYPE_CATEGORY_MAP[QBLeafGroup.Type.MATRIX_2D]['rows'].items() diff --git a/apps/qbank/models.py b/apps/qbank/models.py index 270fd4e..d13f400 100644 --- a/apps/qbank/models.py +++ b/apps/qbank/models.py @@ -82,6 +82,29 @@ def existing_leaf_groups_qs(self) -> models.QuerySet[typing.Self]: qbank=self.qbank, ) + @classmethod + def check_if_hidden_in_framework(cls, _type, c1, c2, c3, c4) -> bool: + if _type == cls.Type.MATRIX_1D: + return c2 in ( + cls.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP[_type].get(c1, {}) + ) + elif _type == cls.Type.MATRIX_2D: + return ( + c2 in ( + cls.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP + [cls.Type.MATRIX_2D] + ['rows'] + .get(c1, {}) + ) or + c4 in ( + cls.CATEGORIES_HIDDEN_IN_FRAMEWORK_MAP + [cls.Type.MATRIX_2D] + ['columns'] + .get(c3, {}) + ) + ) + return False + class QBQuestion(BaseQuestion): qbank = models.ForeignKey(QuestionBank, on_delete=models.CASCADE)