GitHub PullRequestReviewCommentEvent at 2014-12-02 16:56:12
Repository: icommons_lti_tools
Actor: elliottyates
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/comments/21172512","id":21172512,"diff_hunk":"@@ -0,0 +1,279 @@\n+from django.core.management.base import (BaseCommand, CommandError)\n+from django.core.exceptions import ObjectDoesNotExist\n+from django.conf import settings\n+\n+from canvas_sdk.methods import (courses, accounts, sections, enrollments) \n+from canvas_sdk.utils import get_all_list_data\n+from icommons_common.models import (Section, SectionMember, CourseInstance)\n+from icommons_common.canvas_utils import SessionInactivityExpirationRC\n+import logging\n+\n+SDK_CONTEXT = SessionInactivityExpirationRC(**settings.CANVAS_SDK_SETTINGS)\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class Command(BaseCommand):\n+    \n+    help = 'sync canvas sections and section members to the coursemanager.section and coursemanager.section_member tables'\n+    \n+    def handle(self, *args, **options):\n+        \"\"\"\n+        sync canvas sections and section members to the coursemanager.section and coursemanager.section_member tables\n+        \"\"\"\n+\n+        sub_list = get_account_list_from_canvas()\n+        for account_id in sorted(sub_list):       \n+            course_list = get_course_list_from_canvas(account_id)     \n+            for course in course_list:        \n+                sis_course_id = course.get('sis_course_id', None)\n+                canvas_course_id = course.get('id', None)\n+                if sis_course_id and sis_course_id.isnumeric() and canvas_course_id: \n+                    \n+                    try:\n+                        ci = CourseInstance.objects.get(pk=sis_course_id)\n+                    except ObjectDoesNotExist:\n+                        \"\"\"\n+                        if the course instance id in canvas does not exists in the coursemanager\n+                        course_instance table. This is ok as some of the early canvas courses don't have\n+                        course instance records in the coursemanager db, log the exception and continue\n+                        \"\"\"\n+                        logger.exception('course_instance %s does not exist for canvas_course_id %s' % (sis_course_id, canvas_course_id))\n+                        continue\n+\n+                    \"\"\"\n+                    get the list of sections associated with the canvas_course_id\n+                    \"\"\"\n+                    canvas_course_sections_set = set(get_canvas_sections_list(canvas_course_id))\n+                    \n+                    \"\"\"\n+                    get the list of sections associated with the course_instance\n+                    \"\"\"\n+                    cm_section_set = set(get_cm_sections_list(ci))\n+\n+                    \"\"\"\n+                    convert the lists to sets so we can perform set operations:\n+                             a = set('1','2','3')\n+                             b = set('2','3','4')\n+                             c = a - b = ('1') items in a but not in b\n+                             d = b - a = ('4') items in b but not in a\n+\n+                    this tells us what sections we need to add and remove\n+                    \"\"\"\n+            \n+                    sections_to_remove = cm_section_set - canvas_course_sections_set\n+                  \n+                    \"\"\"\n+                    If a section was deleted from Canvas we want to also delete the\n+                    section from the section table. We also need to delete all the\n+                    section members in the section_member table.\n+                    \"\"\"\n+                    for canvas_section_id in sections_to_remove:\n+                        if canvas_section_id:","path":"add_people/management/commands/sync_canvas_sections.py","position":72,"original_position":72,"commit_id":"43455d5cbf2d716ac730d9cca6890d9eb1c8307f","original_commit_id":"43455d5cbf2d716ac730d9cca6890d9eb1c8307f","user":{"login":"elliottyates","id":8975317,"avatar_url":"https://avatars.githubusercontent.com/u/8975317?v=3","gravatar_id":"","url":"https://api.github.com/users/elliottyates","html_url":"https://github.com/elliottyates","followers_url":"https://api.github.com/users/elliottyates/followers","following_url":"https://api.github.com/users/elliottyates/following{/other_user}","gists_url":"https://api.github.com/users/elliottyates/gists{/gist_id}","starred_url":"https://api.github.com/users/elliottyates/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elliottyates/subscriptions","organizations_url":"https://api.github.com/users/elliottyates/orgs","repos_url":"https://api.github.com/users/elliottyates/repos","events_url":"https://api.github.com/users/elliottyates/events{/privacy}","received_events_url":"https://api.github.com/users/elliottyates/received_events","type":"User","site_admin":false},"body":"Why do you need to check this again, don't you only get to this code if canvas_section_id exists in sections_to_remove? Given you've done set operations, when would this be None or equal to an empty string?","created_at":"2014-12-02T16:56:12Z","updated_at":"2014-12-02T16:56:12Z","html_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132#discussion_r21172512","pull_request_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132","_links":{"self":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/comments/21172512"},"html":{"href":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132#discussion_r21172512"},"pull_request":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132"}}},"pull_request":{"url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132","id":25298698,"html_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132","diff_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132.diff","patch_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132.patch","issue_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/132","number":132,"state":"open","locked":false,"title":"Feature/tlt 466 adding api to new batch job to grab section data from canvas","user":{"login":"eparker71","id":1084287,"avatar_url":"https://avatars.githubusercontent.com/u/1084287?v=3","gravatar_id":"","url":"https://api.github.com/users/eparker71","html_url":"https://github.com/eparker71","followers_url":"https://api.github.com/users/eparker71/followers","following_url":"https://api.github.com/users/eparker71/following{/other_user}","gists_url":"https://api.github.com/users/eparker71/gists{/gist_id}","starred_url":"https://api.github.com/users/eparker71/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eparker71/subscriptions","organizations_url":"https://api.github.com/users/eparker71/orgs","repos_url":"https://api.github.com/users/eparker71/repos","events_url":"https://api.github.com/users/eparker71/events{/privacy}","received_events_url":"https://api.github.com/users/eparker71/received_events","type":"User","site_admin":false},"body":"Adds the django command sync_canvas_sections which will keep the section and section_member tables in the course manager database in sync with the canvas sections. For this command Canvas is the master sections holder, any changes in canvas will be synchronized with the coursemanager database but not the other way around. changes to the course_manager database will not be synced with canvas. \r\n\r\nIf a section already exists in the coursemanager it will be updated if the name changed or if there are member to be added or removed. If the section does not exist, it will be created. ","created_at":"2014-12-01T21:05:55Z","updated_at":"2014-12-02T16:56:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ded09e4352ed074f8d3207d127054fc507ce3b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132/commits","review_comments_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132/comments","review_comment_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/132/comments","statuses_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/statuses/43455d5cbf2d716ac730d9cca6890d9eb1c8307f","head":{"label":"Harvard-University-iCommons:feature/TLT-466-Adding-API-to-new-batch-job-to-grab-section-data-from-Canvas","ref":"feature/TLT-466-Adding-API-to-new-batch-job-to-grab-section-data-from-Canvas","sha":"43455d5cbf2d716ac730d9cca6890d9eb1c8307f","user":{"login":"Harvard-University-iCommons","id":1083915,"avatar_url":"https://avatars.githubusercontent.com/u/1083915?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvard-University-iCommons","html_url":"https://github.com/Harvard-University-iCommons","followers_url":"https://api.github.com/users/Harvard-University-iCommons/followers","following_url":"https://api.github.com/users/Harvard-University-iCommons/following{/other_user}","gists_url":"https://api.github.com/users/Harvard-University-iCommons/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvard-University-iCommons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvard-University-iCommons/subscriptions","organizations_url":"https://api.github.com/users/Harvard-University-iCommons/orgs","repos_url":"https://api.github.com/users/Harvard-University-iCommons/repos","events_url":"https://api.github.com/users/Harvard-University-iCommons/events{/privacy}","received_events_url":"https://api.github.com/users/Harvard-University-iCommons/received_events","type":"Organization","site_admin":false},"repo":{"id":14696916,"name":"icommons_lti_tools","full_name":"Harvard-University-iCommons/icommons_lti_tools","owner":{"login":"Harvard-University-iCommons","id":1083915,"avatar_url":"https://avatars.githubusercontent.com/u/1083915?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvard-University-iCommons","html_url":"https://github.com/Harvard-University-iCommons","followers_url":"https://api.github.com/users/Harvard-University-iCommons/followers","following_url":"https://api.github.com/users/Harvard-University-iCommons/following{/other_user}","gists_url":"https://api.github.com/users/Harvard-University-iCommons/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvard-University-iCommons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvard-University-iCommons/subscriptions","organizations_url":"https://api.github.com/users/Harvard-University-iCommons/orgs","repos_url":"https://api.github.com/users/Harvard-University-iCommons/repos","events_url":"https://api.github.com/users/Harvard-University-iCommons/events{/privacy}","received_events_url":"https://api.github.com/users/Harvard-University-iCommons/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools","description":"icf@hsph","fork":false,"url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools","forks_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/forks","keys_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/teams","hooks_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/hooks","issue_events_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/events{/number}","events_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/events","assignees_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/assignees{/user}","branches_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/branches{/branch}","tags_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/tags","blobs_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/languages","stargazers_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/stargazers","contributors_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/contributors","subscribers_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/subscribers","subscription_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/subscription","commits_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/comments/{number}","contents_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/contents/{+path}","compare_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/merges","archive_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/downloads","issues_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues{/number}","pulls_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/labels{/name}","releases_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/releases{/id}","created_at":"2013-11-25T20:06:20Z","updated_at":"2014-11-24T18:11:17Z","pushed_at":"2014-12-01T21:01:08Z","git_url":"git://github.com/Harvard-University-iCommons/icommons_lti_tools.git","ssh_url":"git@github.com:Harvard-University-iCommons/icommons_lti_tools.git","clone_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools.git","svn_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools","homepage":"","size":7321,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":1,"default_branch":"develop"}},"base":{"label":"Harvard-University-iCommons:develop","ref":"develop","sha":"c44fd69849ad7f449772e8b8ec7f6e32cead82e9","user":{"login":"Harvard-University-iCommons","id":1083915,"avatar_url":"https://avatars.githubusercontent.com/u/1083915?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvard-University-iCommons","html_url":"https://github.com/Harvard-University-iCommons","followers_url":"https://api.github.com/users/Harvard-University-iCommons/followers","following_url":"https://api.github.com/users/Harvard-University-iCommons/following{/other_user}","gists_url":"https://api.github.com/users/Harvard-University-iCommons/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvard-University-iCommons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvard-University-iCommons/subscriptions","organizations_url":"https://api.github.com/users/Harvard-University-iCommons/orgs","repos_url":"https://api.github.com/users/Harvard-University-iCommons/repos","events_url":"https://api.github.com/users/Harvard-University-iCommons/events{/privacy}","received_events_url":"https://api.github.com/users/Harvard-University-iCommons/received_events","type":"Organization","site_admin":false},"repo":{"id":14696916,"name":"icommons_lti_tools","full_name":"Harvard-University-iCommons/icommons_lti_tools","owner":{"login":"Harvard-University-iCommons","id":1083915,"avatar_url":"https://avatars.githubusercontent.com/u/1083915?v=3","gravatar_id":"","url":"https://api.github.com/users/Harvard-University-iCommons","html_url":"https://github.com/Harvard-University-iCommons","followers_url":"https://api.github.com/users/Harvard-University-iCommons/followers","following_url":"https://api.github.com/users/Harvard-University-iCommons/following{/other_user}","gists_url":"https://api.github.com/users/Harvard-University-iCommons/gists{/gist_id}","starred_url":"https://api.github.com/users/Harvard-University-iCommons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Harvard-University-iCommons/subscriptions","organizations_url":"https://api.github.com/users/Harvard-University-iCommons/orgs","repos_url":"https://api.github.com/users/Harvard-University-iCommons/repos","events_url":"https://api.github.com/users/Harvard-University-iCommons/events{/privacy}","received_events_url":"https://api.github.com/users/Harvard-University-iCommons/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools","description":"icf@hsph","fork":false,"url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools","forks_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/forks","keys_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/teams","hooks_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/hooks","issue_events_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/events{/number}","events_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/events","assignees_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/assignees{/user}","branches_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/branches{/branch}","tags_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/tags","blobs_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/statuses/{sha}","languages_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/languages","stargazers_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/stargazers","contributors_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/contributors","subscribers_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/subscribers","subscription_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/subscription","commits_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/comments/{number}","contents_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/contents/{+path}","compare_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/merges","archive_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/downloads","issues_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues{/number}","pulls_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls{/number}","milestones_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/milestones{/number}","notifications_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/labels{/name}","releases_url":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/releases{/id}","created_at":"2013-11-25T20:06:20Z","updated_at":"2014-11-24T18:11:17Z","pushed_at":"2014-12-01T21:01:08Z","git_url":"git://github.com/Harvard-University-iCommons/icommons_lti_tools.git","ssh_url":"git@github.com:Harvard-University-iCommons/icommons_lti_tools.git","clone_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools.git","svn_url":"https://github.com/Harvard-University-iCommons/icommons_lti_tools","homepage":"","size":7321,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132"},"html":{"href":"https://github.com/Harvard-University-iCommons/icommons_lti_tools/pull/132"},"issue":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/132"},"comments":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/issues/132/comments"},"review_comments":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132/comments"},"review_comment":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/pulls/132/commits"},"statuses":{"href":"https://api.github.com/repos/Harvard-University-iCommons/icommons_lti_tools/statuses/43455d5cbf2d716ac730d9cca6890d9eb1c8307f"}}}}