{"action":"created","comment":{"url":"https://api.github.com/repos/p-p-m/ffw/pulls/comments/31951301","id":31951301,"diff_hunk":"@@ -55,57 +51,41 @@ def post(self, request, *args, **kwargs):\n             result(request)\n \n             return HttpResponse(json.dumps({'sum_cart': request.session['sum_cart'], 'count_cart': (\n-                request.session['count_cart'])}), cont)\n-\n+                request.session['count_cart']), 'products_cart': request.session['products_cart']}))\n \n-class CartRemove(TemplateView):\n \n-    @method_decorator(csrf_protect)\n-    def dispatch(self, *args, **kwargs):\n-         return super(CartRemove, self).dispatch(*args, **kwargs)\n+class CartRemove(View, CSRFProtectMixin):\n \n     def post(self, request, *args, **kwargs):\n         if request.is_ajax:\n-            cont = cont_get(request)\n-\n             product_pk = request.POST.get('product_pk', '')\n-            request.session[\"products\"].pop(product_pk)\n+            del request.session[\"products_cart\"][product_pk]\n             result(request)\n \n             return HttpResponse(json.dumps({'sum_cart': request.session['sum_cart'], 'count_cart': (\n-                 request.session['count_cart'])}), cont)\n-\n+                 request.session['count_cart']),  'products_cart': request.session['products_cart']}))\n \n-class Cart(TemplateView):\n \n-    @method_decorator(csrf_protect)\n-    def dispatch(self, *args, **kwargs):\n-        return super(Cart, self).dispatch(*args, **kwargs)\n+class Cart(View, CSRFProtectMixin):\n \n     def get(self,request, *args, **kwargs):\n         if request.is_ajax:\n-            return HttpResponse(json.dumps({'products': request.session['products'],\n-                'sum_cart': request.session['sum_cart'], 'count_cart': request.session['count_cart']}))\n+            return HttpResponse(json.dumps({'sum_cart': request.session['sum_cart'], 'count_cart': (\n+                 request.session['count_cart']),  'products_cart': request.session['products_cart']}))\n \n     def post(self, request, *args, **kwargs):\n         if request.is_ajax:\n-            cont = cont_get(request)\n-            request.session['products'] = {}\n+            request.session['products_cart'] = {}\n             request.session['sum_cart'] = 0\n             request.session['count_cart'] = 0\n-            return HttpResponse(json.dumps({}, cont))\n+            return HttpResponse(json.dumps({'sum_cart': request.session['sum_cart'], 'count_cart': (\n+                 request.session['count_cart']),  'products_cart': request.session['products_cart']}))","path":"ffw/cart/views.py","position":98,"original_position":98,"commit_id":"a1c9a013e9134c508c2f8885e80a6d39c7760358","original_commit_id":"a1c9a013e9134c508c2f8885e80a6d39c7760358","user":{"login":"p-p-m","id":1850488,"avatar_url":"https://avatars.githubusercontent.com/u/1850488?v=3","gravatar_id":"","url":"https://api.github.com/users/p-p-m","html_url":"https://github.com/p-p-m","followers_url":"https://api.github.com/users/p-p-m/followers","following_url":"https://api.github.com/users/p-p-m/following{/other_user}","gists_url":"https://api.github.com/users/p-p-m/gists{/gist_id}","starred_url":"https://api.github.com/users/p-p-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p-p-m/subscriptions","organizations_url":"https://api.github.com/users/p-p-m/orgs","repos_url":"https://api.github.com/users/p-p-m/repos","events_url":"https://api.github.com/users/p-p-m/events{/privacy}","received_events_url":"https://api.github.com/users/p-p-m/received_events","type":"User","site_admin":false},"body":"Каждое вью возвращает одно и то же. Давайте сделаем базовое вью которое будет иметь метод что формирует такой ответ. Например `format_response(session)` унаследуем все наши вью от базового и будем использовать этот метод.","created_at":"2015-06-08T19:41:59Z","updated_at":"2015-06-08T19:41:59Z","html_url":"https://github.com/p-p-m/ffw/pull/10#discussion_r31951301","pull_request_url":"https://api.github.com/repos/p-p-m/ffw/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/comments/31951301"},"html":{"href":"https://github.com/p-p-m/ffw/pull/10#discussion_r31951301"},"pull_request":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/p-p-m/ffw/pulls/10","id":37187195,"html_url":"https://github.com/p-p-m/ffw/pull/10","diff_url":"https://github.com/p-p-m/ffw/pull/10.diff","patch_url":"https://github.com/p-p-m/ffw/pull/10.patch","issue_url":"https://api.github.com/repos/p-p-m/ffw/issues/10","number":10,"state":"open","locked":false,"title":"Feature/cart update","user":{"login":"awsh10","id":5907270,"avatar_url":"https://avatars.githubusercontent.com/u/5907270?v=3","gravatar_id":"","url":"https://api.github.com/users/awsh10","html_url":"https://github.com/awsh10","followers_url":"https://api.github.com/users/awsh10/followers","following_url":"https://api.github.com/users/awsh10/following{/other_user}","gists_url":"https://api.github.com/users/awsh10/gists{/gist_id}","starred_url":"https://api.github.com/users/awsh10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awsh10/subscriptions","organizations_url":"https://api.github.com/users/awsh10/orgs","repos_url":"https://api.github.com/users/awsh10/repos","events_url":"https://api.github.com/users/awsh10/events{/privacy}","received_events_url":"https://api.github.com/users/awsh10/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-08T19:29:16Z","updated_at":"2015-06-08T19:41:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"55c26896d38655ce788349e0ec64001eb36b2694","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/p-p-m/ffw/pulls/10/commits","review_comments_url":"https://api.github.com/repos/p-p-m/ffw/pulls/10/comments","review_comment_url":"https://api.github.com/repos/p-p-m/ffw/pulls/comments{/number}","comments_url":"https://api.github.com/repos/p-p-m/ffw/issues/10/comments","statuses_url":"https://api.github.com/repos/p-p-m/ffw/statuses/a1c9a013e9134c508c2f8885e80a6d39c7760358","head":{"label":"p-p-m:feature/cart_update","ref":"feature/cart_update","sha":"a1c9a013e9134c508c2f8885e80a6d39c7760358","user":{"login":"p-p-m","id":1850488,"avatar_url":"https://avatars.githubusercontent.com/u/1850488?v=3","gravatar_id":"","url":"https://api.github.com/users/p-p-m","html_url":"https://github.com/p-p-m","followers_url":"https://api.github.com/users/p-p-m/followers","following_url":"https://api.github.com/users/p-p-m/following{/other_user}","gists_url":"https://api.github.com/users/p-p-m/gists{/gist_id}","starred_url":"https://api.github.com/users/p-p-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p-p-m/subscriptions","organizations_url":"https://api.github.com/users/p-p-m/orgs","repos_url":"https://api.github.com/users/p-p-m/repos","events_url":"https://api.github.com/users/p-p-m/events{/privacy}","received_events_url":"https://api.github.com/users/p-p-m/received_events","type":"User","site_admin":false},"repo":{"id":29500769,"name":"ffw","full_name":"p-p-m/ffw","owner":{"login":"p-p-m","id":1850488,"avatar_url":"https://avatars.githubusercontent.com/u/1850488?v=3","gravatar_id":"","url":"https://api.github.com/users/p-p-m","html_url":"https://github.com/p-p-m","followers_url":"https://api.github.com/users/p-p-m/followers","following_url":"https://api.github.com/users/p-p-m/following{/other_user}","gists_url":"https://api.github.com/users/p-p-m/gists{/gist_id}","starred_url":"https://api.github.com/users/p-p-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p-p-m/subscriptions","organizations_url":"https://api.github.com/users/p-p-m/orgs","repos_url":"https://api.github.com/users/p-p-m/repos","events_url":"https://api.github.com/users/p-p-m/events{/privacy}","received_events_url":"https://api.github.com/users/p-p-m/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/p-p-m/ffw","description":"","fork":false,"url":"https://api.github.com/repos/p-p-m/ffw","forks_url":"https://api.github.com/repos/p-p-m/ffw/forks","keys_url":"https://api.github.com/repos/p-p-m/ffw/keys{/key_id}","collaborators_url":"https://api.github.com/repos/p-p-m/ffw/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/p-p-m/ffw/teams","hooks_url":"https://api.github.com/repos/p-p-m/ffw/hooks","issue_events_url":"https://api.github.com/repos/p-p-m/ffw/issues/events{/number}","events_url":"https://api.github.com/repos/p-p-m/ffw/events","assignees_url":"https://api.github.com/repos/p-p-m/ffw/assignees{/user}","branches_url":"https://api.github.com/repos/p-p-m/ffw/branches{/branch}","tags_url":"https://api.github.com/repos/p-p-m/ffw/tags","blobs_url":"https://api.github.com/repos/p-p-m/ffw/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/p-p-m/ffw/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/p-p-m/ffw/git/refs{/sha}","trees_url":"https://api.github.com/repos/p-p-m/ffw/git/trees{/sha}","statuses_url":"https://api.github.com/repos/p-p-m/ffw/statuses/{sha}","languages_url":"https://api.github.com/repos/p-p-m/ffw/languages","stargazers_url":"https://api.github.com/repos/p-p-m/ffw/stargazers","contributors_url":"https://api.github.com/repos/p-p-m/ffw/contributors","subscribers_url":"https://api.github.com/repos/p-p-m/ffw/subscribers","subscription_url":"https://api.github.com/repos/p-p-m/ffw/subscription","commits_url":"https://api.github.com/repos/p-p-m/ffw/commits{/sha}","git_commits_url":"https://api.github.com/repos/p-p-m/ffw/git/commits{/sha}","comments_url":"https://api.github.com/repos/p-p-m/ffw/comments{/number}","issue_comment_url":"https://api.github.com/repos/p-p-m/ffw/issues/comments{/number}","contents_url":"https://api.github.com/repos/p-p-m/ffw/contents/{+path}","compare_url":"https://api.github.com/repos/p-p-m/ffw/compare/{base}...{head}","merges_url":"https://api.github.com/repos/p-p-m/ffw/merges","archive_url":"https://api.github.com/repos/p-p-m/ffw/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/p-p-m/ffw/downloads","issues_url":"https://api.github.com/repos/p-p-m/ffw/issues{/number}","pulls_url":"https://api.github.com/repos/p-p-m/ffw/pulls{/number}","milestones_url":"https://api.github.com/repos/p-p-m/ffw/milestones{/number}","notifications_url":"https://api.github.com/repos/p-p-m/ffw/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/p-p-m/ffw/labels{/name}","releases_url":"https://api.github.com/repos/p-p-m/ffw/releases{/id}","created_at":"2015-01-19T22:51:59Z","updated_at":"2015-01-19T22:55:29Z","pushed_at":"2015-06-08T19:29:16Z","git_url":"git://github.com/p-p-m/ffw.git","ssh_url":"git@github.com:p-p-m/ffw.git","clone_url":"https://github.com/p-p-m/ffw.git","svn_url":"https://github.com/p-p-m/ffw","homepage":null,"size":21192,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"p-p-m:develop","ref":"develop","sha":"b5ed5f6dcaedc35daa5f6a746fab590b28265af3","user":{"login":"p-p-m","id":1850488,"avatar_url":"https://avatars.githubusercontent.com/u/1850488?v=3","gravatar_id":"","url":"https://api.github.com/users/p-p-m","html_url":"https://github.com/p-p-m","followers_url":"https://api.github.com/users/p-p-m/followers","following_url":"https://api.github.com/users/p-p-m/following{/other_user}","gists_url":"https://api.github.com/users/p-p-m/gists{/gist_id}","starred_url":"https://api.github.com/users/p-p-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p-p-m/subscriptions","organizations_url":"https://api.github.com/users/p-p-m/orgs","repos_url":"https://api.github.com/users/p-p-m/repos","events_url":"https://api.github.com/users/p-p-m/events{/privacy}","received_events_url":"https://api.github.com/users/p-p-m/received_events","type":"User","site_admin":false},"repo":{"id":29500769,"name":"ffw","full_name":"p-p-m/ffw","owner":{"login":"p-p-m","id":1850488,"avatar_url":"https://avatars.githubusercontent.com/u/1850488?v=3","gravatar_id":"","url":"https://api.github.com/users/p-p-m","html_url":"https://github.com/p-p-m","followers_url":"https://api.github.com/users/p-p-m/followers","following_url":"https://api.github.com/users/p-p-m/following{/other_user}","gists_url":"https://api.github.com/users/p-p-m/gists{/gist_id}","starred_url":"https://api.github.com/users/p-p-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/p-p-m/subscriptions","organizations_url":"https://api.github.com/users/p-p-m/orgs","repos_url":"https://api.github.com/users/p-p-m/repos","events_url":"https://api.github.com/users/p-p-m/events{/privacy}","received_events_url":"https://api.github.com/users/p-p-m/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/p-p-m/ffw","description":"","fork":false,"url":"https://api.github.com/repos/p-p-m/ffw","forks_url":"https://api.github.com/repos/p-p-m/ffw/forks","keys_url":"https://api.github.com/repos/p-p-m/ffw/keys{/key_id}","collaborators_url":"https://api.github.com/repos/p-p-m/ffw/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/p-p-m/ffw/teams","hooks_url":"https://api.github.com/repos/p-p-m/ffw/hooks","issue_events_url":"https://api.github.com/repos/p-p-m/ffw/issues/events{/number}","events_url":"https://api.github.com/repos/p-p-m/ffw/events","assignees_url":"https://api.github.com/repos/p-p-m/ffw/assignees{/user}","branches_url":"https://api.github.com/repos/p-p-m/ffw/branches{/branch}","tags_url":"https://api.github.com/repos/p-p-m/ffw/tags","blobs_url":"https://api.github.com/repos/p-p-m/ffw/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/p-p-m/ffw/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/p-p-m/ffw/git/refs{/sha}","trees_url":"https://api.github.com/repos/p-p-m/ffw/git/trees{/sha}","statuses_url":"https://api.github.com/repos/p-p-m/ffw/statuses/{sha}","languages_url":"https://api.github.com/repos/p-p-m/ffw/languages","stargazers_url":"https://api.github.com/repos/p-p-m/ffw/stargazers","contributors_url":"https://api.github.com/repos/p-p-m/ffw/contributors","subscribers_url":"https://api.github.com/repos/p-p-m/ffw/subscribers","subscription_url":"https://api.github.com/repos/p-p-m/ffw/subscription","commits_url":"https://api.github.com/repos/p-p-m/ffw/commits{/sha}","git_commits_url":"https://api.github.com/repos/p-p-m/ffw/git/commits{/sha}","comments_url":"https://api.github.com/repos/p-p-m/ffw/comments{/number}","issue_comment_url":"https://api.github.com/repos/p-p-m/ffw/issues/comments{/number}","contents_url":"https://api.github.com/repos/p-p-m/ffw/contents/{+path}","compare_url":"https://api.github.com/repos/p-p-m/ffw/compare/{base}...{head}","merges_url":"https://api.github.com/repos/p-p-m/ffw/merges","archive_url":"https://api.github.com/repos/p-p-m/ffw/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/p-p-m/ffw/downloads","issues_url":"https://api.github.com/repos/p-p-m/ffw/issues{/number}","pulls_url":"https://api.github.com/repos/p-p-m/ffw/pulls{/number}","milestones_url":"https://api.github.com/repos/p-p-m/ffw/milestones{/number}","notifications_url":"https://api.github.com/repos/p-p-m/ffw/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/p-p-m/ffw/labels{/name}","releases_url":"https://api.github.com/repos/p-p-m/ffw/releases{/id}","created_at":"2015-01-19T22:51:59Z","updated_at":"2015-01-19T22:55:29Z","pushed_at":"2015-06-08T19:29:16Z","git_url":"git://github.com/p-p-m/ffw.git","ssh_url":"git@github.com:p-p-m/ffw.git","clone_url":"https://github.com/p-p-m/ffw.git","svn_url":"https://github.com/p-p-m/ffw","homepage":null,"size":21192,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/10"},"html":{"href":"https://github.com/p-p-m/ffw/pull/10"},"issue":{"href":"https://api.github.com/repos/p-p-m/ffw/issues/10"},"comments":{"href":"https://api.github.com/repos/p-p-m/ffw/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/p-p-m/ffw/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/p-p-m/ffw/statuses/a1c9a013e9134c508c2f8885e80a6d39c7760358"}}}}