Skip to content

Commit

Permalink
Add hide_in_framework logic in load_dummy_data
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Sep 28, 2023
1 parent bcb8910 commit 59794d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions apps/common/management/commands/load_dummy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apps/qbank/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class QBLeafGroupAdmin(ReadOnlyMixin, admin.ModelAdmin):
list_filter = (
AutocompleteFilterFactory('QuestionBank', 'qbank'),
'type',
'hide_in_framework',
'category_1',
'category_2',
'category_3',
Expand Down
11 changes: 6 additions & 5 deletions apps/qbank/importer/xlsxform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions apps/qbank/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59794d8

Please sign in to comment.