def post(self): coordinates_str = self.request.get('coordinates') min_sum = self.request.get_range('min_sum') delivery_sum = self.request.get_range('delivery_sum') free_delivery_sum = self.request.get_range('free_delivery_sum') coordinates = ast.literal_eval(coordinates_str) ribs_num = len(coordinates) - 1 delivery_zone = DeliveryZone() delivery_zone.sequence_number = DeliveryZone.generate_sequence_number() geo_ribs = [] for i in range(0, ribs_num - 1): start_point = coordinates[i] end_point = coordinates[i + 1] geo_rib = GeoRib() geo_rib.point1 = GeoPt(lat=start_point[1], lon=start_point[0]) geo_rib.point2 = GeoPt(lat=end_point[1], lon=end_point[0]) geo_ribs.append(geo_rib) start_point = coordinates[ribs_num - 1] end_point = coordinates[0] last_rib = GeoRib() logging.debug('start_point: {}'.format(coordinates)) last_rib.point1 = GeoPt(lat=start_point[1], lon=start_point[0]) last_rib.point2 = GeoPt(lat=end_point[1], lon=end_point[0]) delivery_zone.geo_ribs = geo_ribs lat, lon = get_mean_coordinate(geo_ribs) candidates = get_cities_by_coordinates(lat, lon) if candidates: logging.critical('CANDIDATES') address = candidates[0]['address'] address_obj = Address(**address) address_obj.lat = lat address_obj.lon = lon candidates = get_areas_by_coordinates(lat, lon) if candidates: address_obj.area = candidates[0]['address']['area'] delivery_zone.address = address_obj delivery_zone.search_type = ZONE delivery_zone.price = delivery_sum delivery_zone.min_sum = min_sum delivery_zone.free_delivery_sum = free_delivery_sum delivery_zone.put() self.redirect('/company/delivery/zone/list')
def get(self): lat = float(self.request.get('lat')) lon = float(self.request.get('lon')) candidates = get_cities_by_coordinates(lat, lon) if candidates: address = candidates[0]['address'] address_obj = Address(**address) address_obj.lat = lat address_obj.lon = lon candidates = get_areas_by_coordinates(lat, lon) if candidates: address_obj.area = candidates[0]['address']['area'] zone = DeliveryZone(address=address_obj) zone.sequence_number = DeliveryZone.generate_sequence_number() zone.put() self.redirect('/company/delivery/zone/list') else: self.redirect('/company/delivery/zone/add_by_map')
def add_address(object, id): """ Ajout une address dans la base de données et retourne la clé de l'adresse """ if id is not None and id != "": cle = ndb.Key("Address", long(id)) newUserAddress = cle.get() if newUserAddress is None: newUserAddress = Address() else: newUserAddress = Address() newUserAddress.civicNo = object["civicNo"] newUserAddress.routeName = object["routeName"] newUserAddress.postalCode = object["postalCode"] newUserAddress.appartNo = object["appartNo"] newUserAddress.long = object["long"] newUserAddress.lat = object["lat"] return newUserAddress.put() newUser.idAddress = newUserAddress.put().id()
def post(self): js_url = self.request.get('js_file') js_text = self.request.get('js_text') if js_text: pass elif js_url: js_text = urlfetch.fetch(js_url).content else: pass json_dict = get_json_from_js(js_text) self.response.content_type = 'application/json' delivery_maps = json_dict['maps'] # self.response.write(json.dumps(delivery_maps)) for delivery_map in delivery_maps: geo_objects = delivery_map['geoObjects'] zones = geo_objects['features'] self.response.write(json.dumps(zones)) for zone in zones: geometry = zone['geometry'] properties = zone['properties'] zone_name = properties['name'] zone_decription = properties['description'] coordinates_array = geometry['coordinates'] type = geometry['type'] if type == 'Polygon': delivery_coordinates = coordinates_array[0] elif type == 'LineString': delivery_coordinates = coordinates_array ribs_num = len(delivery_coordinates) - 1 delivery_zone = DeliveryZone() delivery_zone.sequence_number = DeliveryZone.generate_sequence_number( ) delivery_zone.comment = u'Name: {0}, description: {1}:'.format( zone_name, zone_decription) geo_ribs = [] for i in range(0, ribs_num - 1): start_point = delivery_coordinates[i] end_point = delivery_coordinates[i + 1] geo_rib = GeoRib() geo_rib.point1 = GeoPt(lat=start_point[1], lon=start_point[0]) geo_rib.point2 = GeoPt(lat=end_point[1], lon=end_point[0]) geo_ribs.append(geo_rib) start_point = delivery_coordinates[ribs_num - 1] end_point = delivery_coordinates[0] last_rib = GeoRib() logging.debug('start_point: {}'.format(delivery_coordinates)) last_rib.point1 = GeoPt(lat=start_point[1], lon=start_point[0]) last_rib.point2 = GeoPt(lat=end_point[1], lon=end_point[0]) delivery_zone.geo_ribs = geo_ribs lat, lon = get_mean_coordinate(geo_ribs) candidates = get_cities_by_coordinates(lat, lon) if candidates: logging.critical('CANDIDATES') address = candidates[0]['address'] address_obj = Address(**address) address_obj.lat = lat address_obj.lon = lon candidates = get_areas_by_coordinates(lat, lon) if candidates: address_obj.area = candidates[0]['address']['area'] delivery_zone.address = address_obj delivery_zone.put() self.redirect('/company/delivery/zone/list')