Пример #1
0
    def post(self):
        def error(description):
            self.render('/notifications/news_add.html', error=description)

        title = self.request.get('title')

        if not title:
            return error(u'Введите заголовок')

        text = self.request.get('text')
        if not text:
            return error(u'Введите текст')
        image_url = self.request.get('image_url')

        send_now = bool(self.request.get('send_now'))
        if send_now:
            start = datetime.utcnow()
        else:
            start = self.request.get('start')
            if start:
                try:
                    start = datetime.strptime(start, HTML_STR_TIME_FORMAT)
                except ValueError:
                    return error(u'Неверное время начала')
            else:
                return error(u'Введите время начала')
            if start < datetime.utcnow():
                return error(u'Введите время больше текущего в utc')

        notification = None
        if self.request.get('send_push'):
            channels = []
            company_namespace = namespace_manager.get_namespace()

            company_channel = get_channels(company_namespace)[COMPANY_CHANNEL]
            channels.append(Channel(name=u'Всем', channel=company_channel))
            for venue in Venue.query(Venue.active == True).fetch():
                if self.request.get(str(venue.key.id())):
                    venue_channel = get_channels(company_namespace)[VENUE_CHANNEL]
                    channels.append(Channel(name=venue.title, channel=venue_channel))
            notification = Notification(start=start, text=text, header=title, channels=channels,
                                    should_popup=False)

        news = News(text=text, title=title, image_url=image_url, start=start, notification=notification)

        news.put()
        new_url = get_new_image_url('News', news.key.id(), url=image_url)
        if new_url:
            news.image_url = new_url
            news.put()
        taskqueue.add(url='/task/news/start', method='POST', eta=start, params={
            'news_id': news.key.id()
        })
        self.redirect('/company/notifications/news/list')
Пример #2
0
    def __init__(self,
                 text,
                 should_popup,
                 header,
                 client=None,
                 namespace=None,
                 channels=None,
                 device_type=None,
                 push_id=None):

        logging.debug(
            u"client: {}, namespace: {}, channels: {}, device_type: {}".format(
                client, namespace, channels, device_type))

        if client is not None and namespace is not None:
            device_type = client.device_type
            client_channel = get_channels(
                namespace)[CLIENT_CHANNEL] % client.key.id()
            self.channels = [client_channel]
            self.device_type = client.device_type

            logging.debug('{}'.format(self.channels))

            super(BaseSimplePush, self).__init__(text, device_type, push_id)

        if channels is not None and device_type is not None:
            super(BaseSimplePush, self).__init__(text, device_type, push_id)
            self.channels = channels
            self.device_type = device_type

        self.should_popup = should_popup
        self.header = header
        self.push_type = None
Пример #3
0
    def post(self):
        def error(description):
            return self.render_template(description)

        text = self.request.get('text')
        if not text:
            return error(u'Введите текст')
        header = self.request.get('header')
        if not header:
            return error(u'Введите заголовок')
        full_text = self.request.get('full_text')
        if not full_text:
            return error(u'Введите полный текст')
        send_now = bool(self.request.get('send_now'))
        if send_now:
            start = datetime.utcnow()
        else:
            start = self.request.get('start')
            if start:
                try:
                    start = datetime.strptime(start, HTML_STR_TIME_FORMAT)
                except ValueError:
                    return error(u'Неверное время отправки')
            else:
                return error(u'Введите время отправки')
        if not send_now and start < datetime.utcnow() + timedelta(seconds=MAX_SECONDS_LOSS):
            return error(u'Введите время больше текущего в utc')
        channels = []
        company_namespace = namespace_manager.get_namespace()
        if self.request.get('company'):
            company_channel = get_channels(company_namespace)[COMPANY_CHANNEL]
            channels.append(Channel(name=u'Всем', channel=company_channel))
        for venue in Venue.query(Venue.active == True).fetch():
            if self.request.get(str(venue.key.id())):
                venue_channel = get_channels(company_namespace)[VENUE_CHANNEL]
                channels.append(Channel(name=venue.title, channel=venue_channel))
        notification = Notification(start=start, text=text, popup_text=full_text, header=header, channels=channels,
                                    should_popup=True)

        notification.put()
        taskqueue.add(url='/task/pushes/start', method='POST', eta=start, params={
            'notification_id': notification.key.id()
        })

        self.redirect('/company/notifications/pushes/list')
Пример #4
0
 def __init__(self, order, push_id):
     client = Client.get(order.client_id)
     device_type = client.device_type
     self.order = order
     self.push_type = REVIEW_TYPE
     text = u'Оставьте отзыв о вашем заказе'
     super(ReviewPush, self).__init__(text, device_type, push_id)
     self.header = u'Оцените заказ'
     self.should_popup = False
     client_channel = get_channels(
         order.key.namespace())[CLIENT_CHANNEL] % client.key.id()
     self.channels = [client_channel]
Пример #5
0
    def __init__(self, text, order, namespace, push_id=None):
        """
        Initializes OrderPush
        :param text: text to put in notification
        :param order: order which info have to be pushed
        """
        from methods.fuckups import fuckup_order_channel

        super(OrderPush, self).__init__(text, order.device_type, push_id)
        self.order = order
        self.should_popup = True
        self.push_type = ORDER_TYPE
        self.header = u'Заказ %s' % self.order.key.id()

        order_channel = get_channels(
            namespace)[ORDER_CHANNEL] % self.order.key.id()
        order_channel = fuckup_order_channel(order_channel, self.order)
        self.channels = [order_channel]
Пример #6
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)