{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/solitude/pulls/comments/28801703","id":28801703,"diff_hunk":"@@ -0,0 +1,114 @@\n+from rest_framework.response import Response\n+\n+from ..client import response_to_dict\n+from ..constants import INVALID_PERSON, VAT_NUMBER_DOES_NOT_EXIST\n+from ..errors import BangoFormError, ProcessError\n+from ..forms import (FinanceEmailForm, PackageForm,\n+                     SupportEmailForm, UpdateAddressForm,\n+                     VatNumberForm)\n+from lib.bango.serializers import PackageSerializer, SellerBangoSerializer\n+from lib.bango.views.base import BangoResource\n+from lib.sellers.models import SellerBango\n+from solitude.base import NonDeleteModelViewSet\n+\n+\n+class PackageViewSet(NonDeleteModelViewSet, BangoResource):\n+    queryset = SellerBango.objects.filter()\n+    serializer_class = SellerBangoSerializer\n+\n+    error_lookup = {\n+        'INVALID_COUNTRYISO': 'countryIso',\n+        'INVALID_CURRENCYISO': 'currencyIso',\n+        'INVALID_URL': 'homePageURL',\n+    }\n+\n+    def create(self, request, *args, **kw):\n+        \"\"\"\n+        Create a SellerBango record, which just passes the data\n+        through to Bango and then stores the result here.\n+        \"\"\"\n+\n+        try:\n+            serial, form = self.process(\n+                serial_class=PackageSerializer,\n+                form_class=PackageForm,\n+                request=request)\n+        except ProcessError, exc:\n+            return exc.response\n+\n+        resp = self.client('CreatePackage', form.bango_data)\n+\n+        seller_bango = SellerBango.objects.create(\n+            seller=serial.object['seller'],\n+            package_id=resp.packageId,\n+            admin_person_id=resp.adminPersonId,\n+            support_person_id=resp.supportPersonId,\n+            finance_person_id=resp.financePersonId\n+        )\n+\n+        new_serial = SellerBangoSerializer(seller_bango)\n+        return Response(new_serial.data, status=201)\n+\n+    def update(self, request, *args, **kw):\n+        \"\"\"\n+        Update the Bango records and then our record. We'll assume that\n+        any data that is sent in the patch is optional, if ignored, we won't\n+        update. We also don't know what the old value is, we just assume if\n+        its there its an update.\n+        \"\"\"\n+        if kw.get('partial') is not True:\n+            return Response(status=405)\n+\n+        # These four forms are just that, forms that contain standard fields\n+        # with nothing linking to another object. Using forms seems appropriate\n+        # here instead of a serializer.\n+        #\n+        obj = self.get_object()\n+        data = request.DATA\n+        forms = [FinanceEmailForm(data), SupportEmailForm(data),\n+                 UpdateAddressForm(data), VatNumberForm(data)]\n+\n+        for form in forms:\n+            if not form.is_valid():\n+                return self.form_errors(form)\n+\n+        for form in forms:\n+            data = form.bango_data\n+            keys = form.bango_meta\n+            data['packageId'] = obj.package_id\n+            try:\n+                result = self.client(keys['method'], data,\n+                                     raise_on=keys.get('raise_on', None))\n+            except BangoFormError, exc:\n+                # We don't know the persons email account, we only\n+                # know that Bango might not like it if its unchanged.\n+                if exc.id not in (INVALID_PERSON, VAT_NUMBER_DOES_NOT_EXIST):\n+                    raise\n+            else:\n+                if keys.get('to_field'):\n+                    # Only change the model in some cases.\n+                    setattr(obj, keys.get('to_field'),\n+                            getattr(result, keys.get('from_field')))\n+\n+        obj.save()\n+        new_serial = SellerBangoSerializer(obj).data.copy()\n+        new_serial.update(form.cleaned_data)\n+        return Response(new_serial, status=201)\n+\n+    def retrieve(self, request, *args, **kw):\n+        \"\"\"\n+        Retrive the seller bango data, but if a 'full' is specified,\n+        get the package from bango and include that in the full\n+        attribute.\n+        \"\"\"\n+        self.object = self.get_object()\n+        data = self.get_serializer(self.object).data\n+        data['full'] = {}\n+        if request.DATA.get('full'):\n+            data['full'] = response_to_dict(\n+                self.client(\n+                    'GetPackage',\n+                    {'packageId': self.object.package_id}\n+                )\n+            )","path":"lib/bango/views/package.py","position":113,"original_position":113,"commit_id":"4c8768a23947bd1c083a70d5070d3462d4f5de20","original_commit_id":"4c8768a23947bd1c083a70d5070d3462d4f5de20","user":{"login":"kumar303","id":55398,"avatar_url":"https://avatars.githubusercontent.com/u/55398?v=3","gravatar_id":"","url":"https://api.github.com/users/kumar303","html_url":"https://github.com/kumar303","followers_url":"https://api.github.com/users/kumar303/followers","following_url":"https://api.github.com/users/kumar303/following{/other_user}","gists_url":"https://api.github.com/users/kumar303/gists{/gist_id}","starred_url":"https://api.github.com/users/kumar303/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kumar303/subscriptions","organizations_url":"https://api.github.com/users/kumar303/orgs","repos_url":"https://api.github.com/users/kumar303/repos","events_url":"https://api.github.com/users/kumar303/events{/privacy}","received_events_url":"https://api.github.com/users/kumar303/received_events","type":"User","site_admin":false},"body":"mmm, the full things feels a little crufty. Maybe one to sort out later though.","created_at":"2015-04-21T17:29:02Z","updated_at":"2015-04-21T17:29:02Z","html_url":"https://github.com/mozilla/solitude/pull/341#discussion_r28801703","pull_request_url":"https://api.github.com/repos/mozilla/solitude/pulls/341","_links":{"self":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/comments/28801703"},"html":{"href":"https://github.com/mozilla/solitude/pull/341#discussion_r28801703"},"pull_request":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/341"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/solitude/pulls/341","id":33090085,"html_url":"https://github.com/mozilla/solitude/pull/341","diff_url":"https://github.com/mozilla/solitude/pull/341.diff","patch_url":"https://github.com/mozilla/solitude/pull/341.patch","issue_url":"https://api.github.com/repos/mozilla/solitude/issues/341","number":341,"state":"open","locked":false,"title":"drive a stake through tastypie and crown DRF as a much better plan. omg the pain. (fixes #22)","user":{"login":"andymckay","id":74699,"avatar_url":"https://avatars.githubusercontent.com/u/74699?v=3","gravatar_id":"","url":"https://api.github.com/users/andymckay","html_url":"https://github.com/andymckay","followers_url":"https://api.github.com/users/andymckay/followers","following_url":"https://api.github.com/users/andymckay/following{/other_user}","gists_url":"https://api.github.com/users/andymckay/gists{/gist_id}","starred_url":"https://api.github.com/users/andymckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andymckay/subscriptions","organizations_url":"https://api.github.com/users/andymckay/orgs","repos_url":"https://api.github.com/users/andymckay/repos","events_url":"https://api.github.com/users/andymckay/events{/privacy}","received_events_url":"https://api.github.com/users/andymckay/received_events","type":"User","site_admin":false},"body":"* [ ] this removes /agreement/ from SBI urls because tastypie. will need to fix zamboni\r\n* [ ] this removes /status/ from refund urls because dammit tastypie. will need to fix zamboni\r\n* [ ] SBI reponses will have date and time, will need to check zamboni\r\n* [x] made bango notification return empty, will need to check webpay\r\n* [x] made bango event return empty, will need to check webpay ","created_at":"2015-04-10T22:51:17Z","updated_at":"2015-04-21T17:29:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b100d9e0adf7c405c3adf9a9e4d1e74af5a3ddd0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/solitude/pulls/341/commits","review_comments_url":"https://api.github.com/repos/mozilla/solitude/pulls/341/comments","review_comment_url":"https://api.github.com/repos/mozilla/solitude/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/solitude/issues/341/comments","statuses_url":"https://api.github.com/repos/mozilla/solitude/statuses/4c8768a23947bd1c083a70d5070d3462d4f5de20","head":{"label":"andymckay:22","ref":"22","sha":"4c8768a23947bd1c083a70d5070d3462d4f5de20","user":{"login":"andymckay","id":74699,"avatar_url":"https://avatars.githubusercontent.com/u/74699?v=3","gravatar_id":"","url":"https://api.github.com/users/andymckay","html_url":"https://github.com/andymckay","followers_url":"https://api.github.com/users/andymckay/followers","following_url":"https://api.github.com/users/andymckay/following{/other_user}","gists_url":"https://api.github.com/users/andymckay/gists{/gist_id}","starred_url":"https://api.github.com/users/andymckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andymckay/subscriptions","organizations_url":"https://api.github.com/users/andymckay/orgs","repos_url":"https://api.github.com/users/andymckay/repos","events_url":"https://api.github.com/users/andymckay/events{/privacy}","received_events_url":"https://api.github.com/users/andymckay/received_events","type":"User","site_admin":false},"repo":{"id":23588659,"name":"solitude","full_name":"andymckay/solitude","owner":{"login":"andymckay","id":74699,"avatar_url":"https://avatars.githubusercontent.com/u/74699?v=3","gravatar_id":"","url":"https://api.github.com/users/andymckay","html_url":"https://github.com/andymckay","followers_url":"https://api.github.com/users/andymckay/followers","following_url":"https://api.github.com/users/andymckay/following{/other_user}","gists_url":"https://api.github.com/users/andymckay/gists{/gist_id}","starred_url":"https://api.github.com/users/andymckay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andymckay/subscriptions","organizations_url":"https://api.github.com/users/andymckay/orgs","repos_url":"https://api.github.com/users/andymckay/repos","events_url":"https://api.github.com/users/andymckay/events{/privacy}","received_events_url":"https://api.github.com/users/andymckay/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andymckay/solitude","description":"A server for processing payments for Mozilla’s Marketplace and Add-ons site.","fork":true,"url":"https://api.github.com/repos/andymckay/solitude","forks_url":"https://api.github.com/repos/andymckay/solitude/forks","keys_url":"https://api.github.com/repos/andymckay/solitude/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andymckay/solitude/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andymckay/solitude/teams","hooks_url":"https://api.github.com/repos/andymckay/solitude/hooks","issue_events_url":"https://api.github.com/repos/andymckay/solitude/issues/events{/number}","events_url":"https://api.github.com/repos/andymckay/solitude/events","assignees_url":"https://api.github.com/repos/andymckay/solitude/assignees{/user}","branches_url":"https://api.github.com/repos/andymckay/solitude/branches{/branch}","tags_url":"https://api.github.com/repos/andymckay/solitude/tags","blobs_url":"https://api.github.com/repos/andymckay/solitude/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andymckay/solitude/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andymckay/solitude/git/refs{/sha}","trees_url":"https://api.github.com/repos/andymckay/solitude/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andymckay/solitude/statuses/{sha}","languages_url":"https://api.github.com/repos/andymckay/solitude/languages","stargazers_url":"https://api.github.com/repos/andymckay/solitude/stargazers","contributors_url":"https://api.github.com/repos/andymckay/solitude/contributors","subscribers_url":"https://api.github.com/repos/andymckay/solitude/subscribers","subscription_url":"https://api.github.com/repos/andymckay/solitude/subscription","commits_url":"https://api.github.com/repos/andymckay/solitude/commits{/sha}","git_commits_url":"https://api.github.com/repos/andymckay/solitude/git/commits{/sha}","comments_url":"https://api.github.com/repos/andymckay/solitude/comments{/number}","issue_comment_url":"https://api.github.com/repos/andymckay/solitude/issues/comments{/number}","contents_url":"https://api.github.com/repos/andymckay/solitude/contents/{+path}","compare_url":"https://api.github.com/repos/andymckay/solitude/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andymckay/solitude/merges","archive_url":"https://api.github.com/repos/andymckay/solitude/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andymckay/solitude/downloads","issues_url":"https://api.github.com/repos/andymckay/solitude/issues{/number}","pulls_url":"https://api.github.com/repos/andymckay/solitude/pulls{/number}","milestones_url":"https://api.github.com/repos/andymckay/solitude/milestones{/number}","notifications_url":"https://api.github.com/repos/andymckay/solitude/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andymckay/solitude/labels{/name}","releases_url":"https://api.github.com/repos/andymckay/solitude/releases{/id}","created_at":"2014-09-02T17:37:20Z","updated_at":"2015-04-19T15:06:31Z","pushed_at":"2015-04-21T00:16:39Z","git_url":"git://github.com/andymckay/solitude.git","ssh_url":"git@github.com:andymckay/solitude.git","clone_url":"https://github.com/andymckay/solitude.git","svn_url":"https://github.com/andymckay/solitude","homepage":"http://readthedocs.org/docs/solitude/en/latest/","size":3429,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"204f7d9a2d03fc16bf59667445a65cb5da3ad131","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":4566171,"name":"solitude","full_name":"mozilla/solitude","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/solitude","description":"A server for processing payments for Mozilla’s Marketplace.","fork":false,"url":"https://api.github.com/repos/mozilla/solitude","forks_url":"https://api.github.com/repos/mozilla/solitude/forks","keys_url":"https://api.github.com/repos/mozilla/solitude/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/solitude/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/solitude/teams","hooks_url":"https://api.github.com/repos/mozilla/solitude/hooks","issue_events_url":"https://api.github.com/repos/mozilla/solitude/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/solitude/events","assignees_url":"https://api.github.com/repos/mozilla/solitude/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/solitude/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/solitude/tags","blobs_url":"https://api.github.com/repos/mozilla/solitude/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/solitude/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/solitude/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/solitude/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/solitude/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/solitude/languages","stargazers_url":"https://api.github.com/repos/mozilla/solitude/stargazers","contributors_url":"https://api.github.com/repos/mozilla/solitude/contributors","subscribers_url":"https://api.github.com/repos/mozilla/solitude/subscribers","subscription_url":"https://api.github.com/repos/mozilla/solitude/subscription","commits_url":"https://api.github.com/repos/mozilla/solitude/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/solitude/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/solitude/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/solitude/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/solitude/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/solitude/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/solitude/merges","archive_url":"https://api.github.com/repos/mozilla/solitude/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/solitude/downloads","issues_url":"https://api.github.com/repos/mozilla/solitude/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/solitude/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/solitude/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/solitude/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/solitude/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/solitude/releases{/id}","created_at":"2012-06-05T22:13:53Z","updated_at":"2015-04-20T22:59:16Z","pushed_at":"2015-04-21T00:17:11Z","git_url":"git://github.com/mozilla/solitude.git","ssh_url":"git@github.com:mozilla/solitude.git","clone_url":"https://github.com/mozilla/solitude.git","svn_url":"https://github.com/mozilla/solitude","homepage":"http://readthedocs.org/docs/solitude/en/latest/","size":6463,"stargazers_count":24,"watchers_count":24,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":14,"forks":26,"open_issues":14,"watchers":24,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/341"},"html":{"href":"https://github.com/mozilla/solitude/pull/341"},"issue":{"href":"https://api.github.com/repos/mozilla/solitude/issues/341"},"comments":{"href":"https://api.github.com/repos/mozilla/solitude/issues/341/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/341/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/solitude/pulls/341/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/solitude/statuses/4c8768a23947bd1c083a70d5070d3462d4f5de20"}}}}