예제 #1
0
 def create(self, request, *args, **kws):
     adapter  = SessionHttpAdapter()
     adapter.initFromPost(json.loads(request.raw_post_data))
     sessions = [adapter.jsonDict(detailed = True)]
     return HttpResponse(json.dumps({ 'success' : 'ok'
                                    , self.root : sessions
                         })
                       , content_type = 'application/json')
     return response
예제 #2
0
    def checkDB(self):
        proposals = [Proposal.objects.get(id = id) for id in self.ids]
        print "Modified Proposals: ", ', '.join([p.pcode for p in proposals])
        for p in proposals:
            print "PCode\t\tRq.\tAllot."
            print "%s\t%s\t%s" % (p.pcode, p.requestedTime(), p.allocatedTime())

            print "\tName\t\tGrade\tRq.\tAllot."
            for s in p.session_set.all().order_by('name'):
                sa = SessionHttpAdapter(s)
                data = sa.jsonDict()
                print "\t%s\t%s\t%s\t%s" % (data['name'], data['grade'], data['requested_total'], data['allocated_time'])
예제 #3
0
 def test_jsonDictAllHP(self):
     sa = SessionHttpAdapter(session = Session.objects.all()[0])
     # here's what the json for this session looks like when
     # we use the ORM
     ormJson = sa.jsonDict()
     # here's what the json for this session looks like when
     # we use the high performance query of the DB
     sqlJsons = sa.jsonDictAllHP()
     self.assertEqual(1, len(sqlJsons))
     sqlJson = sqlJsons[0]
     #keys = ormJson.keys()
     #for k in sorted(keys):
     #    print k, " : ", ormJson[k]
     #print "********************"
     #keys = sqlJson.keys()
     #for k in sorted(keys):
     #    print k, " : ", sqlJson[k]
     self.assertEqual(ormJson, sqlJson)
예제 #4
0
 def read(self, request, *args, **kws):
     if len(args) == 1:
         id,   = args
         adapter  = SessionHttpAdapter(Session.objects.get(id = id))
         return HttpResponse(json.dumps(adapter.jsonDict(detailed = True))
                           , content_type = 'application/json')
     else:
         # Keep this here for when we start doing pagenation
         """
         start = request.GET.get('start', 0)
         limit = request.GET.get('limit', 25)
         end   = int(start) + int(limit)
         """
         #sessions = Session.objects.all()
         sessions = SessionHttpAdapter.jsonDictAllHP()
         return HttpResponse(json.dumps({"success" : "ok"
                                       #, "sessions" : [SessionHttpAdapter(s).jsonDict() for s in sessions]
                                       , "sessions" : sessions
                                       , "total" : len(sessions)
                                        })
                           , content_type = 'application/json')