{"action":"created","comment":{"url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/comments/44097423","id":44097423,"diff_hunk":"@@ -0,0 +1,133 @@\n+import json\n+import logging\n+from django import forms\n+from django.http import HttpResponse, QueryDict\n+from django.views.generic.edit import FormView\n+\n+from guestbook.models import Greeting, Guestbook\n+\n+\n+class JSONResponseMixin(object):\n+\tdef render_to_response(self, context):\n+\t\treturn self.get_json_response(self.convert_context_to_json(context))\n+\n+\t@staticmethod\n+\tdef get_json_response(content, **http_response_kwargs):\n+\t\treturn HttpResponse(content, content_type='application/json', **http_response_kwargs)\n+\n+\t@staticmethod\n+\tdef convert_context_to_json(context):\n+\t\treturn json.dumps(context)\n+\n+class SignForm(forms.Form):\n+\tguestbook_name = forms.CharField(\n+\t\tlabel='Guestbook name',\n+\t\tmax_length=50,\n+\t\trequired = False\n+\t)\n+\tguestbook_mesage = forms.CharField(\n+\t\twidget=forms.Textarea,\n+\t\tlabel='Guestkook mesage',\n+\t\tmax_length=100\n+\t)\n+\n+\n+class GetListView(JSONResponseMixin, FormView):\n+\n+\tform_class = SignForm\n+\tdef get(self, request, *args, **kwargs):\n+\t\tguestbook_name = self.request.GET.get('guestbook_name',Guestbook.get_default_guestbook())\n+\t\tcount= 20\n+\t\turl_safe = self.request.GET.get('cursor')\n+\t\tlogging.info(url_safe)\n+\t\tgreetings, next_cursor, is_more = Greeting.get_greeting_with_cursor(\n+\t\t\turl_safe=url_safe,\n+\t\t\tguestbook_name=guestbook_name,\n+\t\t)\n+\t\tdata = {\n+\t\t\t\"guestbook_name\": guestbook_name,\n+\t\t\t\"greetings\": greetings,\n+\t\t\t\"more\": is_more,\n+\t\t\t\"next_cursor\": str(next_cursor.urlsafe()) if is_more else None\n+\t\t}\n+\t\treturn self.render_to_response(data)\n+\n+\tdef post(self, request, *args, **kwargs):\n+\t\ttry:\n+\t\t\tjson_object = json.loads(self.request.body)\n+\n+\t\texcept ValueError:\n+\t\t\tself.request.POST = QueryDict(self.request.body)\n+\t\telse:\n+\t\t\tself.request.POST = json_object\n+\t\tform_class = self.get_form_class()\n+\t\tform = self.get_form(form_class)\n+\t\tif not form.is_valid():\n+\t\t\treturn HttpResponse(status=400)","path":"djangobaseview/guestbook/api/restful.py","position":66,"original_position":66,"commit_id":"6ac7dffee58d35f22d803b30294064041aef11d9","original_commit_id":"6ac7dffee58d35f22d803b30294064041aef11d9","user":{"login":"phucnpm","id":7623464,"avatar_url":"https://avatars.githubusercontent.com/u/7623464?v=3","gravatar_id":"","url":"https://api.github.com/users/phucnpm","html_url":"https://github.com/phucnpm","followers_url":"https://api.github.com/users/phucnpm/followers","following_url":"https://api.github.com/users/phucnpm/following{/other_user}","gists_url":"https://api.github.com/users/phucnpm/gists{/gist_id}","starred_url":"https://api.github.com/users/phucnpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phucnpm/subscriptions","organizations_url":"https://api.github.com/users/phucnpm/orgs","repos_url":"https://api.github.com/users/phucnpm/repos","events_url":"https://api.github.com/users/phucnpm/events{/privacy}","received_events_url":"https://api.github.com/users/phucnpm/received_events","type":"User","site_admin":false},"body":"hãy tách phần xử lý thành 2 method `form_valid` & `form_invalid` cho rõ ràng theo design của django FormView \r\n```\r\nif form.is_valid()\r\n    return self.form_valid(form)\r\nelse \r\n    return self.form_invalid(form)\r\n```","created_at":"2015-11-06T02:23:56Z","updated_at":"2015-11-06T02:23:56Z","html_url":"https://github.com/asv-minhnv/guestbook/pull/15#discussion_r44097423","pull_request_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/comments/44097423"},"html":{"href":"https://github.com/asv-minhnv/guestbook/pull/15#discussion_r44097423"},"pull_request":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15","id":49802726,"html_url":"https://github.com/asv-minhnv/guestbook/pull/15","diff_url":"https://github.com/asv-minhnv/guestbook/pull/15.diff","patch_url":"https://github.com/asv-minhnv/guestbook/pull/15.patch","issue_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/15","number":15,"state":"open","locked":false,"title":"Feature/dojo guestbook","user":{"login":"asv-minhnv","id":14993477,"avatar_url":"https://avatars.githubusercontent.com/u/14993477?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-minhnv","html_url":"https://github.com/asv-minhnv","followers_url":"https://api.github.com/users/asv-minhnv/followers","following_url":"https://api.github.com/users/asv-minhnv/following{/other_user}","gists_url":"https://api.github.com/users/asv-minhnv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-minhnv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-minhnv/subscriptions","organizations_url":"https://api.github.com/users/asv-minhnv/orgs","repos_url":"https://api.github.com/users/asv-minhnv/repos","events_url":"https://api.github.com/users/asv-minhnv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-minhnv/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-05T09:59:12Z","updated_at":"2015-11-06T02:23:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"41a14359905df928386897059de8d4b08e405819","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15/commits","review_comments_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15/comments","review_comment_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/15/comments","statuses_url":"https://api.github.com/repos/asv-minhnv/guestbook/statuses/6ac7dffee58d35f22d803b30294064041aef11d9","head":{"label":"asv-minhnv:feature/dojo-guestbook","ref":"feature/dojo-guestbook","sha":"6ac7dffee58d35f22d803b30294064041aef11d9","user":{"login":"asv-minhnv","id":14993477,"avatar_url":"https://avatars.githubusercontent.com/u/14993477?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-minhnv","html_url":"https://github.com/asv-minhnv","followers_url":"https://api.github.com/users/asv-minhnv/followers","following_url":"https://api.github.com/users/asv-minhnv/following{/other_user}","gists_url":"https://api.github.com/users/asv-minhnv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-minhnv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-minhnv/subscriptions","organizations_url":"https://api.github.com/users/asv-minhnv/orgs","repos_url":"https://api.github.com/users/asv-minhnv/repos","events_url":"https://api.github.com/users/asv-minhnv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-minhnv/received_events","type":"User","site_admin":false},"repo":{"id":43740550,"name":"guestbook","full_name":"asv-minhnv/guestbook","owner":{"login":"asv-minhnv","id":14993477,"avatar_url":"https://avatars.githubusercontent.com/u/14993477?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-minhnv","html_url":"https://github.com/asv-minhnv","followers_url":"https://api.github.com/users/asv-minhnv/followers","following_url":"https://api.github.com/users/asv-minhnv/following{/other_user}","gists_url":"https://api.github.com/users/asv-minhnv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-minhnv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-minhnv/subscriptions","organizations_url":"https://api.github.com/users/asv-minhnv/orgs","repos_url":"https://api.github.com/users/asv-minhnv/repos","events_url":"https://api.github.com/users/asv-minhnv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-minhnv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/asv-minhnv/guestbook","description":"asv-minhnv guestbook","fork":false,"url":"https://api.github.com/repos/asv-minhnv/guestbook","forks_url":"https://api.github.com/repos/asv-minhnv/guestbook/forks","keys_url":"https://api.github.com/repos/asv-minhnv/guestbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asv-minhnv/guestbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asv-minhnv/guestbook/teams","hooks_url":"https://api.github.com/repos/asv-minhnv/guestbook/hooks","issue_events_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/events{/number}","events_url":"https://api.github.com/repos/asv-minhnv/guestbook/events","assignees_url":"https://api.github.com/repos/asv-minhnv/guestbook/assignees{/user}","branches_url":"https://api.github.com/repos/asv-minhnv/guestbook/branches{/branch}","tags_url":"https://api.github.com/repos/asv-minhnv/guestbook/tags","blobs_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asv-minhnv/guestbook/statuses/{sha}","languages_url":"https://api.github.com/repos/asv-minhnv/guestbook/languages","stargazers_url":"https://api.github.com/repos/asv-minhnv/guestbook/stargazers","contributors_url":"https://api.github.com/repos/asv-minhnv/guestbook/contributors","subscribers_url":"https://api.github.com/repos/asv-minhnv/guestbook/subscribers","subscription_url":"https://api.github.com/repos/asv-minhnv/guestbook/subscription","commits_url":"https://api.github.com/repos/asv-minhnv/guestbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/asv-minhnv/guestbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/asv-minhnv/guestbook/contents/{+path}","compare_url":"https://api.github.com/repos/asv-minhnv/guestbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asv-minhnv/guestbook/merges","archive_url":"https://api.github.com/repos/asv-minhnv/guestbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asv-minhnv/guestbook/downloads","issues_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues{/number}","pulls_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls{/number}","milestones_url":"https://api.github.com/repos/asv-minhnv/guestbook/milestones{/number}","notifications_url":"https://api.github.com/repos/asv-minhnv/guestbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asv-minhnv/guestbook/labels{/name}","releases_url":"https://api.github.com/repos/asv-minhnv/guestbook/releases{/id}","created_at":"2015-10-06T09:12:10Z","updated_at":"2015-10-06T09:12:10Z","pushed_at":"2015-11-05T10:56:27Z","git_url":"git://github.com/asv-minhnv/guestbook.git","ssh_url":"git@github.com:asv-minhnv/guestbook.git","clone_url":"https://github.com/asv-minhnv/guestbook.git","svn_url":"https://github.com/asv-minhnv/guestbook","homepage":null,"size":484,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"asv-minhnv:develop","ref":"develop","sha":"41a8a5b3a39917902029ad4731cc73ba10c79ac8","user":{"login":"asv-minhnv","id":14993477,"avatar_url":"https://avatars.githubusercontent.com/u/14993477?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-minhnv","html_url":"https://github.com/asv-minhnv","followers_url":"https://api.github.com/users/asv-minhnv/followers","following_url":"https://api.github.com/users/asv-minhnv/following{/other_user}","gists_url":"https://api.github.com/users/asv-minhnv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-minhnv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-minhnv/subscriptions","organizations_url":"https://api.github.com/users/asv-minhnv/orgs","repos_url":"https://api.github.com/users/asv-minhnv/repos","events_url":"https://api.github.com/users/asv-minhnv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-minhnv/received_events","type":"User","site_admin":false},"repo":{"id":43740550,"name":"guestbook","full_name":"asv-minhnv/guestbook","owner":{"login":"asv-minhnv","id":14993477,"avatar_url":"https://avatars.githubusercontent.com/u/14993477?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-minhnv","html_url":"https://github.com/asv-minhnv","followers_url":"https://api.github.com/users/asv-minhnv/followers","following_url":"https://api.github.com/users/asv-minhnv/following{/other_user}","gists_url":"https://api.github.com/users/asv-minhnv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-minhnv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-minhnv/subscriptions","organizations_url":"https://api.github.com/users/asv-minhnv/orgs","repos_url":"https://api.github.com/users/asv-minhnv/repos","events_url":"https://api.github.com/users/asv-minhnv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-minhnv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/asv-minhnv/guestbook","description":"asv-minhnv guestbook","fork":false,"url":"https://api.github.com/repos/asv-minhnv/guestbook","forks_url":"https://api.github.com/repos/asv-minhnv/guestbook/forks","keys_url":"https://api.github.com/repos/asv-minhnv/guestbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asv-minhnv/guestbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asv-minhnv/guestbook/teams","hooks_url":"https://api.github.com/repos/asv-minhnv/guestbook/hooks","issue_events_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/events{/number}","events_url":"https://api.github.com/repos/asv-minhnv/guestbook/events","assignees_url":"https://api.github.com/repos/asv-minhnv/guestbook/assignees{/user}","branches_url":"https://api.github.com/repos/asv-minhnv/guestbook/branches{/branch}","tags_url":"https://api.github.com/repos/asv-minhnv/guestbook/tags","blobs_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asv-minhnv/guestbook/statuses/{sha}","languages_url":"https://api.github.com/repos/asv-minhnv/guestbook/languages","stargazers_url":"https://api.github.com/repos/asv-minhnv/guestbook/stargazers","contributors_url":"https://api.github.com/repos/asv-minhnv/guestbook/contributors","subscribers_url":"https://api.github.com/repos/asv-minhnv/guestbook/subscribers","subscription_url":"https://api.github.com/repos/asv-minhnv/guestbook/subscription","commits_url":"https://api.github.com/repos/asv-minhnv/guestbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/asv-minhnv/guestbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/asv-minhnv/guestbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/asv-minhnv/guestbook/contents/{+path}","compare_url":"https://api.github.com/repos/asv-minhnv/guestbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asv-minhnv/guestbook/merges","archive_url":"https://api.github.com/repos/asv-minhnv/guestbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asv-minhnv/guestbook/downloads","issues_url":"https://api.github.com/repos/asv-minhnv/guestbook/issues{/number}","pulls_url":"https://api.github.com/repos/asv-minhnv/guestbook/pulls{/number}","milestones_url":"https://api.github.com/repos/asv-minhnv/guestbook/milestones{/number}","notifications_url":"https://api.github.com/repos/asv-minhnv/guestbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asv-minhnv/guestbook/labels{/name}","releases_url":"https://api.github.com/repos/asv-minhnv/guestbook/releases{/id}","created_at":"2015-10-06T09:12:10Z","updated_at":"2015-10-06T09:12:10Z","pushed_at":"2015-11-05T10:56:27Z","git_url":"git://github.com/asv-minhnv/guestbook.git","ssh_url":"git@github.com:asv-minhnv/guestbook.git","clone_url":"https://github.com/asv-minhnv/guestbook.git","svn_url":"https://github.com/asv-minhnv/guestbook","homepage":null,"size":484,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15"},"html":{"href":"https://github.com/asv-minhnv/guestbook/pull/15"},"issue":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/issues/15"},"comments":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/asv-minhnv/guestbook/statuses/6ac7dffee58d35f22d803b30294064041aef11d9"}}}}