本文整理汇总了Python中lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag.feature_enabled方法的典型用法代码示例。如果您正苦于以下问题:Python PersistentGradesEnabledFlag.feature_enabled方法的具体用法?Python PersistentGradesEnabledFlag.feature_enabled怎么用?Python PersistentGradesEnabledFlag.feature_enabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag
的用法示例。
在下文中一共展示了PersistentGradesEnabledFlag.feature_enabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def create(self, subsection, block_structure=None, read_only=False):
"""
Returns the SubsectionGrade object for the student and subsection.
If block_structure is provided, uses it for finding and computing
the grade instead of the course_structure passed in earlier.
If read_only is True, doesn't save any updates to the grades.
"""
self._log_event(
log.warning, u"create, read_only: {0}, subsection: {1}".format(read_only, subsection.location)
)
block_structure = self._get_block_structure(block_structure)
subsection_grade = self._get_saved_grade(subsection, block_structure)
if not subsection_grade:
subsection_grade = SubsectionGrade(subsection, self.course)
subsection_grade.init_from_structure(
self.student, block_structure, self._scores_client, self._submissions_scores
)
if PersistentGradesEnabledFlag.feature_enabled(self.course.id):
if read_only:
self._unsaved_subsection_grades.append(subsection_grade)
else:
with persistence_safe_fallback():
grade_model = subsection_grade.create_model(self.student)
self._update_saved_subsection_grade(subsection.location, grade_model)
return subsection_grade
示例2: test_persistent_grades_not_enabled_on_course
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_persistent_grades_not_enabled_on_course(self, default_store):
with self.store.default_store(default_store):
self.set_up_course(enable_persistent_grades=False)
self.assertFalse(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
with check_mongo_calls(0):
with self.assertNumQueries(0):
self._apply_recalculate_subsection_grade()
示例3: _get_saved_grade
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def _get_saved_grade(self, course, course_structure): # pylint: disable=unused-argument
"""
Returns the saved grade for the given course and student.
"""
if PersistentGradesEnabledFlag.feature_enabled(course.id):
# TODO LATER Retrieve the saved grade for the course, if it exists.
_pretend_to_save_course_grades()
示例4: recalculate_subsection_grade_handler
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def recalculate_subsection_grade_handler(sender, **kwargs): # pylint: disable=unused-argument
"""
Consume the SCORE_CHANGED signal and trigger an update.
This method expects that the kwargs dictionary will contain the following
entries (See the definition of SCORE_CHANGED):
- points_possible: Maximum score available for the exercise
- points_earned: Score obtained by the user
- user: User object
- course_id: Unicode string representing the course
- usage_id: Unicode string indicating the courseware instance
"""
try:
course_id = kwargs.get('course_id', None)
usage_id = kwargs.get('usage_id', None)
student = kwargs.get('user', None)
course_key = CourseLocator.from_string(course_id)
if not PersistentGradesEnabledFlag.feature_enabled(course_key):
return
usage_key = UsageKey.from_string(usage_id).replace(course_key=course_key)
from lms.djangoapps.grades.new.subsection_grade import SubsectionGradeFactory
SubsectionGradeFactory(student).update(usage_key, course_key)
except Exception as ex: # pylint: disable=broad-except
log.exception(
u"Failed to process SCORE_CHANGED signal. "
"user: %s, course_id: %s, "
"usage_id: %s. Exception: %s", unicode(student), course_id, usage_id, ex.message
)
示例5: test_query_counts
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_query_counts(self, default_store, num_mongo_calls, num_sql_calls, create_multiple_subsections):
with self.store.default_store(default_store):
self.set_up_course(create_multiple_subsections=create_multiple_subsections)
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
with check_mongo_calls(num_mongo_calls):
with self.assertNumQueries(num_sql_calls):
self._apply_recalculate_subsection_grade()
示例6: test_persistent_grades_feature_flags
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_persistent_grades_feature_flags(self, global_flag, enabled_for_all_courses, enabled_for_course_1):
with persistent_grades_feature_flags(
global_flag=global_flag,
enabled_for_all_courses=enabled_for_all_courses,
course_id=self.course_id_1,
enabled_for_course=enabled_for_course_1
):
self.assertEqual(PersistentGradesEnabledFlag.feature_enabled(), global_flag)
self.assertEqual(
PersistentGradesEnabledFlag.feature_enabled(self.course_id_1),
global_flag and (enabled_for_all_courses or enabled_for_course_1)
)
self.assertEqual(
PersistentGradesEnabledFlag.feature_enabled(self.course_id_2),
global_flag and enabled_for_all_courses
)
示例7: update
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def update(self, subsection, only_if_higher=None):
"""
Updates the SubsectionGrade object for the student and subsection.
"""
# Save ourselves the extra queries if the course does not persist
# subsection grades.
if not PersistentGradesEnabledFlag.feature_enabled(self.course.id):
return
self._log_event(log.warning, u"update, subsection: {}".format(subsection.location), subsection)
calculated_grade = SubsectionGrade(subsection).init_from_structure(
self.student, self.course_structure, self._submissions_scores, self._csm_scores,
)
if only_if_higher:
try:
grade_model = PersistentSubsectionGrade.read_grade(self.student.id, subsection.location)
except PersistentSubsectionGrade.DoesNotExist:
pass
else:
orig_subsection_grade = SubsectionGrade(subsection).init_from_model(
self.student, grade_model, self.course_structure, self._submissions_scores, self._csm_scores,
)
if not is_score_higher(
orig_subsection_grade.graded_total.earned,
orig_subsection_grade.graded_total.possible,
calculated_grade.graded_total.earned,
calculated_grade.graded_total.possible,
):
return orig_subsection_grade
grade_model = calculated_grade.update_or_create_model(self.student)
self._update_saved_subsection_grade(subsection.location, grade_model)
return calculated_grade
示例8: _get_saved_grade
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def _get_saved_grade(self, course, course_structure):
"""
Returns the saved grade for the given course and student.
"""
if not PersistentGradesEnabledFlag.feature_enabled(course.id):
return None
return CourseGrade.load_persisted_grade(self.student, course, course_structure)
示例9: test_query_count_does_not_change_with_more_problems
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_query_count_does_not_change_with_more_problems(self, default_store):
with self.store.default_store(default_store):
self.set_up_course()
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
ItemFactory.create(parent=self.sequential, category='problem', display_name='problem2')
ItemFactory.create(parent=self.sequential, category='problem', display_name='problem3')
with check_mongo_calls(2) and self.assertNumQueries(15):
recalculate_subsection_grade_handler(None, **self.score_changed_kwargs)
示例10: test_query_count_does_not_change_with_more_problems
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_query_count_does_not_change_with_more_problems(self, default_store, added_queries):
with self.store.default_store(default_store):
self.set_up_course()
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
ItemFactory.create(parent=self.sequential, category="problem", display_name="problem2")
ItemFactory.create(parent=self.sequential, category="problem", display_name="problem3")
with check_mongo_calls(2) and self.assertNumQueries(20 + added_queries):
self._apply_recalculate_subsection_grade()
示例11: test_single_call_to_create_block_structure
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_single_call_to_create_block_structure(self):
self.set_up_course()
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
with patch(
"openedx.core.lib.block_structure.factory.BlockStructureFactory.create_from_cache", return_value=None
) as mock_block_structure_create:
self._apply_recalculate_subsection_grade()
self.assertEquals(mock_block_structure_create.call_count, 1)
示例12: test_single_call_to_create_block_structure
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_single_call_to_create_block_structure(self):
self.set_up_course()
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
with patch(
'openedx.core.lib.block_structure.factory.BlockStructureFactory.create_from_cache',
return_value=None,
) as mock_block_structure_create:
recalculate_subsection_grade_handler(None, **self.score_changed_kwargs)
self.assertEquals(mock_block_structure_create.call_count, 1)
示例13: get_persisted
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def get_persisted(self, student, course):
"""
Returns the saved grade for the given course and student,
irrespective of whether the saved grade is up-to-date.
"""
if not PersistentGradesEnabledFlag.feature_enabled(course.id):
return None
return CourseGrade.get_persisted_grade(student, course)
示例14: test_block_structure_created_only_once
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_block_structure_created_only_once(self):
self.set_up_course()
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course.id))
with patch(
'openedx.core.djangoapps.content.block_structure.factory.BlockStructureFactory.create_from_store',
side_effect=BlockStructureNotFound(self.course.location),
) as mock_block_structure_create:
self._apply_recalculate_subsection_grade()
self.assertEquals(mock_block_structure_create.call_count, 1)
示例15: test_enable_disable_course_flag
# 需要导入模块: from lms.djangoapps.grades.config.models import PersistentGradesEnabledFlag [as 别名]
# 或者: from lms.djangoapps.grades.config.models.PersistentGradesEnabledFlag import feature_enabled [as 别名]
def test_enable_disable_course_flag(self):
"""
Ensures that the flag, once enabled for a course, can also be disabled.
"""
with persistent_grades_feature_flags(
global_flag=True,
enabled_for_all_courses=False,
course_id=self.course_id_1,
enabled_for_course=True
):
self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))
# Prior to TNL-5698, creating a second object would fail due to db constraints
with persistent_grades_feature_flags(
global_flag=True,
enabled_for_all_courses=False,
course_id=self.course_id_1,
enabled_for_course=False
):
self.assertFalse(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))