Ejemplo n.º 1
0
    def get(self):
        zones = DeliveryZone.query().order(
            DeliveryZone.sequence_number).fetch()
        for venue in Venue.query(Venue.active == True).fetch():
            found = False
            for zone in zones:
                if zone.address.city == venue.address.city:
                    if zone.address.street == venue.address.street:
                        if zone.address.home == venue.address.home:
                            found = True

            if not found:
                address = venue.address
                address.lat = venue.coordinates.lat
                address.lon = venue.coordinates.lon
                candidates = get_areas_by_coordinates(address.lat, address.lon)
                if candidates:
                    address.area = candidates[0]['address']['area']
                zone = DeliveryZone(address=address)
                zone.sequence_number = DeliveryZone.generate_sequence_number()
                zone.put()
                for delivery in venue.delivery_types:
                    if delivery.delivery_type == DELIVERY:
                        delivery.delivery_zones = [zone.key]
                venue.put()
                zones.append(zone)
        for zone in zones:
            zone.address_str = zone.address.str()
        self.render('/delivery_settings/delivery_zones.html',
                    zones=zones,
                    ZONE_MAP=DeliveryZone.SEARCH_MAP)
Ejemplo n.º 2
0
    def post(self):
        zone_id = self.request.get_range('zone_id')
        zone = DeliveryZone.get_by_id(zone_id)
        if not zone:
            self.abort(400)
        logging.info(zone)
        polygon = self.request.get('polygon').split(',')
        polygon = [point for point in polygon if point]
        logging.info(polygon)

        def get_point(index):
            lat = float(polygon[index])
            index += 1
            lon = float(polygon[index])
            index += 1
            point = GeoPt(lat=lat, lon=lon)
            return point, index

        i = 0
        old_point = None
        ribs = []
        while i < len(polygon):
            point, i = get_point(i)
            if old_point:
                ribs.append(GeoRib(point1=old_point, point2=point))
            old_point = point
        zone.geo_ribs = ribs
        logging.info(ribs)
        zone.put()
        self.redirect('/company/delivery/zone/list')
Ejemplo n.º 3
0
 def post(self):
     zones = DeliveryZone.query().fetch()
     for zone in zones:
         confirmed = bool(self.request.get(str(zone.key.id())))
         if confirmed:
             zone.status = STATUS_AVAILABLE
         else:
             zone.status = STATUS_UNAVAILABLE
         zone.put()
     self.redirect('/company/main')
Ejemplo n.º 4
0
 def get(self):
     zone_id = self.request.get_range('zone_id')
     zone = DeliveryZone.get_by_id(zone_id)
     if not zone:
         self.abort(400)
     values = {
         'zone': zone,
         'lat': zone.address.lat,
         'lon': zone.address.lon,
         'name': zone.address.str(),
         'coords': zone.polygon
     }
     self.render('/delivery_settings/restriction_map.html', **values)
Ejemplo n.º 5
0
 def post(self):
     zone_id = self.request.get_range('zone_id')
     zone = DeliveryZone.get_by_id(zone_id)
     if not zone:
         self.abort(400)
     zone.search_type = self.request.get_range('search_type')
     zone.value = self.request.get_range('value')
     zone.min_sum = self.request.get_range('min_sum')
     zone.price = self.request.get_range('price')
     zone.comment = self.request.get('comment')
     zone.free_delivery_sum = self.request.get_range('free_delivery_sum')
     zone.put()
     self.redirect('/company/delivery/zone/list')
Ejemplo n.º 6
0
 def get(self):
     zone_id = self.request.get_range('zone_id')
     zone = DeliveryZone.get_by_id(zone_id)
     if not zone:
         self.abort(400)
     search_types = []
     for search_type in DeliveryZone.SEARCH_TYPES:
         search_types.append({
             'name': DeliveryZone.SEARCH_MAP[search_type],
             'value': search_type
         })
     self.render('/delivery_settings/edit_delivery_zones.html',
                 zone=zone,
                 search_types=search_types)
Ejemplo n.º 7
0
 def get(self):
     venue_id = self.request.get_range('venue_id')
     venue = Venue.get_by_id(venue_id)
     if not venue:
         self.abort(400)
     venue_zone_keys = []
     for delivery in venue.delivery_types:
         if delivery.delivery_type == DELIVERY:
             venue_zone_keys = delivery.delivery_zones
     zones = DeliveryZone.query().order(
         DeliveryZone.sequence_number).fetch()
     for zone in zones:
         zone.address_str = zone.address.str()
         if zone.key in venue_zone_keys:
             zone.has = True
         else:
             zone.has = False
     self.render('/venues/choose_zones.html', zones=zones, venue=venue)
Ejemplo n.º 8
0
 def post(self):
     venue_id = self.request.get_range('venue_id')
     venue = Venue.get_by_id(venue_id)
     if not venue:
         self.abort(400)
     found_delivery = None
     for delivery in venue.delivery_types:
         if delivery.delivery_type == DELIVERY:
             found_delivery = delivery
     if not found_delivery:
         self.abort(400)
     zones = DeliveryZone.query().fetch()
     for zone in zones:
         confirmed = bool(self.request.get(str(zone.key.id())))
         if confirmed:
             if zone.key not in found_delivery.delivery_zones:
                 found_delivery.delivery_zones.append(zone.key)
         else:
             if zone.key in found_delivery.delivery_zones:
                 found_delivery.delivery_zones.remove(zone.key)
     venue.put()
     self.redirect('/company/venues')
Ejemplo n.º 9
0
 def post(self):
     zone_id = self.request.get_range('zone_id')
     zone = DeliveryZone.get_by_id(zone_id)
     if not zone:
         self.abort(400)
     next_ = zone.get_next()
     if not next_:
         self.abort(400)
     number = next_.sequence_number
     next_.sequence_number = zone.sequence_number
     zone.sequence_number = number
     zone.put()
     next_.put()
     self.response.headers["Content-Type"] = "application/json"
     self.response.write(
         json.dumps(
             {
                 'success': True,
                 'zone_id': zone.key.id(),
                 'next_id': next_.key.id()
             },
             separators=(',', ':')))
Ejemplo n.º 10
0
 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')
Ejemplo n.º 11
0
    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')
Ejemplo n.º 12
0
    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')
Ejemplo n.º 13
0
    def get(self):
        zones = set()
        deliveries = {}

        city_obj = self.request.city

        if city_obj:
            conditions = Venue.active == True, Venue.address.city == city_obj.city
        else:
            conditions = Venue.active == True,

        logging.debug(city_obj)

        for venue in Venue.fetch_venues(*conditions):
            logging.debug(venue)
            for venue_delivery in venue.delivery_types:
                if venue_delivery.status == STATUS_UNAVAILABLE:
                    continue
                if venue_delivery.delivery_type not in deliveries:
                    deliveries[
                        venue_delivery.delivery_type] = venue_delivery.dict()
                if venue_delivery.delivery_type == DELIVERY:
                    zones.update(venue_delivery.delivery_zones)

        deliveries = fuckup_ios_delivery_types(deliveries.values())
        cities = []
        for zone in sorted([DeliveryZone.get(zone) for zone in list(zones)],
                           key=lambda zone: zone.sequence_number):
            if zone.address.city not in cities:
                cities.append(zone.address.city)
        if config.ANOTHER_CITY_IN_LIST:
            cities.append(u'Другой город')
        version = get_version(self.request.headers.get('Version', 0))
        response = {
            'promo_code_active':
            PromoCode.query(
                PromoCode.status.IN(PROMO_CODE_ACTIVE_STATUS_CHOICES)).get()
            is not None,
            'delivery_types':
            deliveries,
            'cities':
            cities,
            'screen_logic_type':
            config.SCREEN_LOGIC,
            'push_channels':
            get_channels(namespace_manager.get_namespace()),
            'colors': {
                'action': config.ACTION_COLOR,
            },
            'wallet': {
                'enabled': config.WALLET_ENABLED,
            },
            'share_gift': {
                'enabled':
                config.SHARE_GIFT_ENABLED
                or (config.MIVAKO_GIFT_MODULE is not None
                    and config.MIVAKO_GIFT_MODULE.status == STATUS_AVAILABLE)
            },
            'share_invitation': {
                'enabled': config.SHARE_INVITATION_ENABLED,
            },
            'new_version_popup': {
                'show':
                not is_available_version(self.request.headers.get(
                    'Version', 0)),
                'version':
                version.dict() if version else None
            },
            'cancel_order':
            RestoCompany.get() is not None,
            'back_end':
            config.APP_KIND,
            'pick_venue_at_startup':
            config.PICK_VENUE_AT_STARTUP,
        }
        response.update(config.get_company_dict())
        self.render_json(response)