Esempio n. 1
0
 def backend_setting(self, setting_name, default=None):
     """ Get a setting, from XapiBackendConfig """
     from xapi.models import XapiBackendConfig
     self.config = XapiBackendConfig.current()
     if hasattr(self.config, str(setting_name)):
         return getattr(self.config, str(setting_name))
     else:
         return default
Esempio n. 2
0
 def send_2_tincan_by_settings(cls):
     options = XapiBackendConfig.current()
     cls.send_2_tincan(
         options.lrs_api_url,
         options.username_lrs,
         options.password_lrs,
         options.extracted_event_number,
         10)
Esempio n. 3
0
def _generate_course_structure(course_key):
    """
    Generates a course structure dictionary for the specified course.
    """

    course = modulestore().get_course(course_key, depth=None)
    end_date = course.end
    blocks_stack = [course]
    blocks_dict = {}
    while blocks_stack:
        curr_block = blocks_stack.pop()
        children = curr_block.get_children() if curr_block.has_children else []
        key = unicode(curr_block.scope_ids.usage_id)
        typeblock = ACTIVITY_TYPE.get(curr_block.category, curr_block.category)
        block = {
            "id": key,
            "type": typeblock,
            "completedTimestamp": end_date
        }

        # Retrieve these attributes separately so that we can fail gracefully if the block doesn't have the attribute.
        # attrs = (('end_date', None), ('format', None), ("completedTimestamp", None), ("relativeCompletion", None))
        # for attr, default in attrs:
        #    if hasattr(curr_block, attr):
        #        block[attr] = getattr(curr_block, attr, default)
        #    else:
        #        log.warning('Failed to retrieve %s attribute of block %s. Defaulting to %s.', attr, key, default)
        #        block[attr] = default

        blocks_dict[key] = block

        # Add this blocks children to the stack so that we can traverse them as well.
        blocks_stack.extend(children)
    oai_prefix = XapiBackendConfig.current().oai_prefix
    return {
        "moocId": oai_prefix+course_key.to_deprecated_string(),
        "tasks": blocks_dict.values()
    }
Esempio n. 4
0
def tasks(request, course_id):  # pylint: disable=unused-argument
    '''
    Retrieve course structure for Learning Analytics integration
    https://docs.google.com/document/d/1pTcAm9o9XrHXgiXkm7YzFWHqusvPQN4xRnVuMDjg-lA
    '''
    course_key = ""
    oai_prefix = XapiBackendConfig.current().oai_prefix
    course_id = course_id.replace(oai_prefix, "")
    try:
        course_key = CourseKey.from_string(course_id)
    except InvalidKeyError:
        course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)

    try:
        oai_course = OaiRecord.objects.get(identifier=oai_prefix + course_id)  # pylint: disable=unused-variable
    except OaiRecord.DoesNotExist:
        return JsonResponse({}, status=404)
    try:
        structure = CourseStructureCache.objects.get(course_id=course_key)
        return JsonResponse(json.loads(structure.structure_json))
    except CourseStructureCache.DoesNotExist:
        update_course_structure.delay(unicode(course_key))
        return JsonResponse({}, status=503)