{"action":"created","comment":{"url":"https://api.github.com/repos/dendgau/guestbook/pulls/comments/26203561","id":26203561,"diff_hunk":"@@ -0,0 +1,180 @@\n+# -*- coding: utf-8 -*-\n+\n+import time\n+\n+from google.appengine.api import users\n+from google.appengine.ext import ndb\n+\n+from django import forms\n+from django.contrib import messages\n+from django.views.generic.edit import FormView, FormMixin\n+from django.views.generic.base import TemplateView\n+\n+from guestbook.models import Greeting, DEFAULT_GUESTBOOK_NAME\n+\n+\n+class SignForm(forms.Form):\n+    guestbook_name = forms.CharField(\n+        label=\"Guest_book Name\",\n+        max_length=20,\n+        required=True,\n+        widget=forms.TextInput()\n+    )\n+    greeting_message = forms.CharField(\n+        label=\"Greeting Massage\",\n+        max_length=50,\n+        required=True,\n+        widget=forms.Textarea()\n+    )\n+\n+\n+class DeleteForm(forms.Form):\n+    guestbook_name = forms.CharField(\n+        label=\"Guestbook Name\",\n+        max_length=20,\n+        widget=forms.HiddenInput()\n+    )\n+    greeting_id = forms.CharField(\n+        label=\"Greeting ID\",\n+        max_length=50,\n+        widget=forms.HiddenInput()\n+    )\n+\n+\n+class SignView(FormView):\n+    form_class = SignForm\n+    template_name = \"greetingform.html\"\n+    success_url = 'sign'\n+    messages = {\n+        \"greeting_create\": {\n+            \"level\": messages.SUCCESS,\n+            \"text\": \"Greeting create success.\"\n+        },\n+    }\n+    \n+    def get_initial(self):\n+        initial = super(SignView, self).get_initial()\n+        initial[\"guestbook_name\"] = DEFAULT_GUESTBOOK_NAME\n+        return initial\n+\n+    def form_valid(self, form):\n+        if self.messages.get(\"greeting_create\"):\n+            messages.add_message(\n+                self.request,\n+                self.messages[\"greeting_create\"][\"level\"],\n+                self.messages[\"greeting_create\"][\"text\"]\n+            )\n+        self.greeting_create(form)\n+        return super(SignView, self).form_valid(form)\n+\n+    def greeting_create(self, form):\n+        dictionary = {\n+            'guestbook_name': form.cleaned_data[\"guestbook_name\"],\n+            'content': form.cleaned_data[\"greeting_message\"]\n+        }\n+        Greeting.put_from_dict(dictionary)\n+\n+\n+class GreetingEditView(FormView):\n+    template_name = \"greetingedit.html\"\n+    form_class = SignForm\n+    success_url = \"/\"\n+    messages = {\n+        \"greeting_create\": {\n+            \"level\": messages.SUCCESS,\n+            \"text\": \"Greeting updated.\"\n+        },\n+    }\n+    \n+    def get_initial(self):\n+        initial = super(GreetingEditView, self).get_initial()\n+\n+        book_id = self.request.GET.get(\"book\")\n+        greeting_id = self.request.GET.get(\"id\")\n+        greeting = Greeting.get_greeting(book_id, greeting_id)\n+\n+        initial[\"greeting_message\"] = greeting.content\n+        initial[\"guestbook_name\"] = book_id\n+        return initial\n+\n+    def form_valid(self, form):\n+        if self.messages.get(\"greeting_create\"):\n+            messages.add_message(\n+                self.request,\n+                self.messages[\"greeting_create\"][\"level\"],\n+                self.messages[\"greeting_create\"][\"text\"]\n+            )\n+        self.greeting_update(form)\n+        self.success_url = '/'\n+        time.sleep(0.5)\n+        return super(GreetingEditView, self).form_valid(form)\n+\n+    def greeting_update(self, form):\n+        greeting_id = self.request.GET.get(\"id\")\n+        book_id = self.request.GET.get(\"book\")\n+        greeting_content = form.cleaned_data[\"greeting_message\"]\n+        dictionary = {\n+            'guestbook_name': book_id,\n+            'greeting_id': greeting_id,\n+            'content': greeting_content\n+        }\n+        Greeting.update_greeting(dictionary)\n+\n+\n+class GreetingDeleteView(FormView):\n+    form_class = DeleteForm\n+    template_name = \"greetingdelete.html\"\n+    success_url = '/'\n+\n+    def get_initial(self):\n+        initial = super(GreetingDeleteView, self).get_initial()\n+\n+        book_id = self.request.GET.get(\"book\")\n+        greeting_id = self.request.GET.get(\"id\")\n+\n+        initial[\"greeting_id\"] = greeting_id\n+        initial[\"guestbook_name\"] = book_id\n+\n+        return initial\n+\n+    def form_valid(self, form):\n+        self.greeting_delete(form)\n+        time.sleep(0.5)","path":"testguestbook/guestbook/views.py","position":142,"original_position":142,"commit_id":"e069f203f0e73f6c47e258f93a035afdc210941e","original_commit_id":"e069f203f0e73f6c47e258f93a035afdc210941e","user":{"login":"asv-nhathv","id":8231950,"avatar_url":"https://avatars.githubusercontent.com/u/8231950?v=3","gravatar_id":"","url":"https://api.github.com/users/asv-nhathv","html_url":"https://github.com/asv-nhathv","followers_url":"https://api.github.com/users/asv-nhathv/followers","following_url":"https://api.github.com/users/asv-nhathv/following{/other_user}","gists_url":"https://api.github.com/users/asv-nhathv/gists{/gist_id}","starred_url":"https://api.github.com/users/asv-nhathv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asv-nhathv/subscriptions","organizations_url":"https://api.github.com/users/asv-nhathv/orgs","repos_url":"https://api.github.com/users/asv-nhathv/repos","events_url":"https://api.github.com/users/asv-nhathv/events{/privacy}","received_events_url":"https://api.github.com/users/asv-nhathv/received_events","type":"User","site_admin":false},"body":"dòng lệnh này để làm gì? có cần thiết ko?","created_at":"2015-03-11T11:08:31Z","updated_at":"2015-03-11T11:08:31Z","html_url":"https://github.com/dendgau/guestbook/pull/6#discussion_r26203561","pull_request_url":"https://api.github.com/repos/dendgau/guestbook/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/comments/26203561"},"html":{"href":"https://github.com/dendgau/guestbook/pull/6#discussion_r26203561"},"pull_request":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/dendgau/guestbook/pulls/6","id":29336194,"html_url":"https://github.com/dendgau/guestbook/pull/6","diff_url":"https://github.com/dendgau/guestbook/pull/6.diff","patch_url":"https://github.com/dendgau/guestbook/pull/6.patch","issue_url":"https://api.github.com/repos/dendgau/guestbook/issues/6","number":6,"state":"open","locked":false,"title":"Feature/django­api​​","user":{"login":"dendgau","id":6759698,"avatar_url":"https://avatars.githubusercontent.com/u/6759698?v=3","gravatar_id":"","url":"https://api.github.com/users/dendgau","html_url":"https://github.com/dendgau","followers_url":"https://api.github.com/users/dendgau/followers","following_url":"https://api.github.com/users/dendgau/following{/other_user}","gists_url":"https://api.github.com/users/dendgau/gists{/gist_id}","starred_url":"https://api.github.com/users/dendgau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dendgau/subscriptions","organizations_url":"https://api.github.com/users/dendgau/orgs","repos_url":"https://api.github.com/users/dendgau/repos","events_url":"https://api.github.com/users/dendgau/events{/privacy}","received_events_url":"https://api.github.com/users/dendgau/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-15T15:35:08Z","updated_at":"2015-03-11T11:08:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"320dc99902f92076ff533685291ab991697ae9f2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dendgau/guestbook/pulls/6/commits","review_comments_url":"https://api.github.com/repos/dendgau/guestbook/pulls/6/comments","review_comment_url":"https://api.github.com/repos/dendgau/guestbook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dendgau/guestbook/issues/6/comments","statuses_url":"https://api.github.com/repos/dendgau/guestbook/statuses/e069f203f0e73f6c47e258f93a035afdc210941e","head":{"label":"dendgau:feature/django­api​​","ref":"feature/django­api​​","sha":"e069f203f0e73f6c47e258f93a035afdc210941e","user":{"login":"dendgau","id":6759698,"avatar_url":"https://avatars.githubusercontent.com/u/6759698?v=3","gravatar_id":"","url":"https://api.github.com/users/dendgau","html_url":"https://github.com/dendgau","followers_url":"https://api.github.com/users/dendgau/followers","following_url":"https://api.github.com/users/dendgau/following{/other_user}","gists_url":"https://api.github.com/users/dendgau/gists{/gist_id}","starred_url":"https://api.github.com/users/dendgau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dendgau/subscriptions","organizations_url":"https://api.github.com/users/dendgau/orgs","repos_url":"https://api.github.com/users/dendgau/repos","events_url":"https://api.github.com/users/dendgau/events{/privacy}","received_events_url":"https://api.github.com/users/dendgau/received_events","type":"User","site_admin":false},"repo":{"id":30630355,"name":"guestbook","full_name":"dendgau/guestbook","owner":{"login":"dendgau","id":6759698,"avatar_url":"https://avatars.githubusercontent.com/u/6759698?v=3","gravatar_id":"","url":"https://api.github.com/users/dendgau","html_url":"https://github.com/dendgau","followers_url":"https://api.github.com/users/dendgau/followers","following_url":"https://api.github.com/users/dendgau/following{/other_user}","gists_url":"https://api.github.com/users/dendgau/gists{/gist_id}","starred_url":"https://api.github.com/users/dendgau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dendgau/subscriptions","organizations_url":"https://api.github.com/users/dendgau/orgs","repos_url":"https://api.github.com/users/dendgau/repos","events_url":"https://api.github.com/users/dendgau/events{/privacy}","received_events_url":"https://api.github.com/users/dendgau/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dendgau/guestbook","description":"Build guestbook app","fork":false,"url":"https://api.github.com/repos/dendgau/guestbook","forks_url":"https://api.github.com/repos/dendgau/guestbook/forks","keys_url":"https://api.github.com/repos/dendgau/guestbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dendgau/guestbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dendgau/guestbook/teams","hooks_url":"https://api.github.com/repos/dendgau/guestbook/hooks","issue_events_url":"https://api.github.com/repos/dendgau/guestbook/issues/events{/number}","events_url":"https://api.github.com/repos/dendgau/guestbook/events","assignees_url":"https://api.github.com/repos/dendgau/guestbook/assignees{/user}","branches_url":"https://api.github.com/repos/dendgau/guestbook/branches{/branch}","tags_url":"https://api.github.com/repos/dendgau/guestbook/tags","blobs_url":"https://api.github.com/repos/dendgau/guestbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dendgau/guestbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dendgau/guestbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/dendgau/guestbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dendgau/guestbook/statuses/{sha}","languages_url":"https://api.github.com/repos/dendgau/guestbook/languages","stargazers_url":"https://api.github.com/repos/dendgau/guestbook/stargazers","contributors_url":"https://api.github.com/repos/dendgau/guestbook/contributors","subscribers_url":"https://api.github.com/repos/dendgau/guestbook/subscribers","subscription_url":"https://api.github.com/repos/dendgau/guestbook/subscription","commits_url":"https://api.github.com/repos/dendgau/guestbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/dendgau/guestbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/dendgau/guestbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/dendgau/guestbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/dendgau/guestbook/contents/{+path}","compare_url":"https://api.github.com/repos/dendgau/guestbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dendgau/guestbook/merges","archive_url":"https://api.github.com/repos/dendgau/guestbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dendgau/guestbook/downloads","issues_url":"https://api.github.com/repos/dendgau/guestbook/issues{/number}","pulls_url":"https://api.github.com/repos/dendgau/guestbook/pulls{/number}","milestones_url":"https://api.github.com/repos/dendgau/guestbook/milestones{/number}","notifications_url":"https://api.github.com/repos/dendgau/guestbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dendgau/guestbook/labels{/name}","releases_url":"https://api.github.com/repos/dendgau/guestbook/releases{/id}","created_at":"2015-02-11T04:21:43Z","updated_at":"2015-02-11T06:40:47Z","pushed_at":"2015-03-11T07:00:04Z","git_url":"git://github.com/dendgau/guestbook.git","ssh_url":"git@github.com:dendgau/guestbook.git","clone_url":"https://github.com/dendgau/guestbook.git","svn_url":"https://github.com/dendgau/guestbook","homepage":null,"size":253,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":0,"default_branch":"master"}},"base":{"label":"dendgau:master","ref":"master","sha":"92908363484edbdbc7d19d0f7b41e8cc7dca4b05","user":{"login":"dendgau","id":6759698,"avatar_url":"https://avatars.githubusercontent.com/u/6759698?v=3","gravatar_id":"","url":"https://api.github.com/users/dendgau","html_url":"https://github.com/dendgau","followers_url":"https://api.github.com/users/dendgau/followers","following_url":"https://api.github.com/users/dendgau/following{/other_user}","gists_url":"https://api.github.com/users/dendgau/gists{/gist_id}","starred_url":"https://api.github.com/users/dendgau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dendgau/subscriptions","organizations_url":"https://api.github.com/users/dendgau/orgs","repos_url":"https://api.github.com/users/dendgau/repos","events_url":"https://api.github.com/users/dendgau/events{/privacy}","received_events_url":"https://api.github.com/users/dendgau/received_events","type":"User","site_admin":false},"repo":{"id":30630355,"name":"guestbook","full_name":"dendgau/guestbook","owner":{"login":"dendgau","id":6759698,"avatar_url":"https://avatars.githubusercontent.com/u/6759698?v=3","gravatar_id":"","url":"https://api.github.com/users/dendgau","html_url":"https://github.com/dendgau","followers_url":"https://api.github.com/users/dendgau/followers","following_url":"https://api.github.com/users/dendgau/following{/other_user}","gists_url":"https://api.github.com/users/dendgau/gists{/gist_id}","starred_url":"https://api.github.com/users/dendgau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dendgau/subscriptions","organizations_url":"https://api.github.com/users/dendgau/orgs","repos_url":"https://api.github.com/users/dendgau/repos","events_url":"https://api.github.com/users/dendgau/events{/privacy}","received_events_url":"https://api.github.com/users/dendgau/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dendgau/guestbook","description":"Build guestbook app","fork":false,"url":"https://api.github.com/repos/dendgau/guestbook","forks_url":"https://api.github.com/repos/dendgau/guestbook/forks","keys_url":"https://api.github.com/repos/dendgau/guestbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dendgau/guestbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dendgau/guestbook/teams","hooks_url":"https://api.github.com/repos/dendgau/guestbook/hooks","issue_events_url":"https://api.github.com/repos/dendgau/guestbook/issues/events{/number}","events_url":"https://api.github.com/repos/dendgau/guestbook/events","assignees_url":"https://api.github.com/repos/dendgau/guestbook/assignees{/user}","branches_url":"https://api.github.com/repos/dendgau/guestbook/branches{/branch}","tags_url":"https://api.github.com/repos/dendgau/guestbook/tags","blobs_url":"https://api.github.com/repos/dendgau/guestbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dendgau/guestbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dendgau/guestbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/dendgau/guestbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dendgau/guestbook/statuses/{sha}","languages_url":"https://api.github.com/repos/dendgau/guestbook/languages","stargazers_url":"https://api.github.com/repos/dendgau/guestbook/stargazers","contributors_url":"https://api.github.com/repos/dendgau/guestbook/contributors","subscribers_url":"https://api.github.com/repos/dendgau/guestbook/subscribers","subscription_url":"https://api.github.com/repos/dendgau/guestbook/subscription","commits_url":"https://api.github.com/repos/dendgau/guestbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/dendgau/guestbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/dendgau/guestbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/dendgau/guestbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/dendgau/guestbook/contents/{+path}","compare_url":"https://api.github.com/repos/dendgau/guestbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dendgau/guestbook/merges","archive_url":"https://api.github.com/repos/dendgau/guestbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dendgau/guestbook/downloads","issues_url":"https://api.github.com/repos/dendgau/guestbook/issues{/number}","pulls_url":"https://api.github.com/repos/dendgau/guestbook/pulls{/number}","milestones_url":"https://api.github.com/repos/dendgau/guestbook/milestones{/number}","notifications_url":"https://api.github.com/repos/dendgau/guestbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dendgau/guestbook/labels{/name}","releases_url":"https://api.github.com/repos/dendgau/guestbook/releases{/id}","created_at":"2015-02-11T04:21:43Z","updated_at":"2015-02-11T06:40:47Z","pushed_at":"2015-03-11T07:00:04Z","git_url":"git://github.com/dendgau/guestbook.git","ssh_url":"git@github.com:dendgau/guestbook.git","clone_url":"https://github.com/dendgau/guestbook.git","svn_url":"https://github.com/dendgau/guestbook","homepage":null,"size":253,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/6"},"html":{"href":"https://github.com/dendgau/guestbook/pull/6"},"issue":{"href":"https://api.github.com/repos/dendgau/guestbook/issues/6"},"comments":{"href":"https://api.github.com/repos/dendgau/guestbook/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dendgau/guestbook/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/dendgau/guestbook/statuses/e069f203f0e73f6c47e258f93a035afdc210941e"}}}}