コード例 #1
0
ファイル: maniac.py プロジェクト: ssxenon01/open-project
    def get(*args):
        self = args[0]
        result = []
        if len(args) == 1 :
            limit = int(self.request.get('limit')) if self.request.get('limit') else 20
            offset = int(self.request.get('start')) if self.request.get('start') else 0

            projects = memcache.get('%d:projects:%d' % (limit,offset))
            if projects is not None:
                result = projects
            else:
                for p in Project.all().run(limit=limit,offset=offset):
                    result.append(p.toMap())

                memcache.add('%d:projects:%d' % (limit,offset), result, 60)

            self.response.headers['x-total-count'] = str(Project.all().count())
        elif len(args) == 2 :
            p = memcache.get('project:%s'%args[1])
            if p is None:
                p = Project.get(db.Key.from_path('Project',int(args[1])))
                memcache.set('project:%s'%p.key().id_or_name(),p.toMap(),6000)
                result = p.toMap()
            else:
                result = p


        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(result))
コード例 #2
0
 def post(self):
     data = json.loads(self.request.body)
     p = Project(name=data['name'] , description=data['description'] , priority=data['priority'])
     p.put()
     response_json = {'id':p.key().id_or_name(),'name':p.name,'description':p.description,'priority':p.priority,'dateCreated':str(p.dateCreated),'lastUpdated':str(p.lastUpdated)}
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(response_json))
コード例 #3
0
    def get(*args):
        self = args[0]

        response_json = []

        if len(args) == 1 :
            limit = int(self.request.get('limit')) if self.request.get('limit') else 20
            offset = int(self.request.get('start')) if self.request.get('start') else 0
            for p in Project.all().run(limit=limit,offset=offset):
                response_json.append({'id':p.key().id_or_name(),'name':p.name,'description':p.description,'priority':p.priority,'dateCreated':str(p.dateCreated),'lastUpdated':str(p.lastUpdated)})
                self.response.headers['x-total-count'] = str(Project.all().count())
        elif len(args) == 2 :
            p = Project.get(db.Key.from_path('Project',int(args[1])))
            response_json = {'id':p.key().id_or_name(),'name':p.name,'description':p.description,'priority':p.priority,'dateCreated':str(p.dateCreated),'lastUpdated':str(p.lastUpdated)}


        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(response_json))
コード例 #4
0
ファイル: maniac.py プロジェクト: ssxenon01/open-project
 def put(self,id):
     data = json.loads(self.request.body)
     p = Project.get(db.Key.from_path('Project',int(id)))
     for k in data:
         if data[k] is not None:
             setattr(p,k,data[k])
     p.put()
     memcache.set('project:%s'%p.key().id_or_name(),p.toMap(),6000)
     result = p.toMap()
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(result))
コード例 #5
0
    def put(self,id):
        data = json.loads(self.request.body)
        p = Project.get(db.Key.from_path('Project',int(id)))
        # for property, value in vars(data).iteritems():
            # print property, ": ", value
        for k in data:
            setattr(p,k,data[k])

        response_json = {'id':p.key().id_or_name(),'name':p.name,'description':p.description,'priority':p.priority,'dateCreated':str(p.dateCreated),'lastUpdated':str(p.lastUpdated)}
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(response_json))
コード例 #6
0
ファイル: maniac.py プロジェクト: ssxenon01/open-project
 def post(self):
     data = json.loads(self.request.body)
     p = Project().fromMap(data)
     # p = Project(name=data['name'] , description=data['description'] , priority=data['priority'])
     p.put()
     memcache.set('project:%s'%p.key().id_or_name(),p.toMap(),6000)
     result = p.toMap()
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(result))