{"action":"created","comment":{"url":"https://api.github.com/repos/datamade/committee-oversight/pulls/comments/227881496","pull_request_review_id":168008748,"id":227881496,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNzg4MTQ5Ng==","diff_hunk":"@@ -1,3 +1,160 @@\n+import re\n+import threading\n+import requests\n+from os.path import splitext\n+from urllib.parse import urlparse\n+\n+from django.urls import reverse_lazy\n from django.shortcuts import render\n+from django.views.generic.edit import CreateView\n+from django.views.generic.detail import DetailView\n+from django.views.generic import ListView, DeleteView, TemplateView\n+\n+from opencivicdata.legislative.models import Event, EventParticipant, EventDocument, EventDocumentLink\n+from opencivicdata.core.models import Organization\n+from .forms import EventForm, CommitteeForm, CommitteeMemberForm, WitnessForm, TranscriptForm\n+\n+class Success(TemplateView):\n+    template_name = 'success.html'\n+\n+class EventView(DetailView):\n+    model = Event\n+    template_name = 'detail.html'\n+\n+    def get_context_data(self, **kwargs):\n+        context = super().get_context_data(**kwargs)\n+        return context\n+\n+# given a url string, find the file extension at the end\n+def get_ext(url):\n+    path = urlparse(url).path\n+    ext = splitext(path)[1]\n+    return ext\n+\n+# archive a url string\n+def archive_url(url):\n+    wayback_host = 'http://web.archive.org'\n+    save_url = '{0}/save/{1}'.format(wayback_host, url)\n+    archived = requests.get(save_url)\n+    archive_url = '{0}{1}'.format(wayback_host, archived.headers['Content-Location'])\n+    return archive_url\n+\n+class EventCreate(TemplateView):\n+    template_name = \"create.html\"\n+\n+    def get_context_data(self, **kwargs):\n+        context = super().get_context_data(**kwargs)\n+\n+        context['event_form'] = EventForm(prefix=\"event\")\n+        context['committee_form'] = CommitteeForm(prefix=\"committee\")\n+        context['committeemember_form'] = CommitteeMemberForm(prefix=\"committeemember\")\n+        context['witness_form'] = WitnessForm(prefix=\"witness\")\n+        context['transcript_form'] = TranscriptForm(prefix=\"transcript\")\n+\n+        return context\n+\n+    def post(self, request, **kwargs):\n+        event_form = EventForm(request.POST, prefix=\"event\")\n+        committee_form = CommitteeForm(request.POST, prefix=\"committee\")\n+        committeemember_form = CommitteeMemberForm(request.POST, prefix=\"committeemember\")\n+        witness_form = WitnessForm(request.POST, prefix=\"witness\")\n+        transcript_form = TranscriptForm(request.POST, prefix=\"transcript\")\n+\n+        print(\"Checking if forms are valid...\")\n+\n+        forms_valid = [event_form.is_valid(), committee_form.is_valid(),\n+                       committeemember_form.is_valid(), witness_form.is_valid(),\n+                       transcript_form.is_valid()]\n+\n+        if all(forms_valid):\n+            print(\"All forms valid! Saving...\")\n+\n+            # save event\n+            event = event_form.save()\n+\n+            # find and create committees as EventParticipants\n+            committees = committee_form.cleaned_data['name']\n+\n+            for committee in committees:\n+                name = committee.name\n+                event = event_form.save(commit=False)\n+                organization = Organization.objects.get(id=committee.id)\n+                entity_type = \"organization\"\n+                new_committee = EventParticipant(name=name, event=event, organization=organization, entity_type=entity_type)\n+                new_committee.save()\n+\n+            # find and create committee members as EventParticipants\n+            committeemembers = committeemember_form.cleaned_data['name'].split(\",\")\n+\n+            for committeemember in committeemembers:\n+                if committeemember == '' or committeemember.isspace():\n+                    pass\n+                else:\n+                    name = committeemember.strip()\n+                    entity_type = \"committee member\"\n+                    new_committeemember = EventParticipant(name=name, event=event, entity_type=entity_type)\n+                    new_committeemember.save()\n+\n+            # find and create witnesses as EventParticipants\n+            witnesses = witness_form.cleaned_data['name'].split(\",\")\n+\n+            for witness in witnesses:\n+                if witness == '' or witness.isspace():\n+                    pass\n+                else:\n+                    name = witness.strip()\n+                    entity_type = \"person\"\n+                    new_witness = EventParticipant(name=name, event=event, entity_type=entity_type)\n+                    new_witness.save()\n+\n+            # if form includes a transcript URL create EventDocument with original and archived url\n+            transcript_url = transcript_form.cleaned_data['url']\n+\n+            if transcript_url == '' or witness.isspace():\n+                pass\n+            else:\n+                note=\"transcript\"\n+                new_document = EventDocument(note=note, event=event)\n+                new_document.save()\n+\n+                archived_transcript_url = archive_url(transcript_url)\n+                print(archived_transcript_url)\n+\n+                ext = get_ext(transcript_url)\n+                if ext.lower() == '.pdf':","path":"committeeoversightapp/views.py","position":124,"original_position":124,"commit_id":"1a99f669e69d6e314ea3cff728c0631e1f180cd4","original_commit_id":"1a99f669e69d6e314ea3cff728c0631e1f180cd4","user":{"login":"reginafcompton","id":13078679,"node_id":"MDQ6VXNlcjEzMDc4Njc5","avatar_url":"https://avatars1.githubusercontent.com/u/13078679?v=4","gravatar_id":"","url":"https://api.github.com/users/reginafcompton","html_url":"https://github.com/reginafcompton","followers_url":"https://api.github.com/users/reginafcompton/followers","following_url":"https://api.github.com/users/reginafcompton/following{/other_user}","gists_url":"https://api.github.com/users/reginafcompton/gists{/gist_id}","starred_url":"https://api.github.com/users/reginafcompton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reginafcompton/subscriptions","organizations_url":"https://api.github.com/users/reginafcompton/orgs","repos_url":"https://api.github.com/users/reginafcompton/repos","events_url":"https://api.github.com/users/reginafcompton/events{/privacy}","received_events_url":"https://api.github.com/users/reginafcompton/received_events","type":"User","site_admin":false},"body":"You could make this a tad more DRY. One way that comes to mind: a mapping of the extensions, rather than the successive IF/ELSE statements. So, something like: \r\n\r\n```\r\nextensions = {'.pdf': 'application/pdf', '.htm': 'text/html'} \r\n...\r\nmedia_type=extensions[ext.lower()]\r\n```","created_at":"2018-10-24T17:14:26Z","updated_at":"2018-10-24T17:17:57Z","html_url":"https://github.com/datamade/committee-oversight/pull/5#discussion_r227881496","pull_request_url":"https://api.github.com/repos/datamade/committee-oversight/pulls/5","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/comments/227881496"},"html":{"href":"https://github.com/datamade/committee-oversight/pull/5#discussion_r227881496"},"pull_request":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/datamade/committee-oversight/pulls/5","id":223686943,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIzNjg2OTQz","html_url":"https://github.com/datamade/committee-oversight/pull/5","diff_url":"https://github.com/datamade/committee-oversight/pull/5.diff","patch_url":"https://github.com/datamade/committee-oversight/pull/5.patch","issue_url":"https://api.github.com/repos/datamade/committee-oversight/issues/5","number":5,"state":"open","locked":false,"title":"Form setup","user":{"login":"beamalsky","id":1094243,"node_id":"MDQ6VXNlcjEwOTQyNDM=","avatar_url":"https://avatars1.githubusercontent.com/u/1094243?v=4","gravatar_id":"","url":"https://api.github.com/users/beamalsky","html_url":"https://github.com/beamalsky","followers_url":"https://api.github.com/users/beamalsky/followers","following_url":"https://api.github.com/users/beamalsky/following{/other_user}","gists_url":"https://api.github.com/users/beamalsky/gists{/gist_id}","starred_url":"https://api.github.com/users/beamalsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beamalsky/subscriptions","organizations_url":"https://api.github.com/users/beamalsky/orgs","repos_url":"https://api.github.com/users/beamalsky/repos","events_url":"https://api.github.com/users/beamalsky/events{/privacy}","received_events_url":"https://api.github.com/users/beamalsky/received_events","type":"User","site_admin":false},"body":"Questions for Lugar logged in #3. Next steps: better validation, some tests would be very nice!\r\n\r\nIt occurred to me midway through this that maybe this should be in the admin interface. LMK if you feel that way too.","created_at":"2018-10-17T17:18:13Z","updated_at":"2018-10-24T17:17:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3286a0683922646e4ade880b85305a5592cb6a4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/datamade/committee-oversight/pulls/5/commits","review_comments_url":"https://api.github.com/repos/datamade/committee-oversight/pulls/5/comments","review_comment_url":"https://api.github.com/repos/datamade/committee-oversight/pulls/comments{/number}","comments_url":"https://api.github.com/repos/datamade/committee-oversight/issues/5/comments","statuses_url":"https://api.github.com/repos/datamade/committee-oversight/statuses/1a99f669e69d6e314ea3cff728c0631e1f180cd4","head":{"label":"datamade:form-setup","ref":"form-setup","sha":"1a99f669e69d6e314ea3cff728c0631e1f180cd4","user":{"login":"datamade","id":3723931,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MjM5MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/3723931?v=4","gravatar_id":"","url":"https://api.github.com/users/datamade","html_url":"https://github.com/datamade","followers_url":"https://api.github.com/users/datamade/followers","following_url":"https://api.github.com/users/datamade/following{/other_user}","gists_url":"https://api.github.com/users/datamade/gists{/gist_id}","starred_url":"https://api.github.com/users/datamade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datamade/subscriptions","organizations_url":"https://api.github.com/users/datamade/orgs","repos_url":"https://api.github.com/users/datamade/repos","events_url":"https://api.github.com/users/datamade/events{/privacy}","received_events_url":"https://api.github.com/users/datamade/received_events","type":"Organization","site_admin":false},"repo":{"id":151442536,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE0NDI1MzY=","name":"committee-oversight","full_name":"datamade/committee-oversight","private":false,"owner":{"login":"datamade","id":3723931,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MjM5MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/3723931?v=4","gravatar_id":"","url":"https://api.github.com/users/datamade","html_url":"https://github.com/datamade","followers_url":"https://api.github.com/users/datamade/followers","following_url":"https://api.github.com/users/datamade/following{/other_user}","gists_url":"https://api.github.com/users/datamade/gists{/gist_id}","starred_url":"https://api.github.com/users/datamade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datamade/subscriptions","organizations_url":"https://api.github.com/users/datamade/orgs","repos_url":"https://api.github.com/users/datamade/repos","events_url":"https://api.github.com/users/datamade/events{/privacy}","received_events_url":"https://api.github.com/users/datamade/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/datamade/committee-oversight","description":"⚖️ Committee oversight map coding project for the Lugar Center","fork":false,"url":"https://api.github.com/repos/datamade/committee-oversight","forks_url":"https://api.github.com/repos/datamade/committee-oversight/forks","keys_url":"https://api.github.com/repos/datamade/committee-oversight/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datamade/committee-oversight/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datamade/committee-oversight/teams","hooks_url":"https://api.github.com/repos/datamade/committee-oversight/hooks","issue_events_url":"https://api.github.com/repos/datamade/committee-oversight/issues/events{/number}","events_url":"https://api.github.com/repos/datamade/committee-oversight/events","assignees_url":"https://api.github.com/repos/datamade/committee-oversight/assignees{/user}","branches_url":"https://api.github.com/repos/datamade/committee-oversight/branches{/branch}","tags_url":"https://api.github.com/repos/datamade/committee-oversight/tags","blobs_url":"https://api.github.com/repos/datamade/committee-oversight/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datamade/committee-oversight/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datamade/committee-oversight/git/refs{/sha}","trees_url":"https://api.github.com/repos/datamade/committee-oversight/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datamade/committee-oversight/statuses/{sha}","languages_url":"https://api.github.com/repos/datamade/committee-oversight/languages","stargazers_url":"https://api.github.com/repos/datamade/committee-oversight/stargazers","contributors_url":"https://api.github.com/repos/datamade/committee-oversight/contributors","subscribers_url":"https://api.github.com/repos/datamade/committee-oversight/subscribers","subscription_url":"https://api.github.com/repos/datamade/committee-oversight/subscription","commits_url":"https://api.github.com/repos/datamade/committee-oversight/commits{/sha}","git_commits_url":"https://api.github.com/repos/datamade/committee-oversight/git/commits{/sha}","comments_url":"https://api.github.com/repos/datamade/committee-oversight/comments{/number}","issue_comment_url":"https://api.github.com/repos/datamade/committee-oversight/issues/comments{/number}","contents_url":"https://api.github.com/repos/datamade/committee-oversight/contents/{+path}","compare_url":"https://api.github.com/repos/datamade/committee-oversight/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datamade/committee-oversight/merges","archive_url":"https://api.github.com/repos/datamade/committee-oversight/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datamade/committee-oversight/downloads","issues_url":"https://api.github.com/repos/datamade/committee-oversight/issues{/number}","pulls_url":"https://api.github.com/repos/datamade/committee-oversight/pulls{/number}","milestones_url":"https://api.github.com/repos/datamade/committee-oversight/milestones{/number}","notifications_url":"https://api.github.com/repos/datamade/committee-oversight/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datamade/committee-oversight/labels{/name}","releases_url":"https://api.github.com/repos/datamade/committee-oversight/releases{/id}","deployments_url":"https://api.github.com/repos/datamade/committee-oversight/deployments","created_at":"2018-10-03T16:15:48Z","updated_at":"2018-10-08T20:54:47Z","pushed_at":"2018-10-24T16:42:12Z","git_url":"git://github.com/datamade/committee-oversight.git","ssh_url":"git@github.com:datamade/committee-oversight.git","clone_url":"https://github.com/datamade/committee-oversight.git","svn_url":"https://github.com/datamade/committee-oversight","homepage":"","size":536,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"datamade:master","ref":"master","sha":"f41f6c553339826f7dc1028547f8cf3d64bd4c82","user":{"login":"datamade","id":3723931,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MjM5MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/3723931?v=4","gravatar_id":"","url":"https://api.github.com/users/datamade","html_url":"https://github.com/datamade","followers_url":"https://api.github.com/users/datamade/followers","following_url":"https://api.github.com/users/datamade/following{/other_user}","gists_url":"https://api.github.com/users/datamade/gists{/gist_id}","starred_url":"https://api.github.com/users/datamade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datamade/subscriptions","organizations_url":"https://api.github.com/users/datamade/orgs","repos_url":"https://api.github.com/users/datamade/repos","events_url":"https://api.github.com/users/datamade/events{/privacy}","received_events_url":"https://api.github.com/users/datamade/received_events","type":"Organization","site_admin":false},"repo":{"id":151442536,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE0NDI1MzY=","name":"committee-oversight","full_name":"datamade/committee-oversight","private":false,"owner":{"login":"datamade","id":3723931,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3MjM5MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/3723931?v=4","gravatar_id":"","url":"https://api.github.com/users/datamade","html_url":"https://github.com/datamade","followers_url":"https://api.github.com/users/datamade/followers","following_url":"https://api.github.com/users/datamade/following{/other_user}","gists_url":"https://api.github.com/users/datamade/gists{/gist_id}","starred_url":"https://api.github.com/users/datamade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datamade/subscriptions","organizations_url":"https://api.github.com/users/datamade/orgs","repos_url":"https://api.github.com/users/datamade/repos","events_url":"https://api.github.com/users/datamade/events{/privacy}","received_events_url":"https://api.github.com/users/datamade/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/datamade/committee-oversight","description":"⚖️ Committee oversight map coding project for the Lugar Center","fork":false,"url":"https://api.github.com/repos/datamade/committee-oversight","forks_url":"https://api.github.com/repos/datamade/committee-oversight/forks","keys_url":"https://api.github.com/repos/datamade/committee-oversight/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datamade/committee-oversight/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datamade/committee-oversight/teams","hooks_url":"https://api.github.com/repos/datamade/committee-oversight/hooks","issue_events_url":"https://api.github.com/repos/datamade/committee-oversight/issues/events{/number}","events_url":"https://api.github.com/repos/datamade/committee-oversight/events","assignees_url":"https://api.github.com/repos/datamade/committee-oversight/assignees{/user}","branches_url":"https://api.github.com/repos/datamade/committee-oversight/branches{/branch}","tags_url":"https://api.github.com/repos/datamade/committee-oversight/tags","blobs_url":"https://api.github.com/repos/datamade/committee-oversight/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datamade/committee-oversight/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datamade/committee-oversight/git/refs{/sha}","trees_url":"https://api.github.com/repos/datamade/committee-oversight/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datamade/committee-oversight/statuses/{sha}","languages_url":"https://api.github.com/repos/datamade/committee-oversight/languages","stargazers_url":"https://api.github.com/repos/datamade/committee-oversight/stargazers","contributors_url":"https://api.github.com/repos/datamade/committee-oversight/contributors","subscribers_url":"https://api.github.com/repos/datamade/committee-oversight/subscribers","subscription_url":"https://api.github.com/repos/datamade/committee-oversight/subscription","commits_url":"https://api.github.com/repos/datamade/committee-oversight/commits{/sha}","git_commits_url":"https://api.github.com/repos/datamade/committee-oversight/git/commits{/sha}","comments_url":"https://api.github.com/repos/datamade/committee-oversight/comments{/number}","issue_comment_url":"https://api.github.com/repos/datamade/committee-oversight/issues/comments{/number}","contents_url":"https://api.github.com/repos/datamade/committee-oversight/contents/{+path}","compare_url":"https://api.github.com/repos/datamade/committee-oversight/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datamade/committee-oversight/merges","archive_url":"https://api.github.com/repos/datamade/committee-oversight/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datamade/committee-oversight/downloads","issues_url":"https://api.github.com/repos/datamade/committee-oversight/issues{/number}","pulls_url":"https://api.github.com/repos/datamade/committee-oversight/pulls{/number}","milestones_url":"https://api.github.com/repos/datamade/committee-oversight/milestones{/number}","notifications_url":"https://api.github.com/repos/datamade/committee-oversight/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datamade/committee-oversight/labels{/name}","releases_url":"https://api.github.com/repos/datamade/committee-oversight/releases{/id}","deployments_url":"https://api.github.com/repos/datamade/committee-oversight/deployments","created_at":"2018-10-03T16:15:48Z","updated_at":"2018-10-08T20:54:47Z","pushed_at":"2018-10-24T16:42:12Z","git_url":"git://github.com/datamade/committee-oversight.git","ssh_url":"git@github.com:datamade/committee-oversight.git","clone_url":"https://github.com/datamade/committee-oversight.git","svn_url":"https://github.com/datamade/committee-oversight","homepage":"","size":536,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/5"},"html":{"href":"https://github.com/datamade/committee-oversight/pull/5"},"issue":{"href":"https://api.github.com/repos/datamade/committee-oversight/issues/5"},"comments":{"href":"https://api.github.com/repos/datamade/committee-oversight/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/datamade/committee-oversight/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/datamade/committee-oversight/statuses/1a99f669e69d6e314ea3cff728c0631e1f180cd4"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"reginafcompton"}}