Commit f0cfc93a by muzaffaryousaf

Adding the support for '$exists' into the get_items for split mongo.

TNL-1451
parent 7aea582a
...@@ -777,6 +777,10 @@ class ModuleStoreRead(ModuleStoreAssetBase): ...@@ -777,6 +777,10 @@ class ModuleStoreRead(ModuleStoreAssetBase):
for key, criteria in qualifiers.iteritems(): for key, criteria in qualifiers.iteritems():
is_set, value = _is_set_on(key) is_set, value = _is_set_on(key)
if isinstance(criteria, dict) and '$exists' in criteria and criteria['$exists'] == is_set:
continue
if not is_set: if not is_set:
return False return False
if not self._value_matches(value, criteria): if not self._value_matches(value, criteria):
......
...@@ -90,6 +90,10 @@ class InheritanceMixin(XBlockMixin): ...@@ -90,6 +90,10 @@ class InheritanceMixin(XBlockMixin):
help="Amount of time after the due date that submissions will be accepted", help="Amount of time after the due date that submissions will be accepted",
scope=Scope.settings, scope=Scope.settings,
) )
group_access = Dict(
help=_("Enter the ids for the content groups this problem belongs to."),
scope=Scope.settings,
)
showanswer = String( showanswer = String(
display_name=_("Show Answer"), display_name=_("Show Answer"),
help=_("Specify when the Show Answer button appears for each problem. Valid values are \"always\", \"answered\", \"attempted\", \"closed\", \"finished\", \"past_due\", and \"never\"."), help=_("Specify when the Show Answer button appears for each problem. Valid values are \"always\", \"answered\", \"attempted\", \"closed\", \"finished\", \"past_due\", and \"never\"."),
......
...@@ -295,6 +295,16 @@ class SplitModuleTest(unittest.TestCase): ...@@ -295,6 +295,16 @@ class SplitModuleTest(unittest.TestCase):
"fields": { "fields": {
"display_name": "Problem 3.2" "display_name": "Problem 3.2"
}, },
},
{
"id": "problem32",
"parent": "chapter3",
"parent_type": "chapter",
"category": "problem",
"fields": {
"display_name": "Problem 3.3",
"group_access": {"3": ["33"]},
},
} }
] ]
}, },
...@@ -898,6 +908,17 @@ class SplitModuleItemTests(SplitModuleTest): ...@@ -898,6 +908,17 @@ class SplitModuleItemTests(SplitModuleTest):
self.assertFalse(modulestore()._value_matches('gotcha', {'$nin': ['a', 'bunch', 'of', 'gotcha']})) self.assertFalse(modulestore()._value_matches('gotcha', {'$nin': ['a', 'bunch', 'of', 'gotcha']}))
self.assertTrue(modulestore()._value_matches('gotcha', {'$nin': ['a', 'bunch', 'of', 'gotchas']})) self.assertTrue(modulestore()._value_matches('gotcha', {'$nin': ['a', 'bunch', 'of', 'gotchas']}))
self.assertTrue(modulestore()._block_matches({'group_access': {'1': [1]}}, {'group_access': {'$exists': True}}))
self.assertTrue(modulestore()._block_matches({'a': 1, 'b': 2}, {'group_access': {'$exists': False}}))
self.assertTrue(modulestore()._block_matches(
{'a': 1, 'group_access': {'1': [1]}},
{'a': 1, 'group_access': {'$exists': True}}))
self.assertFalse(modulestore()._block_matches(
{'a': 1, 'group_access': {'1': [1]}},
{'a': 111, 'group_access': {'$exists': True}}))
self.assertTrue(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 1, 'group_access': {'$exists': False}}))
self.assertFalse(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 9, 'group_access': {'$exists': False}}))
self.assertTrue(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 1})) self.assertTrue(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 1}))
self.assertFalse(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 2})) self.assertFalse(modulestore()._block_matches({'a': 1, 'b': 2}, {'a': 2}))
self.assertFalse(modulestore()._block_matches({'a': 1, 'b': 2}, {'c': 1})) self.assertFalse(modulestore()._block_matches({'a': 1, 'b': 2}, {'c': 1}))
...@@ -911,9 +932,9 @@ class SplitModuleItemTests(SplitModuleTest): ...@@ -911,9 +932,9 @@ class SplitModuleItemTests(SplitModuleTest):
locator = CourseLocator(org='testx', course='GreekHero', run="run", branch=BRANCH_NAME_DRAFT) locator = CourseLocator(org='testx', course='GreekHero', run="run", branch=BRANCH_NAME_DRAFT)
# get all modules # get all modules
matches = modulestore().get_items(locator) matches = modulestore().get_items(locator)
self.assertEqual(len(matches), 6) self.assertEqual(len(matches), 7)
matches = modulestore().get_items(locator) matches = modulestore().get_items(locator)
self.assertEqual(len(matches), 6) self.assertEqual(len(matches), 7)
matches = modulestore().get_items(locator, qualifiers={'category': 'chapter'}) matches = modulestore().get_items(locator, qualifiers={'category': 'chapter'})
self.assertEqual(len(matches), 3) self.assertEqual(len(matches), 3)
matches = modulestore().get_items(locator, qualifiers={'category': 'garbage'}) matches = modulestore().get_items(locator, qualifiers={'category': 'garbage'})
...@@ -924,6 +945,10 @@ class SplitModuleItemTests(SplitModuleTest): ...@@ -924,6 +945,10 @@ class SplitModuleItemTests(SplitModuleTest):
settings={'display_name': re.compile(r'Hera')}, settings={'display_name': re.compile(r'Hera')},
) )
self.assertEqual(len(matches), 2) self.assertEqual(len(matches), 2)
matches = modulestore().get_items(locator, settings={'group_access': {'$exists': True}})
self.assertEqual(len(matches), 1)
matches = modulestore().get_items(locator, settings={'group_access': {'$exists': False}})
self.assertEqual(len(matches), 6)
def test_get_parents(self): def test_get_parents(self):
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment