{"action":"created","comment":{"url":"https://api.github.com/repos/champs794/codeguild/pulls/comments/78031216","id":78031216,"diff_hunk":"@@ -0,0 +1,89 @@\n+\"\"\" Validation and Data Storage/Retrieval \"\"\"\n+\n+from django.http import QueryDict\n+from typing import Dict\n+import uuid\n+from . import models\n+\n+\n+# VALIDATION ###########################################################################################################\n+def get_working_data(post_data) -> Dict:\n+    \"\"\" Amend default data with POST data\n+\n+    >>> test = get_working_data(QueryDict(''))\n+    >>> test['is_post'] == False\n+    True\n+    >>> test = get_working_data(QueryDict('foo=bar'))\n+    >>> test['is_post'] == True\n+    True\n+    >>> test = get_working_data(QueryDict('setup=A&punch=B'))\n+    >>> test['setup'] == 'A' and test['punch'] == 'B' and len(test['messages']) == 0\n+    True\n+    \"\"\"\n+    working = {\n+        'setup': '',\n+        'punch': '',\n+        'is_post': False,\n+    }\n+    working.update(post_data.dict())\n+    working['messages'] = []\n+    working['is_post'] = len(post_data) > 0\n+    return working\n+\n+\n+def validate_joke(post_data) -> Dict:\n+    \"\"\" Validate for non-blank setup & punchline, generate messages\n+\n+    >>> test = validate_joke(QueryDict('setup=foo&punch=bar'))\n+    >>> test['valid'] == True\n+    True\n+    >>> test = validate_joke(QueryDict('setup=foo&punch='))\n+    >>> test['valid'] == False and len(test['messages']) == 1\n+    True\n+    \"\"\"\n+    validation = get_working_data(post_data)\n+    if validation['is_post']:\n+        validation['messages'] = [\n+            'No {}line'.format(key)\n+            for key in ['setup ', 'punch'] if len(validation[key.strip()]) == 0\n+        ]\n+\n+    # could be other uses for messages, but not today.\n+    validation['valid'] = len(validation['messages']) == 0\n+\n+    return validation\n+\n+\n+# DATA MODEL ###########################################################################################################\n+def get_jokes() -> Dict:\n+    \"\"\" Return all jokes\n+\n+    >>> len(get_jokes()) == len(models.all_jokes)\n+    True\n+    \"\"\"\n+    return models.all_jokes\n+\n+\n+def add_joke(setup: str, punchline: str) -> None:\n+    \"\"\" Add a joke to the database\n+\n+    >>> prev_count = len(models.all_jokes)\n+    >>> add_joke('foo?', 'bar.')\n+    >>> len(models.all_jokes) - prev_count == 1\n+    True\n+    \"\"\"\n+    joke_id = str(uuid.uuid4())\n+    models.all_jokes[joke_id] = {\n+        'setup': setup,\n+        'punch': punchline\n+    }","path":"practice/jokes/jokes/logic.py","position":79,"original_position":79,"commit_id":"47965b5c2deae911b17b70a4df5b8a306d858890","original_commit_id":"47965b5c2deae911b17b70a4df5b8a306d858890","user":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"body":"Very well, but FWIW this pull request and code is older than the note.","created_at":"2016-09-08T15:35:32Z","updated_at":"2016-09-08T15:35:32Z","html_url":"https://github.com/champs794/codeguild/pull/19#discussion_r78031216","pull_request_url":"https://api.github.com/repos/champs794/codeguild/pulls/19","_links":{"self":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/comments/78031216"},"html":{"href":"https://github.com/champs794/codeguild/pull/19#discussion_r78031216"},"pull_request":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/19"}}},"pull_request":{"url":"https://api.github.com/repos/champs794/codeguild/pulls/19","id":83352046,"html_url":"https://github.com/champs794/codeguild/pull/19","diff_url":"https://github.com/champs794/codeguild/pull/19.diff","patch_url":"https://github.com/champs794/codeguild/pull/19.patch","issue_url":"https://api.github.com/repos/champs794/codeguild/issues/19","number":19,"state":"open","locked":false,"title":"Jokes","user":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"body":"\"Hold up! I've got jokes, too!\"","created_at":"2016-08-30T21:37:07Z","updated_at":"2016-09-08T15:35:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3659e06d6c7b2e0406254b9f12a8045caff6972","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/champs794/codeguild/pulls/19/commits","review_comments_url":"https://api.github.com/repos/champs794/codeguild/pulls/19/comments","review_comment_url":"https://api.github.com/repos/champs794/codeguild/pulls/comments{/number}","comments_url":"https://api.github.com/repos/champs794/codeguild/issues/19/comments","statuses_url":"https://api.github.com/repos/champs794/codeguild/statuses/47965b5c2deae911b17b70a4df5b8a306d858890","head":{"label":"champs794:jokes","ref":"jokes","sha":"47965b5c2deae911b17b70a4df5b8a306d858890","user":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"repo":{"id":62911469,"name":"codeguild","full_name":"champs794/codeguild","owner":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/champs794/codeguild","description":null,"fork":false,"url":"https://api.github.com/repos/champs794/codeguild","forks_url":"https://api.github.com/repos/champs794/codeguild/forks","keys_url":"https://api.github.com/repos/champs794/codeguild/keys{/key_id}","collaborators_url":"https://api.github.com/repos/champs794/codeguild/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/champs794/codeguild/teams","hooks_url":"https://api.github.com/repos/champs794/codeguild/hooks","issue_events_url":"https://api.github.com/repos/champs794/codeguild/issues/events{/number}","events_url":"https://api.github.com/repos/champs794/codeguild/events","assignees_url":"https://api.github.com/repos/champs794/codeguild/assignees{/user}","branches_url":"https://api.github.com/repos/champs794/codeguild/branches{/branch}","tags_url":"https://api.github.com/repos/champs794/codeguild/tags","blobs_url":"https://api.github.com/repos/champs794/codeguild/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/champs794/codeguild/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/champs794/codeguild/git/refs{/sha}","trees_url":"https://api.github.com/repos/champs794/codeguild/git/trees{/sha}","statuses_url":"https://api.github.com/repos/champs794/codeguild/statuses/{sha}","languages_url":"https://api.github.com/repos/champs794/codeguild/languages","stargazers_url":"https://api.github.com/repos/champs794/codeguild/stargazers","contributors_url":"https://api.github.com/repos/champs794/codeguild/contributors","subscribers_url":"https://api.github.com/repos/champs794/codeguild/subscribers","subscription_url":"https://api.github.com/repos/champs794/codeguild/subscription","commits_url":"https://api.github.com/repos/champs794/codeguild/commits{/sha}","git_commits_url":"https://api.github.com/repos/champs794/codeguild/git/commits{/sha}","comments_url":"https://api.github.com/repos/champs794/codeguild/comments{/number}","issue_comment_url":"https://api.github.com/repos/champs794/codeguild/issues/comments{/number}","contents_url":"https://api.github.com/repos/champs794/codeguild/contents/{+path}","compare_url":"https://api.github.com/repos/champs794/codeguild/compare/{base}...{head}","merges_url":"https://api.github.com/repos/champs794/codeguild/merges","archive_url":"https://api.github.com/repos/champs794/codeguild/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/champs794/codeguild/downloads","issues_url":"https://api.github.com/repos/champs794/codeguild/issues{/number}","pulls_url":"https://api.github.com/repos/champs794/codeguild/pulls{/number}","milestones_url":"https://api.github.com/repos/champs794/codeguild/milestones{/number}","notifications_url":"https://api.github.com/repos/champs794/codeguild/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/champs794/codeguild/labels{/name}","releases_url":"https://api.github.com/repos/champs794/codeguild/releases{/id}","deployments_url":"https://api.github.com/repos/champs794/codeguild/deployments","created_at":"2016-07-08T19:09:49Z","updated_at":"2016-07-08T19:11:27Z","pushed_at":"2016-09-07T22:44:19Z","git_url":"git://github.com/champs794/codeguild.git","ssh_url":"git@github.com:champs794/codeguild.git","clone_url":"https://github.com/champs794/codeguild.git","svn_url":"https://github.com/champs794/codeguild","homepage":null,"size":288,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"champs794:master","ref":"master","sha":"5281ad692d285be9c6f167e11dac9ff36650d9fb","user":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"repo":{"id":62911469,"name":"codeguild","full_name":"champs794/codeguild","owner":{"login":"champs794","id":1580633,"avatar_url":"https://avatars.githubusercontent.com/u/1580633?v=3","gravatar_id":"","url":"https://api.github.com/users/champs794","html_url":"https://github.com/champs794","followers_url":"https://api.github.com/users/champs794/followers","following_url":"https://api.github.com/users/champs794/following{/other_user}","gists_url":"https://api.github.com/users/champs794/gists{/gist_id}","starred_url":"https://api.github.com/users/champs794/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/champs794/subscriptions","organizations_url":"https://api.github.com/users/champs794/orgs","repos_url":"https://api.github.com/users/champs794/repos","events_url":"https://api.github.com/users/champs794/events{/privacy}","received_events_url":"https://api.github.com/users/champs794/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/champs794/codeguild","description":null,"fork":false,"url":"https://api.github.com/repos/champs794/codeguild","forks_url":"https://api.github.com/repos/champs794/codeguild/forks","keys_url":"https://api.github.com/repos/champs794/codeguild/keys{/key_id}","collaborators_url":"https://api.github.com/repos/champs794/codeguild/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/champs794/codeguild/teams","hooks_url":"https://api.github.com/repos/champs794/codeguild/hooks","issue_events_url":"https://api.github.com/repos/champs794/codeguild/issues/events{/number}","events_url":"https://api.github.com/repos/champs794/codeguild/events","assignees_url":"https://api.github.com/repos/champs794/codeguild/assignees{/user}","branches_url":"https://api.github.com/repos/champs794/codeguild/branches{/branch}","tags_url":"https://api.github.com/repos/champs794/codeguild/tags","blobs_url":"https://api.github.com/repos/champs794/codeguild/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/champs794/codeguild/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/champs794/codeguild/git/refs{/sha}","trees_url":"https://api.github.com/repos/champs794/codeguild/git/trees{/sha}","statuses_url":"https://api.github.com/repos/champs794/codeguild/statuses/{sha}","languages_url":"https://api.github.com/repos/champs794/codeguild/languages","stargazers_url":"https://api.github.com/repos/champs794/codeguild/stargazers","contributors_url":"https://api.github.com/repos/champs794/codeguild/contributors","subscribers_url":"https://api.github.com/repos/champs794/codeguild/subscribers","subscription_url":"https://api.github.com/repos/champs794/codeguild/subscription","commits_url":"https://api.github.com/repos/champs794/codeguild/commits{/sha}","git_commits_url":"https://api.github.com/repos/champs794/codeguild/git/commits{/sha}","comments_url":"https://api.github.com/repos/champs794/codeguild/comments{/number}","issue_comment_url":"https://api.github.com/repos/champs794/codeguild/issues/comments{/number}","contents_url":"https://api.github.com/repos/champs794/codeguild/contents/{+path}","compare_url":"https://api.github.com/repos/champs794/codeguild/compare/{base}...{head}","merges_url":"https://api.github.com/repos/champs794/codeguild/merges","archive_url":"https://api.github.com/repos/champs794/codeguild/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/champs794/codeguild/downloads","issues_url":"https://api.github.com/repos/champs794/codeguild/issues{/number}","pulls_url":"https://api.github.com/repos/champs794/codeguild/pulls{/number}","milestones_url":"https://api.github.com/repos/champs794/codeguild/milestones{/number}","notifications_url":"https://api.github.com/repos/champs794/codeguild/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/champs794/codeguild/labels{/name}","releases_url":"https://api.github.com/repos/champs794/codeguild/releases{/id}","deployments_url":"https://api.github.com/repos/champs794/codeguild/deployments","created_at":"2016-07-08T19:09:49Z","updated_at":"2016-07-08T19:11:27Z","pushed_at":"2016-09-07T22:44:19Z","git_url":"git://github.com/champs794/codeguild.git","ssh_url":"git@github.com:champs794/codeguild.git","clone_url":"https://github.com/champs794/codeguild.git","svn_url":"https://github.com/champs794/codeguild","homepage":null,"size":288,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/19"},"html":{"href":"https://github.com/champs794/codeguild/pull/19"},"issue":{"href":"https://api.github.com/repos/champs794/codeguild/issues/19"},"comments":{"href":"https://api.github.com/repos/champs794/codeguild/issues/19/comments"},"review_comments":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/19/comments"},"review_comment":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/champs794/codeguild/pulls/19/commits"},"statuses":{"href":"https://api.github.com/repos/champs794/codeguild/statuses/47965b5c2deae911b17b70a4df5b8a306d858890"}}}}
{"actor":{"display_login":"champs794"}}