Esempio n. 1
0
    def get(self):
        countryname = self.request.get("name")
        if countryname == "all":
            country_query = Country.query()
        elif countryname == "list":
            country_query = Country.query(projection=[Country.Name])
        else:
            country_query = Country.query(Country.Name == countryname)

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(
            json.dumps(
                [temp.to_dict() for temp in country_query],
                default=default_json_serializer,
            ))
Esempio n. 2
0
    def get(self):
        country_query = Country.query()

        region = self.request.get("Region")
        if region != "all":
            country_query = country_query.filter(
                Country.Region.IN(region.split("|")))

        population = self.request.get("Population")
        if population != "all" and country_query.fetch() != []:
            listOfEle = population.split("|")
            listOFKey = []
            for rang in listOfEle:
                if rang == "0-100":
                    temp = country_query.filter(
                        Country.Population < 100).fetch(keys_only=True)
                elif rang == "100-500":
                    temp = country_query.filter(
                        Country.Population < 500,
                        Country.Population >= 100).fetch(keys_only=True)
                else:
                    temp = country_query.filter(
                        Country.Population >= 500).fetch(keys_only=True)
                listOFKey += temp
            country_query = ndb.get_multi(listOFKey)

        totalProduce = self.request.get("Total_Production")
        if totalProduce != "all" and country_query != []:
            listOfEle = totalProduce.split("|")
            listOFResult = []
            for rang in listOfEle:
                for each in country_query:
                    if rang == "0-1000" and each.Total_Production < 1000:
                        listOFResult.append(each)
                    elif (rang == "1000-2000" and each.Total_Production < 2000
                          and each.Total_Production >= 1000):
                        listOFResult.append(each)
                    elif rang == ">2000" and each.Total_Production >= 2000:
                        listOFResult.append(each)
            country_query = listOFResult

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(
            json.dumps(
                [temp.to_dict() for temp in country_query],
                default=default_json_serializer,
            ))