{"action":"created","comment":{"url":"https://api.github.com/repos/ubc/ubcpi/pulls/comments/47794673","id":47794673,"diff_hunk":"@@ -242,7 +244,103 @@ def parse_from_xml(root):\n         'options': options,\n         'rationale_size': {'min': rationale_size_min, 'max': rationale_size_max},\n         'correct_answer': correct_answer,\n-        'correct_rationale': {'text': correct_rationale},\n+        'correct_rationale': correct_rationale,\n         'seeds': seeds,\n         'algo': {\"name\": algo, 'num_responses': num_responses}\n     }\n+\n+\n+def serialize_options(options, block):\n+    \"\"\"\n+    Serialize the options in peer instruction XBlock to xml\n+\n+    Args:\n+        options (lxml.etree.Element): The <options> XML element.\n+        block (PeerInstructionXBlock): The XBlock with configuration to serialize.\n+\n+    Returns:\n+        None\n+    \"\"\"\n+    for index, option_dict in enumerate(block.options):\n+        option = etree.SubElement(options, 'option')\n+        # set correct option and rationale\n+        if index == block.correct_answer:\n+            option.set('correct', u'True')\n+\n+            if hasattr(block, 'correct_rationale'):\n+                rationale = etree.SubElement(option, 'rationale')\n+                rationale.text = unicode(block.correct_rationale['text'])\n+\n+        text = etree.SubElement(option, 'text')\n+        text.text = unicode(option_dict.get('text', ''))\n+\n+        serialize_image(option, option_dict)\n+\n+\n+def serialize_image(root, image_dict):\n+    if 'image_url' not in image_dict:\n+        return\n+    image = etree.SubElement(root, 'image')\n+    image.text = unicode(image_dict.get('image_url', ''))\n+    for attr in ['image_position', 'image_show_fields', 'image_alt']:\n+        if image_dict.get(attr) is not None:\n+            image.set(attr[6:], unicode(image_dict.get(attr)))\n+\n+\n+def serialize_seeds(seeds, block):\n+    \"\"\"\n+    Serialize the seeds in peer instruction XBlock to xml\n+\n+    Args:\n+        seeds (lxml.etree.Element): The <seeds> XML element.\n+        block (PeerInstructionXBlock): The XBlock with configuration to serialize.\n+\n+    Returns:\n+        None\n+    \"\"\"\n+    for index, seed_dict in enumerate(block.seeds):\n+        seed = etree.SubElement(seeds, 'seed')\n+        # options in xml starts with 1\n+        seed.set('option', unicode(seed_dict.get('answer', 0) + 1))\n+        seed.text = unicode(seed_dict.get('rationale', ''))\n+\n+\n+def serialize_to_xml(block, root):","path":"ubcpi/serialize.py","position":110,"original_position":110,"commit_id":"adc6cc2b067034c34063542cd6a1490d963728e7","original_commit_id":"adc6cc2b067034c34063542cd6a1490d963728e7","user":{"login":"nedbat","id":23789,"avatar_url":"https://avatars.githubusercontent.com/u/23789?v=3","gravatar_id":"","url":"https://api.github.com/users/nedbat","html_url":"https://github.com/nedbat","followers_url":"https://api.github.com/users/nedbat/followers","following_url":"https://api.github.com/users/nedbat/following{/other_user}","gists_url":"https://api.github.com/users/nedbat/gists{/gist_id}","starred_url":"https://api.github.com/users/nedbat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nedbat/subscriptions","organizations_url":"https://api.github.com/users/nedbat/orgs","repos_url":"https://api.github.com/users/nedbat/repos","events_url":"https://api.github.com/users/nedbat/events{/privacy}","received_events_url":"https://api.github.com/users/nedbat/received_events","type":"User","site_admin":false},"body":"It might be easier to follow the code if you used a uniform signature.  Sometimes it's `(data, xml_element)`, and sometimes it's `(xml_element, data)`.","created_at":"2015-12-16T16:06:23Z","updated_at":"2015-12-16T16:06:23Z","html_url":"https://github.com/ubc/ubcpi/pull/55#discussion_r47794673","pull_request_url":"https://api.github.com/repos/ubc/ubcpi/pulls/55","_links":{"self":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/comments/47794673"},"html":{"href":"https://github.com/ubc/ubcpi/pull/55#discussion_r47794673"},"pull_request":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/55"}}},"pull_request":{"url":"https://api.github.com/repos/ubc/ubcpi/pulls/55","id":53085125,"html_url":"https://github.com/ubc/ubcpi/pull/55","diff_url":"https://github.com/ubc/ubcpi/pull/55.diff","patch_url":"https://github.com/ubc/ubcpi/pull/55.patch","issue_url":"https://api.github.com/repos/ubc/ubcpi/issues/55","number":55,"state":"open","locked":false,"title":"Changes since 0.4.4","user":{"login":"xcompass","id":465548,"avatar_url":"https://avatars.githubusercontent.com/u/465548?v=3","gravatar_id":"","url":"https://api.github.com/users/xcompass","html_url":"https://github.com/xcompass","followers_url":"https://api.github.com/users/xcompass/followers","following_url":"https://api.github.com/users/xcompass/following{/other_user}","gists_url":"https://api.github.com/users/xcompass/gists{/gist_id}","starred_url":"https://api.github.com/users/xcompass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xcompass/subscriptions","organizations_url":"https://api.github.com/users/xcompass/orgs","repos_url":"https://api.github.com/users/xcompass/repos","events_url":"https://api.github.com/users/xcompass/events{/privacy}","received_events_url":"https://api.github.com/users/xcompass/received_events","type":"User","site_admin":false},"body":"This is a PR for EdX review and PR is based from version 0.4.4 which is the current version in EdX. All changes are already in master. The changes include:\r\n* Updated UX based on feedbacks from the student usability testing\r\n* Updated UX and accessibility based on feedbacks from EdX\r\n* Added serialisation support for course export \r\n* Added EdX analytic event (https://openedx.atlassian.net/wiki/display/AN/Peer+Instruction+XBlock+Event+Design)\r\n* Disabled student empty rationale submission \r\n* Fixed a bug where a 500 error is generated when removing an option from list under certain condition\r\n* Fixed a bug where the responses are missing after going to a different page","created_at":"2015-12-09T07:26:26Z","updated_at":"2015-12-16T16:06:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33bd9f4993acb3a332e5b01a1e6d2f1c1bcbac40","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ubc/ubcpi/pulls/55/commits","review_comments_url":"https://api.github.com/repos/ubc/ubcpi/pulls/55/comments","review_comment_url":"https://api.github.com/repos/ubc/ubcpi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ubc/ubcpi/issues/55/comments","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/adc6cc2b067034c34063542cd6a1490d963728e7","head":{"label":"ubc:master","ref":"master","sha":"adc6cc2b067034c34063542cd6a1490d963728e7","user":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"repo":{"id":30939095,"name":"ubcpi","full_name":"ubc/ubcpi","owner":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubc/ubcpi","description":"Peer Instruction XBlock","fork":false,"url":"https://api.github.com/repos/ubc/ubcpi","forks_url":"https://api.github.com/repos/ubc/ubcpi/forks","keys_url":"https://api.github.com/repos/ubc/ubcpi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubc/ubcpi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubc/ubcpi/teams","hooks_url":"https://api.github.com/repos/ubc/ubcpi/hooks","issue_events_url":"https://api.github.com/repos/ubc/ubcpi/issues/events{/number}","events_url":"https://api.github.com/repos/ubc/ubcpi/events","assignees_url":"https://api.github.com/repos/ubc/ubcpi/assignees{/user}","branches_url":"https://api.github.com/repos/ubc/ubcpi/branches{/branch}","tags_url":"https://api.github.com/repos/ubc/ubcpi/tags","blobs_url":"https://api.github.com/repos/ubc/ubcpi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubc/ubcpi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubc/ubcpi/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubc/ubcpi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/{sha}","languages_url":"https://api.github.com/repos/ubc/ubcpi/languages","stargazers_url":"https://api.github.com/repos/ubc/ubcpi/stargazers","contributors_url":"https://api.github.com/repos/ubc/ubcpi/contributors","subscribers_url":"https://api.github.com/repos/ubc/ubcpi/subscribers","subscription_url":"https://api.github.com/repos/ubc/ubcpi/subscription","commits_url":"https://api.github.com/repos/ubc/ubcpi/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubc/ubcpi/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubc/ubcpi/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubc/ubcpi/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubc/ubcpi/contents/{+path}","compare_url":"https://api.github.com/repos/ubc/ubcpi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubc/ubcpi/merges","archive_url":"https://api.github.com/repos/ubc/ubcpi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubc/ubcpi/downloads","issues_url":"https://api.github.com/repos/ubc/ubcpi/issues{/number}","pulls_url":"https://api.github.com/repos/ubc/ubcpi/pulls{/number}","milestones_url":"https://api.github.com/repos/ubc/ubcpi/milestones{/number}","notifications_url":"https://api.github.com/repos/ubc/ubcpi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubc/ubcpi/labels{/name}","releases_url":"https://api.github.com/repos/ubc/ubcpi/releases{/id}","created_at":"2015-02-17T21:37:02Z","updated_at":"2015-12-01T20:14:02Z","pushed_at":"2015-12-15T23:52:00Z","git_url":"git://github.com/ubc/ubcpi.git","ssh_url":"git@github.com:ubc/ubcpi.git","clone_url":"https://github.com/ubc/ubcpi.git","svn_url":"https://github.com/ubc/ubcpi","homepage":null,"size":874,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":2,"default_branch":"master"}},"base":{"label":"ubc:edx-pr-0.5","ref":"edx-pr-0.5","sha":"7a8934352f0a50b5b14e92d8a30dfcdbe450c010","user":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"repo":{"id":30939095,"name":"ubcpi","full_name":"ubc/ubcpi","owner":{"login":"ubc","id":1396118,"avatar_url":"https://avatars.githubusercontent.com/u/1396118?v=3","gravatar_id":"","url":"https://api.github.com/users/ubc","html_url":"https://github.com/ubc","followers_url":"https://api.github.com/users/ubc/followers","following_url":"https://api.github.com/users/ubc/following{/other_user}","gists_url":"https://api.github.com/users/ubc/gists{/gist_id}","starred_url":"https://api.github.com/users/ubc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubc/subscriptions","organizations_url":"https://api.github.com/users/ubc/orgs","repos_url":"https://api.github.com/users/ubc/repos","events_url":"https://api.github.com/users/ubc/events{/privacy}","received_events_url":"https://api.github.com/users/ubc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ubc/ubcpi","description":"Peer Instruction XBlock","fork":false,"url":"https://api.github.com/repos/ubc/ubcpi","forks_url":"https://api.github.com/repos/ubc/ubcpi/forks","keys_url":"https://api.github.com/repos/ubc/ubcpi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ubc/ubcpi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ubc/ubcpi/teams","hooks_url":"https://api.github.com/repos/ubc/ubcpi/hooks","issue_events_url":"https://api.github.com/repos/ubc/ubcpi/issues/events{/number}","events_url":"https://api.github.com/repos/ubc/ubcpi/events","assignees_url":"https://api.github.com/repos/ubc/ubcpi/assignees{/user}","branches_url":"https://api.github.com/repos/ubc/ubcpi/branches{/branch}","tags_url":"https://api.github.com/repos/ubc/ubcpi/tags","blobs_url":"https://api.github.com/repos/ubc/ubcpi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ubc/ubcpi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ubc/ubcpi/git/refs{/sha}","trees_url":"https://api.github.com/repos/ubc/ubcpi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ubc/ubcpi/statuses/{sha}","languages_url":"https://api.github.com/repos/ubc/ubcpi/languages","stargazers_url":"https://api.github.com/repos/ubc/ubcpi/stargazers","contributors_url":"https://api.github.com/repos/ubc/ubcpi/contributors","subscribers_url":"https://api.github.com/repos/ubc/ubcpi/subscribers","subscription_url":"https://api.github.com/repos/ubc/ubcpi/subscription","commits_url":"https://api.github.com/repos/ubc/ubcpi/commits{/sha}","git_commits_url":"https://api.github.com/repos/ubc/ubcpi/git/commits{/sha}","comments_url":"https://api.github.com/repos/ubc/ubcpi/comments{/number}","issue_comment_url":"https://api.github.com/repos/ubc/ubcpi/issues/comments{/number}","contents_url":"https://api.github.com/repos/ubc/ubcpi/contents/{+path}","compare_url":"https://api.github.com/repos/ubc/ubcpi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ubc/ubcpi/merges","archive_url":"https://api.github.com/repos/ubc/ubcpi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ubc/ubcpi/downloads","issues_url":"https://api.github.com/repos/ubc/ubcpi/issues{/number}","pulls_url":"https://api.github.com/repos/ubc/ubcpi/pulls{/number}","milestones_url":"https://api.github.com/repos/ubc/ubcpi/milestones{/number}","notifications_url":"https://api.github.com/repos/ubc/ubcpi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ubc/ubcpi/labels{/name}","releases_url":"https://api.github.com/repos/ubc/ubcpi/releases{/id}","created_at":"2015-02-17T21:37:02Z","updated_at":"2015-12-01T20:14:02Z","pushed_at":"2015-12-15T23:52:00Z","git_url":"git://github.com/ubc/ubcpi.git","ssh_url":"git@github.com:ubc/ubcpi.git","clone_url":"https://github.com/ubc/ubcpi.git","svn_url":"https://github.com/ubc/ubcpi","homepage":null,"size":874,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/55"},"html":{"href":"https://github.com/ubc/ubcpi/pull/55"},"issue":{"href":"https://api.github.com/repos/ubc/ubcpi/issues/55"},"comments":{"href":"https://api.github.com/repos/ubc/ubcpi/issues/55/comments"},"review_comments":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/55/comments"},"review_comment":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ubc/ubcpi/pulls/55/commits"},"statuses":{"href":"https://api.github.com/repos/ubc/ubcpi/statuses/adc6cc2b067034c34063542cd6a1490d963728e7"}}}}