Exemplo n.º 1
0
    def build(self, data):
        """Method should converts json_data to python object."""
        self.manager.clear()  # always clear manager data.
        self.parser.data = data

        def validate(location):
            return False if not location.city else True

        results = self.parser.get_results()

        for result in results:
            self.parser.data = result

            model = LocationModel()

            model.city = self.parser.parse_city()
            model.route = self.parser.parse_route()
            model.street_number = self.parser.parse_street_number()
            model.postal_code = self.parser.parse_postal_code()

            model.country = self.parser.parse_country()
            model.country_shortcut = self.parser.parse_country_shortcut()

            model.administrative_area = self.parser.parse_administrative_area()

            model.lat = self.parser.parse_lat()
            model.lng = self.parser.parse_lng()

            model.formatted_address = self.parser.parse_formatted_address()

            if validate(model):
                self.manager.data.add(model)
Exemplo n.º 2
0
    def to_python(self, json_data):
        """Method should converts json_data to python object."""
        self.manager.clear()  # always clear manager data.
        self.parser.json_data = json_data

        results = self.parser.get_results()

        for result in results:
            self.parser.json_data = result

            model = LocationModel()

            model.city = self.parser.get_city()
            model.route = self.parser.get_route()
            model.street_number = self.parser.get_street_number()
            model.postal_code = self.parser.get_postal_code()

            model.country = self.parser.get_country()
            model.country_shortcut = self.parser.get_country_shortcut()

            model.administrative_area = self.parser.get_administrative_area()

            model.lat = self.parser.get_lat()
            model.lng = self.parser.get_lng()

            model.formatted_address = self.parser.get_formatted_address()

            if self.validate(model):
                self.manager.data.add(model)
Exemplo n.º 3
0
    def build(self, data):
        """Method should converts json_data to python object."""
        self.manager.clear()  # always clear manager data.
        self.parser.data = data

        def validate(location): return False if not location.city else True

        results = self.parser.get_results()

        for result in results:
            self.parser.data = result

            model = LocationModel()

            model.city = self.parser.parse_city()
            model.route = self.parser.parse_route()
            model.street_number = self.parser.parse_street_number()
            model.postal_code = self.parser.parse_postal_code()

            model.country = self.parser.parse_country()
            model.country_shortcut = self.parser.parse_country_shortcut()

            model.administrative_area = self.parser.parse_administrative_area()

            model.lat = self.parser.parse_lat()
            model.lng = self.parser.parse_lng()

            model.formatted_address = self.parser.parse_formatted_address()

            if validate(model):
                self.manager.data.add(model)