def publish(block, event_type, event): """A function that allows XModules to publish events.""" if event_type == 'grade' and not is_masquerading_as_specific_student( user, course_id): SCORE_PUBLISHED.send( sender=None, block=block, user=user, raw_earned=event['value'], raw_possible=event['max_value'], only_if_higher=event.get('only_if_higher'), ) else: context = contexts.course_context_from_course_id(course_id) if block.runtime.user_id: context['user_id'] = block.runtime.user_id context['asides'] = {} for aside in block.runtime.get_asides(block): if hasattr(aside, 'get_event_context'): aside_event_info = aside.get_event_context( event_type, event) if aside_event_info is not None: context['asides'][ aside.scope_ids.block_type] = aside_event_info with tracker.get_tracker().context(event_type, context): track_function(event_type, event)
def handle_grade_event(block, event_type, event): # pylint: disable=unused-argument """ Manages the workflow for recording and updating of student module grade state """ if not settings.FEATURES.get("ALLOW_STUDENT_STATE_UPDATES_ON_CLOSED_COURSE", True): # if a course has ended, don't register grading events course = modulestore().get_course(course_id, depth=0) now = datetime.now(UTC()) if course.end is not None and now > course.end: return SCORE_PUBLISHED.send( sender=None, block=block, user=user, raw_earned=event['value'], raw_possible=event['max_value'], only_if_higher=event.get('only_if_higher'), ) # we can treat a grading event as a indication that a user # "completed" an xBlock if settings.FEATURES.get('MARK_PROGRESS_ON_GRADING_EVENT', False): handle_progress_event(block, event_type, event)
def handle_grade_event(block, event): """ Submit a grade for the block. """ SCORE_PUBLISHED.send( sender=None, block=block, user=user, raw_earned=event['value'], raw_possible=event['max_value'], only_if_higher=event.get('only_if_higher'), score_deleted=event.get('score_deleted'), )
def handle_grade_event(block, event): """ Submit a grade for the block. """ SCORE_PUBLISHED.send( sender=None, block=block, user=user, raw_earned=event['value'], raw_possible=event['max_value'], only_if_higher=event.get('only_if_higher'), score_deleted=event.get('score_deleted'), )
def grades(self, request, pk): """ Submit a grade for a Workgroup. The grade will be applied to all members of the workgroup """ # Ensure we received all of the necessary information course_id = request.data.get('course_id') if course_id is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) course_key = get_course_key(course_id) if not course_key: return Response({}, status=status.HTTP_400_BAD_REQUEST) course_descriptor = get_course(course_key) if not course_descriptor: return Response({}, status=status.HTTP_400_BAD_REQUEST) content_id = request.data.get('content_id') if content_id is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) try: usage_key = UsageKey.from_string(content_id) except InvalidKeyError: return Response({}, status=status.HTTP_400_BAD_REQUEST) content_descriptor = modulestore().get_item(usage_key) if content_descriptor is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) grade = request.data.get('grade') if grade is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) max_grade = request.data.get('max_grade') if max_grade is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) if grade > max_grade: max_grade = grade users = User.objects.filter(workgroups=pk) for user in users: SCORE_PUBLISHED.send( sender=None, block=content_descriptor, user=user, raw_earned=grade, raw_possible=max_grade, only_if_higher=None, ) return Response({}, status=status.HTTP_201_CREATED)
def grades(self, request, pk): """ Submit a grade for a Workgroup. The grade will be applied to all members of the workgroup """ # Ensure we received all of the necessary information course_id = request.data.get('course_id') if course_id is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) course_key = get_course_key(course_id) if not course_key: return Response({}, status=status.HTTP_400_BAD_REQUEST) course_descriptor = get_course(course_key) if not course_descriptor: return Response({}, status=status.HTTP_400_BAD_REQUEST) content_id = request.data.get('content_id') if content_id is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) try: usage_key = UsageKey.from_string(content_id) except InvalidKeyError: return Response({}, status=status.HTTP_400_BAD_REQUEST) content_descriptor = modulestore().get_item(usage_key) if content_descriptor is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) grade = request.data.get('grade') if grade is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) max_grade = request.data.get('max_grade') if max_grade is None: return Response({}, status=status.HTTP_400_BAD_REQUEST) if grade > max_grade: max_grade = grade users = User.objects.filter(workgroups=pk) for user in users: SCORE_PUBLISHED.send( sender=None, block=content_descriptor, user=user, raw_earned=grade, raw_possible=max_grade, only_if_higher=None, ) return Response({}, status=status.HTTP_201_CREATED)
def publish(block, event_type, event): """A function that allows XModules to publish events.""" if event_type == 'grade' and not is_masquerading_as_specific_student(user, course_id): SCORE_PUBLISHED.send( sender=None, block=block, user=user, raw_earned=event['value'], raw_possible=event['max_value'], only_if_higher=event.get('only_if_higher'), ) else: aside_context = {} for aside in block.runtime.get_asides(block): if hasattr(aside, 'get_event_context'): aside_event_info = aside.get_event_context(event_type, event) if aside_event_info is not None: aside_context[aside.scope_ids.block_type] = aside_event_info with tracker.get_tracker().context('asides', {'asides': aside_context}): track_function(event_type, event)