def testGetPropertiesOf(self):
   """Test for get_properties_of_kind."""
   self.assertEqual(['str'], metadata.get_properties_of_kind('Bar'))
   self.assertEqual([], metadata.get_properties_of_kind('Baz', 'g'))
   self.assertEqual(['data'],
                    metadata.get_properties_of_kind('Foo', None, 'e'))
   self.assertEqual(['data'], metadata.get_properties_of_kind('Foo', '', 'e'))
   self.assertEqual([], metadata.get_properties_of_kind('Foo', None, ''))
예제 #2
0
    def get(self, collection, item):
        if (self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()
            c.kind()
            n = c.all().filter("__key__ =",
                               db.Key.from_path(collection, int(item)))
            b = metadata.get_properties_of_kind(collection.lower())
            arr = {}

            for g in n:
                for a in b:
                    try:
                        arr[a.lower()] = getattr(g, a)
                    except:
                        pass

            # RESPONSE === BEGIN #
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write(
                "%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(arr))
            self.response.out.write(")")
예제 #3
0
    def get(self, collection):

        if (self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()

            c.kind()
            n = c.all()

            if self.request.get("filter") != "":
                n.filter("%s" % self.request.get("filter"),
                         "%s" % self.request.get("value").replace(' ', '_'))
            else:
                pass

            if self.request.get("offset") != "":
                fil = n.fetch(int(self.request.get("limit")),
                              int(self.request.get("offset")))
            elif self.request.get("limit") != "":
                fil = n.fetch(int(self.request.get("limit")))
            else:
                fil = n

            r = fil.count()

            m = metadata.get_properties_of_kind(collection.lower())
            arr = {}
            full = []
            count = 0
            for ab in m:
                arr[count] = ab
                count += 1
            arr[count] = "id"
            full.append(arr)
            string = {}
            string["count"] = r
            full.append(string)

            # RESPONSE === BEGIN #
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write(
                "%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(full))
            self.response.out.write(")")
예제 #4
0
    def get(self, collection):
        if (self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()
            c.kind()
            n = c.all()

            if self.request.get("filter") != "":
                n.filter("%s" % self.request.get("filter"),
                         "%s" % self.request.get("value").replace(' ', '_'))
            else:
                pass

            if self.request.get("offset") != "":
                fil = n.fetch(int(self.request.get("limit")),
                              int(self.request.get("offset")))
            elif self.request.get("limit") != "":
                fil = n.fetch(int(self.request.get("limit")))
            else:
                fil = n

            b = metadata.get_properties_of_kind(collection.lower())
            arr = []

            for g in fil:
                results = {}
                results["id"] = g.key().id()
                for a in b:
                    try:
                        results[a] = getattr(g, a)
                    except:
                        pass

                arr.append(results)

            # RESPONSE === BEGIN #
            self.response.out.write(
                "%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(arr))
            self.response.out.write(")")
예제 #5
0
파일: main.py 프로젝트: kdurril/gae-api
    def get(self, collection):

        if(self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()

            c.kind()
            n = c.all()

            if self.request.get("filter") != "":
                n.filter("%s" % self.request.get("filter"), "%s" %  self.request.get("value").replace(' ', '_'))
            else:
                pass

            if self.request.get("offset") != "":
                fil = n.fetch(int(self.request.get("limit")), int(self.request.get("offset")))
            elif self.request.get("limit") != "":
                fil = n.fetch(int(self.request.get("limit")))
            else:
                fil = n

            r = fil.count()

            m = metadata.get_properties_of_kind(collection.lower())
            arr = {}
            full = []
            count = 0
            for ab in m:
                arr[count] = ab
                count += 1
            arr[count] = "id"
            full.append(arr)
            string = {}
            string["count"] = r
            full.append(string)

            # RESPONSE === BEGIN #
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write("%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(full))
            self.response.out.write(")")
예제 #6
0
파일: main.py 프로젝트: kdurril/gae-api
    def get(self, collection):
        if(self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            self.response.headers['Access-Control-Allow-Origin'] = '*'
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()
            c.kind()
            n = c.all()

            if self.request.get("filter") != "":
                n.filter("%s" % self.request.get("filter"), "%s" %  self.request.get("value").replace(' ', '_'))
            else:
                pass

            if self.request.get("offset") != "":
                fil = n.fetch(int(self.request.get("limit")), int(self.request.get("offset")))
            elif self.request.get("limit") != "":
                fil = n.fetch(int(self.request.get("limit")))
            else:
                fil = n

            b = metadata.get_properties_of_kind(collection.lower())
            arr = []

            for g in fil:
                results = {}
                results["id"] = g.key().id()
                for a in b:
                    try:
                        results[a] = getattr(g,a)
                    except:
                        pass

                arr.append(results)

            # RESPONSE === BEGIN #
            self.response.out.write("%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(arr))
            self.response.out.write(")")
예제 #7
0
파일: main.py 프로젝트: kdurril/gae-api
    def get(self, collection, item):
        if(self.request.get('secret_key') != SECRET_KEY):
            pass
        else:
            global currentcollection
            currentcollection = collection.lower()
            c = CustomCollection()
            c.kind()
            n = c.all().filter("__key__ =", db.Key.from_path(collection, int(item)))
            b = metadata.get_properties_of_kind(collection.lower())
            arr = {}

            for g in n:
                for a in b:
                    try:
                        arr[a.lower()] = getattr(g,a)
                    except:
                        pass

            # RESPONSE === BEGIN #
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write("%s(" % urllib2.unquote(self.request.get('callback')))
            self.response.out.write(json.dumps(arr))
            self.response.out.write(")")