コード例 #1
0
 def update(self, request, *args, **kws):
     print "Resource.update: ", args, kws
     pid,   = args
     adapter  = ChoiceHttpAdapter(Choice.objects.get(id = pid))
     adapter.updateFromPost(json.loads(request.body))
     return HttpResponse(json.dumps({"success" : "ok"})
                       , content_type = 'application/json')
コード例 #2
0
 def read(self, request, *args, **kws):
     if len(args) == 1:
         id,   = args
         adapter  = ChoiceHttpAdapter(Choice.objects.get(id = id))
         return HttpResponse(json.dumps(adapter.jsonDict())
                           , content_type = 'application/json')
     else:
         
         choiceJson = []
         for c in Choice.objects.all().order_by('id'):
             adapter = ChoiceHttpAdapter(c)
             #choiceJson.append(json.dumps(adapter.jsonDict()))
             choiceJson.append(adapter.jsonDict())
         return HttpResponse(json.dumps({"success" : "ok"
                                       , "choices" : choiceJson
                                       , "total" : len(choiceJson)
                                        })
                           , content_type = 'application/json')