{"action":"created","comment":{"url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/comments/75823274","id":75823274,"diff_hunk":"@@ -22,27 +31,27 @@ def __init__(self, session):\n         if not cart:\n             cart = self._session[settings.CART_ID] = {}\n \n-        self._cart = cart\n+        self._cart = Cart.deserialize(cart)\n+\n+    @staticmethod\n+    def deserialize(session_cart):\n+        cart = {}\n+        for key, value in session_cart.items():\n+            cart[int(key)] = value\n+        return cart\n \n     def __iter__(self):\n         \"\"\"\n-        Iterate over the items in the Cart,\n+        Iterate over the positions in the Cart,\n         add 'product' key with respective model to every item.\n         \"\"\"\n-        model = apps.get_model(settings.PRODUCT_MODEL)\n-        products = model.objects.filter(id__in=self._cart.keys())\n-\n         # Since dict is mutable we should copy it.\n         cart = deepcopy(self._cart)\n \n-        for product in products:\n-            cart[str(product.id)]['product'] = product\n-\n-        sort_by_name = lambda item: item['product'].name\n-        \n-        for item in sorted(cart.values(), key=sort_by_name):\n-            item['total'] = item['quantity'] * item['price']\n-            yield item\n+        # without cart.values() sorting because json serializing for front mixes dict\n+        for id_, item in cart.items():","path":"ecommerce/cart.py","position":65,"original_position":65,"commit_id":"6a2ef5f5adc0bf23691d7bd76cebf64842c87818","original_commit_id":"6a2ef5f5adc0bf23691d7bd76cebf64842c87818","user":{"login":"begor","id":10001148,"avatar_url":"https://avatars.githubusercontent.com/u/10001148?v=3","gravatar_id":"","url":"https://api.github.com/users/begor","html_url":"https://github.com/begor","followers_url":"https://api.github.com/users/begor/followers","following_url":"https://api.github.com/users/begor/following{/other_user}","gists_url":"https://api.github.com/users/begor/gists{/gist_id}","starred_url":"https://api.github.com/users/begor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begor/subscriptions","organizations_url":"https://api.github.com/users/begor/orgs","repos_url":"https://api.github.com/users/begor/repos","events_url":"https://api.github.com/users/begor/events{/privacy}","received_events_url":"https://api.github.com/users/begor/received_events","type":"User","site_admin":false},"body":"В одном цикле происходят две несвязанные вещи:\r\n1. Апдейт value словаря\r\n2. Бросание пары из генераторы\r\n\r\nЯ бы разделил на map и бросание, потому что этот апдейт - подготовка внутреннего представления Cart к использованию и будет меняться, скорее всего, часто. ","created_at":"2016-08-23T08:38:06Z","updated_at":"2016-08-23T08:38:06Z","html_url":"https://github.com/fidals/refarm-ecommerce/pull/12#discussion_r75823274","pull_request_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/comments/75823274"},"html":{"href":"https://github.com/fidals/refarm-ecommerce/pull/12#discussion_r75823274"},"pull_request":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12","id":82214351,"html_url":"https://github.com/fidals/refarm-ecommerce/pull/12","diff_url":"https://github.com/fidals/refarm-ecommerce/pull/12.diff","patch_url":"https://github.com/fidals/refarm-ecommerce/pull/12.patch","issue_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/12","number":12,"state":"open","locked":false,"title":"F 780 release","user":{"login":"duker33","id":3526796,"avatar_url":"https://avatars.githubusercontent.com/u/3526796?v=3","gravatar_id":"","url":"https://api.github.com/users/duker33","html_url":"https://github.com/duker33","followers_url":"https://api.github.com/users/duker33/followers","following_url":"https://api.github.com/users/duker33/following{/other_user}","gists_url":"https://api.github.com/users/duker33/gists{/gist_id}","starred_url":"https://api.github.com/users/duker33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duker33/subscriptions","organizations_url":"https://api.github.com/users/duker33/orgs","repos_url":"https://api.github.com/users/duker33/repos","events_url":"https://api.github.com/users/duker33/events{/privacy}","received_events_url":"https://api.github.com/users/duker33/received_events","type":"User","site_admin":false},"body":"SE Fist Release","created_at":"2016-08-22T15:42:55Z","updated_at":"2016-08-23T08:38:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e8fb378efe2131cfe9f579da8f91c14989376679","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12/commits","review_comments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12/comments","review_comment_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/12/comments","statuses_url":"https://api.github.com/repos/fidals/refarm-ecommerce/statuses/6a2ef5f5adc0bf23691d7bd76cebf64842c87818","head":{"label":"fidals:f-780_release","ref":"f-780_release","sha":"6a2ef5f5adc0bf23691d7bd76cebf64842c87818","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":56853816,"name":"refarm-ecommerce","full_name":"fidals/refarm-ecommerce","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/refarm-ecommerce","description":"Django application with typical eCommerce functions: user's Cart, Order, sending mails","fork":false,"url":"https://api.github.com/repos/fidals/refarm-ecommerce","forks_url":"https://api.github.com/repos/fidals/refarm-ecommerce/forks","keys_url":"https://api.github.com/repos/fidals/refarm-ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-ecommerce/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-ecommerce/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-ecommerce/events","assignees_url":"https://api.github.com/repos/fidals/refarm-ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-ecommerce/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-ecommerce/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-ecommerce/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-ecommerce/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-ecommerce/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-ecommerce/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-ecommerce/merges","archive_url":"https://api.github.com/repos/fidals/refarm-ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-ecommerce/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/deployments","created_at":"2016-04-22T12:29:01Z","updated_at":"2016-05-03T09:07:15Z","pushed_at":"2016-08-22T15:42:55Z","git_url":"git://github.com/fidals/refarm-ecommerce.git","ssh_url":"git@github.com:fidals/refarm-ecommerce.git","clone_url":"https://github.com/fidals/refarm-ecommerce.git","svn_url":"https://github.com/fidals/refarm-ecommerce","homepage":"","size":43,"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":"fidals:master","ref":"master","sha":"caabfc5d84769f15ea2d05c045c66ebdc63b3555","user":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"repo":{"id":56853816,"name":"refarm-ecommerce","full_name":"fidals/refarm-ecommerce","owner":{"login":"fidals","id":16228604,"avatar_url":"https://avatars.githubusercontent.com/u/16228604?v=3","gravatar_id":"","url":"https://api.github.com/users/fidals","html_url":"https://github.com/fidals","followers_url":"https://api.github.com/users/fidals/followers","following_url":"https://api.github.com/users/fidals/following{/other_user}","gists_url":"https://api.github.com/users/fidals/gists{/gist_id}","starred_url":"https://api.github.com/users/fidals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fidals/subscriptions","organizations_url":"https://api.github.com/users/fidals/orgs","repos_url":"https://api.github.com/users/fidals/repos","events_url":"https://api.github.com/users/fidals/events{/privacy}","received_events_url":"https://api.github.com/users/fidals/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fidals/refarm-ecommerce","description":"Django application with typical eCommerce functions: user's Cart, Order, sending mails","fork":false,"url":"https://api.github.com/repos/fidals/refarm-ecommerce","forks_url":"https://api.github.com/repos/fidals/refarm-ecommerce/forks","keys_url":"https://api.github.com/repos/fidals/refarm-ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fidals/refarm-ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fidals/refarm-ecommerce/teams","hooks_url":"https://api.github.com/repos/fidals/refarm-ecommerce/hooks","issue_events_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/fidals/refarm-ecommerce/events","assignees_url":"https://api.github.com/repos/fidals/refarm-ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/fidals/refarm-ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/fidals/refarm-ecommerce/tags","blobs_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fidals/refarm-ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/fidals/refarm-ecommerce/languages","stargazers_url":"https://api.github.com/repos/fidals/refarm-ecommerce/stargazers","contributors_url":"https://api.github.com/repos/fidals/refarm-ecommerce/contributors","subscribers_url":"https://api.github.com/repos/fidals/refarm-ecommerce/subscribers","subscription_url":"https://api.github.com/repos/fidals/refarm-ecommerce/subscription","commits_url":"https://api.github.com/repos/fidals/refarm-ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/fidals/refarm-ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/fidals/refarm-ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/fidals/refarm-ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fidals/refarm-ecommerce/merges","archive_url":"https://api.github.com/repos/fidals/refarm-ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fidals/refarm-ecommerce/downloads","issues_url":"https://api.github.com/repos/fidals/refarm-ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/fidals/refarm-ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/fidals/refarm-ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fidals/refarm-ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/fidals/refarm-ecommerce/releases{/id}","deployments_url":"https://api.github.com/repos/fidals/refarm-ecommerce/deployments","created_at":"2016-04-22T12:29:01Z","updated_at":"2016-05-03T09:07:15Z","pushed_at":"2016-08-22T15:42:55Z","git_url":"git://github.com/fidals/refarm-ecommerce.git","ssh_url":"git@github.com:fidals/refarm-ecommerce.git","clone_url":"https://github.com/fidals/refarm-ecommerce.git","svn_url":"https://github.com/fidals/refarm-ecommerce","homepage":"","size":43,"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/fidals/refarm-ecommerce/pulls/12"},"html":{"href":"https://github.com/fidals/refarm-ecommerce/pull/12"},"issue":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/12"},"comments":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/fidals/refarm-ecommerce/statuses/6a2ef5f5adc0bf23691d7bd76cebf64842c87818"}}}}
{"actor":{"display_login":"begor"}}