Exemple #1
0
def make_canvas_quiz(coursera_file, is_survey, canvas_id, canvas_folder, course):
    """
    Create a Canvas quiz (2 XML files).
    """
    xml = util.read_file(coursera_file)
    xml = wiki.convert_content(xml, course)
    quiz = util.read_xml(xml, is_string=True)

    metadata = quiz.find('metadata')
    preamble = quiz.findtext('preamble')
    data = quiz.find('data')

    metadata.set('canvas_id', canvas_id)
    metadata.set('is_survey', is_survey)

    metadata_file = make_canvas_metadata(course, metadata, preamble, canvas_folder)
    data_file = make_canvas_data(data, metadata, canvas_folder)

    args = {
        'id': canvas_id,
        'type': 'associatedcontent/imscc_xmlv1p1/learning-application-resource',
        'path': metadata_file,
        'files': resource.FILE.format(metadata_file) + resource.FILE.format(data_file)
    }
    course.add_resources(args)
Exemple #2
0
def make_solution_page(course, assignment, canvas_id, title, file_name):
    page = ""
    questions = assignment["form"][1]["children"]
    for question in questions:
        html = wiki.convert_content(question["html"], course)
        page += html
        for evaluation in question["evaluation"]["children"]:
            if evaluation["children"][0]["type"] == "gradingNumber":
                html = wiki.convert_content(evaluation["html"], course)
                page += u"<p>{}</p>".format(html)

    canvas_id = "wiki_{}_solution".format(canvas_id)
    canvas_path = "wiki_content/{}-solution.html".format(file_name)
    canvas_file = "{}/{}".format(course.get_canvas_folder(), canvas_path)
    title = "{} solution".format(title)

    wiki.make_canvas_wiki(page, title, canvas_file, canvas_id, course)
    args = {"id": canvas_id, "type": "webcontent", "path": canvas_path, "files": resource.FILE.format(canvas_path)}
    course.add_resources(args)
Exemple #3
0
def make_description_page(course, assignment, canvas_id, title, file_name):
    page = ""

    intros = assignment["form"][0]["children"]
    for intro in intros:
        html = wiki.convert_content(intro["html"], course)
        page += u"<p>{}</p>".format(html)

    questions = assignment["form"][1]["children"]
    for question in questions:
        html = wiki.convert_content(question["html"], course)
        page += u"<p>{}</p>".format(html)

    canvas_id = "wiki_{}".format(canvas_id)
    canvas_path = "wiki_content/{}.html".format(file_name)
    canvas_file = course.get_canvas_folder() + "/" + canvas_path

    wiki.make_canvas_wiki(page, title, canvas_file, canvas_id, course)

    args = {"id": canvas_id, "type": "webcontent", "path": canvas_path, "files": resource.FILE.format(canvas_path)}
    course.add_resources(args)
Exemple #4
0
def convert(course, item):
    coursera_folder = course.get_coursera_folder()
    canvas_folder = course.get_canvas_folder()

    data_canvas_id = item['canvas_id']
    meta_canvas_id = data_canvas_id + '_meta'

    data_file = '{}.xml'.format(data_canvas_id)
    meta_file = '{}.xml'.format(meta_canvas_id)

    data_path = '{}/{}'.format(canvas_folder, data_file)
    meta_path = '{}/{}'.format(canvas_folder, meta_file)

    pos = course.get_topic_pos()
    course.set_topic_pos(pos + 1)

    coursera_file = '{}/announcement/{}.json'.format(coursera_folder, item['item_id'])
    announcement = util.read_json(coursera_file)
    args = {
        'topic_id': item['canvas_id'],
        'title': item['title'],
        'position': pos,
        'content': wiki.convert_content(announcement['message'], course)
    }

    meta = META.format(**args)
    data = TOPIC.format(**args)

    util.write_file(data_path, data)
    util.write_file(meta_path, meta)

    data_args = {
        'id': data_canvas_id,
        'type': 'imsdt_xmlv1p1',
        'path': '',
        'files': resource.FILE.format(data_file) + resource.DEPENDENCY.format(meta_canvas_id)
    }
    meta_args = {
        'id': meta_canvas_id,
        'type': 'associatedcontent/imscc_xmlv1p1/learning-application-resource',
        'path': meta_file,
        'files': resource.FILE.format(meta_file)
    }
    course.add_resources(data_args)
    course.add_resources(meta_args)
Exemple #5
0
def convert(course, item):
    coursera_id = item['item_id']
    coursera_folder = course.get_coursera_folder()
    coursera_file = '{}/assignment/{}.html'.format(coursera_folder, coursera_id)

    canvas_id = item['canvas_id']
    canvas_folder = course.get_canvas_folder()

    title = item['title']
    assignment = util.read_file(coursera_file)
    assignment = wiki.convert_content(assignment, course)

    main_file = make_main_file(assignment, canvas_folder, canvas_id, title)
    settings_file = make_settings_file(course, canvas_folder, canvas_id, title)

    args = {
        'id': canvas_id,
        'type': 'associatedcontent/imscc_xmlv1p1/learning-application-resource',
        'path': main_file,
        'files': resource.FILE.format(main_file) + resource.FILE.format(settings_file)
    }
    course.add_resources(args)
Exemple #6
0
def find_links(text, course):
    ans = []
    text = wiki.convert_content(text, course)
    for match in re.finditer(r'href="(.*?)"', text):
        ans.append(match.group(1))
    return ans