コード例 #1
0
 def get(self, request, **kwargs):
     acct_id = kwargs.get('acct_id')
     g = request.GET
     fields = g.getlist("fields", None)
     account = Account.objects.get(pk=acct_id)
     if fields:
         JSONHoldings = ExtJsonSerializer().serialize(account.holdings, fields=fields)
     else:
         JSONHoldings = ExtJsonSerializer().serialize(account.holdings)
     return HttpResponse(JSONHoldings, status=200, content_type="application/json")
コード例 #2
0
 def test_get_account_holdings(self):
     c = Client()
     response = c.get('/account/1/holdings')
     self.assertEqual(
         response.status_code, 200,
         "Response status was not OK: {0}.".format(response.status_code))
     account = Account.objects.get(pk=1)
     serialized_holdings = simplejson.loads(ExtJsonSerializer().serialize(
         account.holdings))
     self.assertListEqual(
         simplejson.loads(response.content), serialized_holdings,
         "Returned holdings JSON data did not match expected.")
コード例 #3
0
 def post(self, request):
     n = request.post
     h = Holding.objects.filter(account=n.account).filter(security=n.security)
     if h:
         h.quantity = n.quantity
         h.expected_quantity = n.expected_quantity
         h.save()
     else:
         holding = Holding(account=n.account, security=n.security, quantity=n.quantity, expected_quantity=n.expected_quantity)
         try:
             holding.full_clean()
             holding.save()
             return HttpResponse(ExtJsonSerializer().serialize(holding), status="201 Created", content_type="application/json")
         except ValidationError as e:
             return HttpResponse(e, status="409 Conflict", content_type="application/json")
コード例 #4
0
    def get(self, request, **kwargs):
        acct_id = kwargs.get('acct_id')
        account = Account.objects.filter(pk=acct_id)
        JSONAccount = ExtJsonSerializer().serialize(account)

        return HttpResponse(JSONAccount, status="200 OK", content_type="application/json")
コード例 #5
0
ファイル: views.py プロジェクト: flyiniggle/Poptart
def asset_class(request, ac_id):
    return HttpResponse(ExtJsonSerializer().serialize(
        AssetClass.objects.filter(id=ac_id)),
                        status="200 OK",
                        content_type="application/json")
コード例 #6
0
ファイル: views.py プロジェクト: flyiniggle/Poptart
def asset_classes(request):
    return HttpResponse(ExtJsonSerializer().serialize(
        AssetClass.objects.all()),
                        status="200 OK",
                        content_type="application/json")
コード例 #7
0
ファイル: views.py プロジェクト: flyiniggle/Poptart
def security(request, ticker):
    return HttpResponse(ExtJsonSerializer().serialize(
        Security.objects.filter(ticker=ticker)),
                        status="200 OK",
                        content_type="application/json")
コード例 #8
0
ファイル: views.py プロジェクト: flyiniggle/Poptart
 def get(self, request):
     return HttpResponse(ExtJsonSerializer().serialize(
         Security.objects.all()),
                         status="200 OK",
                         content_type="application/json")