Example #1
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     self.render(
         '/promos/conflicts.html',
         main_promo=promo,
         promos=Promo.query(Promo.status == STATUS_AVAILABLE).fetch())
Example #2
0
 def post(self):
     promo_id = self.request.get_range('promo_id')
     main_promo = Promo.get_by_id(promo_id)
     if not main_promo:
         self.abort(400)
     conflicts = []
     for promo in Promo.query(Promo.status == STATUS_AVAILABLE).fetch():
         confirmed = bool(self.request.get('%s' % promo.key.id()))
         if confirmed:
             conflicts.append(promo.key)
     main_promo.conflicts = conflicts
     main_promo.put()
     self.redirect('/company/promos/list')
Example #3
0
def get_promos():
    resto_company = RestoCompany.get()
    resto_promos = get_resto_promos(resto_company)
    promos = memcache.get('promos_%s' % resto_company.key.id())
    if not promos:
        promos = []
        for index, resto_promo in enumerate(resto_promos['promos']):
            promo = Promo(id=resto_promo['id'])
            promo.title = resto_promo['name']
            promo.description = resto_promo['description']
            promo.priority = index
            promos.append(promo)
        memcache.set('promos_%s' % resto_company.key.id(), promos, time=3600)
    return promos
def addpromo(user_id):
    """ Add Promo route. Adds clip to whatever the current show that is being edited. """
    error = None
    current_user = Users.query.filter_by(id=user_id).first()
    form = NewPromoForm()
    if request.method == "POST" and form.validate_on_submit():
        storage = GoogleStorage()
        try:
            current_user = Users.query.filter_by(id=user_id).first()
            fn = secure_filename(form.clip_file.data.filename)
            url = storage.upload_promo_video(name=fn, file=form.clip_file.data)

            # save vid and get still from it
            form.clip_file.data.save('/tmp/{}'.format(fn))
            image_path = screencap_from_video("/tmp/{}".format(fn))
            still_url = storage.upload_promo_image(
                name=image_path.split("/")[-1], image_data=open(image_path).read())

            current_user.promos.append(Promo(
                name=form.promo_name.data,
                description=form.description.data,
                clip_url=url,
                image_url=still_url,
            ))

            db.session.commit()
        except Exception as err:
            db.session.rollback()
            if 'duplicate key value violates unique constraint' in str(e):
                error = 'show name already registered.'
        flash("Promo Created.", category="success")
    return render_template("admin/addpromo.html", form=form, error=error, current_user=current_user)
Example #5
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     days = []
     for day in DaySchedule.DAYS:
         days.append({
             'name': DaySchedule.DAY_MAP[day],
             'value': day,
             'exist': False,
             'start': '00:00',
             'end': '00:00'
         })
     methods = []
     for condition in PromoCondition.CHOICES:
         if condition in [
                 PromoCondition.CHECK_HAPPY_HOURS,
                 PromoCondition.CHECK_HAPPY_HOURS_CREATED_TIME
         ]:
             methods.append({
                 'name': CONDITION_MAP[condition],
                 'value': condition
             })
     self.render('/schedule.html', **{
         'promo': promo,
         'days': days,
         'methods': methods
     })
Example #6
0
def _get_promos(venue):
    promos = []
    for promo in Promo.query(
            Promo.status == STATUS_AVAILABLE).order(-Promo.priority).fetch():
        if promo not in venue.promo_restrictions:
            promos.append(promo)
    return promos
Example #7
0
def test_get_from_hash():
    eig_1 = Eig(name="eig 1", project="project 1")
    eig_2 = Eig(name="eig 2", project="project 2")
    promo = Promo(promo_number=1, eigs=[eig_1, eig_2])
    done = True
    meeting = Meeting(eig_1=eig_1, eig_2=eig_2, done=done)
    hash = f"{eig_1.get_hash()}_{eig_2.get_hash()}"
    meeting_from_hash = Meeting.get_from_hash(meeting_hash=hash,
                                              promo=promo,
                                              done=done)
    assert meeting == meeting_from_hash
Example #8
0
 def post(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     condition = PromoCondition()
     condition.method = self.request.get_range('method')
     condition.value = self.request.get_range('value')
     condition.item_details = PromoMenuItem()
     promo.conditions.append(condition)
     promo.put()
     self.redirect('/company/promos/list')
def addloop():
    error = None
    trends = Channel.query.order_by(Channel.id.desc()).limit(10).all()
    entertainments = Channel.query.order_by(Channel.id.desc()).filter(
        (Channel.category).like('Entertainment')).all()
    sports = Channel.query.order_by(Channel.id.desc()).filter(
        (Channel.category).like('Sports')).all()
    news = Channel.query.order_by(Channel.id.desc()).filter(
        (Channel.category).like('News')).all()
    form = DashNewPromoForm()
    if request.method == "POST" and form.validate_on_submit():
        storage = GoogleStorage()
        try:
            # Get secure filename from file data.
            fn = secure_filename(form.promo_file.data.filename)
            # Save file locally.
            form.promo_file.data.save('/tmp/' + fn)
            # Get frame from 5 seconds into video and save it locally.
            image_path = screencap_from_video("/tmp/{}".format(fn))

            # save video locally
            url = storage.upload_promo_video(name=fn, file=open("/tmp/" + fn))

            screencap_url = storage.upload_promo_image(
                name=image_path.split("/")[-1],
                image_data=open(image_path).read())

            current_user.promos.append(
                Promo(
                    name=form.promo_name.data,
                    description=form.description.data,
                    clip_url=url,
                    image_url=screencap_url,
                ))

            db.session.commit()
            flash("Promo created successfully.", category="success")

        except Exception as err:
            print(err)
            logging.error("error uploading new loop: {} {}".format(
                type(err), err))
            flash("Error creating new loop. Please try again in a few minutes",
                  category="error")
    return render_template("dashboard/addloop.html",
                           form=form,
                           error=error,
                           current_user=current_user,
                           trends=trends,
                           entertainments=entertainments,
                           sports=sports,
                           news=news)
Example #10
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     methods = []
     for condition in PromoOutcome.CHOICES:
         methods.append({
             'name': OUTCOME_MAP[condition],
             'value': condition
         })
     methods = sorted(methods, key=lambda method: method['name'])
     self.render('/promos/add_condition_or_outcome.html',
                 promo=promo,
                 methods=methods)
Example #11
0
    def post(self):
        promo_id = self.request.get_range('promo_id')
        promo = Promo.get_by_id(promo_id)
        if not promo:
            self.abort(400)
        outcome = PromoOutcome()
        outcome.method = self.request.get_range('method')
        outcome.value = self.request.get_range('value')
        outcome.item_details = PromoMenuItem()

        outcome.error_message = self.request.get('error_message')

        promo.outcomes.append(outcome)
        promo.put()
        self.redirect('/company/promos/list')
Example #12
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     methods = []
     for condition in PromoCondition.CHOICES:
         if condition == PromoCondition.CHECK_HAPPY_HOURS:
             continue
         methods.append({
             'name': CONDITION_MAP[condition],
             'value': condition
         })
     methods = sorted(methods, key=lambda method: method['name'])
     self.render('/promos/add_condition_or_outcome.html',
                 promo=promo,
                 methods=methods)
Example #13
0
 def post(self):
     for promo in Promo.query().fetch():
         confirmed_status = bool(
             self.request.get('status_%s' % promo.key.id()))
         confirmed_visible = bool(
             self.request.get('visible_%s' % promo.key.id()))
         if not confirmed_status:
             confirmed_visible = False
         if confirmed_status:
             promo.status = STATUS_AVAILABLE
         else:
             promo.status = STATUS_UNAVAILABLE
         if confirmed_visible:
             promo.visible = STATUS_AVAILABLE
         else:
             promo.visible = STATUS_UNAVAILABLE
         promo.put()
     self.redirect('/company/promos/list')
Example #14
0
 def get(self):
     client_id = self.request.get('client_id') or int(
         self.request.headers.get('Client-Id') or 0)
     if client_id:
         client_id = int(client_id)
         client = Client.get(client_id)
         if not client:
             self.abort(400)
     gift_items = [
         gift.dict() for gift in GiftMenuItem.query(
             GiftMenuItem.status == STATUS_AVAILABLE).order(
                 GiftMenuItem.points).fetch()
     ]
     share_items = [gift.dict() for gift in SharedGiftMenuItem.query(SharedGiftMenuItem.status == STATUS_AVAILABLE).fetch()] \
         if config.SHARE_GIFT_MODULE and config.SHARE_GIFT_MODULE.status else []
     promo_texts = []
     promo_dicts = []
     for promo in sorted(
             Promo.query_promos(Promo.status == STATUS_AVAILABLE),
             key=lambda query_promo: -query_promo.priority):
         if not promo.visible or promo.hide_in_list:
             continue
         text = u'%s_%s' % (promo.title.strip() if promo.title else u'',
                            promo.description.strip()
                            if promo.description else u'')
         if text not in promo_texts:
             promo_texts.append(text)
             promo_dicts.append(promo.dict(self.request.host))
     self.render_json({
         'wallet': {
             'enable': config.WALLET_ENABLED,
             'text': self.WALLET_TEXT
         },
         'promos': promo_dicts,
         'bonuses': {
             'items': gift_items,
             'text': self.BONUS_TEXT
         },
         'shares': {
             'items': share_items
         }
     })
Example #15
0
 def post(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     promo.title = self.request.get('name')
     promo.description = self.request.get('description')
     promo.image = self.request.get('image')
     start = self.request.get('start')
     if start:
         promo.start = datetime.strptime(start, HTML_STR_TIME_FORMAT)
     else:
         promo.start = None
     end = self.request.get('end')
     if end:
         promo.end = datetime.strptime(end, HTML_STR_TIME_FORMAT)
     else:
         promo.end = None
     promo.put()
     self.redirect('/company/promos/list')
Example #16
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     feature_type = self.request.get_range('feature_type')
     if feature_type not in FEATURES_TYPES:
         self.abort(400)
     number = self.request.get_range('number')
     if feature_type == OUTCOME:
         if len(promo.outcomes) <= number:
             self.abort(400)
         feature = promo.outcomes[number]
         feature_name = OUTCOME_MAP[feature.method]
     elif feature_type == CONDITION:
         if len(promo.conditions) <= number:
             self.abort(400)
         feature = promo.conditions[number]
         feature_name = CONDITION_MAP[feature.method]
     else:
         feature_name = u'Не найдено'
         feature = None
     categories = MenuCategory.query().fetch()
     for category in categories:
         items = []
         for item in category.get_items():
             if item.key == feature.item_details.item:
                 item.has = True
             else:
                 item.has = False
             items.append(item)
         category.items = items
     self.render(
         '/promos/choose_product.html', **{
             'categories': categories,
             'promo': promo,
             'feature': feature,
             'feature_name': feature_name,
             'feature_number': number,
         })
Example #17
0
 def post(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     next_ = promo.get_next()
     if not next_:
         self.abort(400)
     number = next_.priority
     next_.priority = promo.priority
     promo.priority = number
     promo.put()
     next_.put()
     self.response.headers["Content-Type"] = "application/json"
     self.response.write(
         json.dumps(
             {
                 'success': True,
                 'promo_id': promo.key.id(),
                 'next_id': next_.key.id()
             },
             separators=(',', ':')))
Example #18
0
 def post(self):
     item_id = self.request.get('product_id')
     choice_ids = []
     if item_id:
         item = MenuItem.get_by_id(int(item_id))
         for modifier in item.group_modifiers:
             modifier = modifier.get()
             choice_id = self.request.get_range(
                 'modifier_%s_%s' % (item.key.id(), modifier.key.id()))
             if choice_id:
                 choice = modifier.get_choice_by_id(choice_id)
                 if choice:
                     choice_ids.append(choice_id)
     else:
         item = None
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     feature_type = self.request.get_range('feature_type')
     if feature_type not in FEATURES_TYPES:
         self.abort(400)
     number = self.request.get_range('number')
     feature = None
     if feature_type == OUTCOME:
         if len(promo.outcomes) <= number:
             self.abort(400)
         feature = promo.outcomes[number]
     elif feature_type == CONDITION:
         if len(promo.conditions) <= number:
             self.abort(400)
         feature = promo.conditions[number]
     if item:
         feature.item_details.item = item.key
         feature.item_details.group_choice_ids = choice_ids
     else:
         feature.item_details.item = None
     promo.put()
     self.redirect('/company/promos/list')
Example #19
0
 def get(self):
     result_text = u''
     for namespace in metadata.get_namespaces():
         namespace_manager.set_namespace(namespace)
         text = u''
         for promo in Promo.query().fetch():
             if promo.status == STATUS_AVAILABLE:
                 if promo.end and datetime.utcnow() >= promo.end:
                     promo.status = STATUS_UNAVAILABLE
                     promo.put()
                     text += u'\nАкция "%s" была выключена' % promo.title
             if promo.status == STATUS_UNAVAILABLE:
                 if promo.start and promo.start <= datetime.utcnow():
                     if promo.end and datetime.utcnow() >= promo.end:
                         continue
                     promo.status = STATUS_AVAILABLE
                     promo.visible = True
                     promo.put()
                     text += u'\nАкция "%s" была включена' % promo.title
         if text:
             result_text += u'В компании %s: %s' % (namespace, text)
     if result_text:
         namespace_manager.set_namespace('')
         admins.send_error('Promos', 'Promos has been updated', result_text)
Example #20
0
 def post(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     days = []
     for day in DaySchedule.DAYS:
         confirmed = bool(self.request.get(str(day)))
         if confirmed:
             start = datetime.strptime(self.request.get('start_%s' % day),
                                       STR_TIME_FORMAT)
             end = datetime.strptime(self.request.get('end_%s' % day),
                                     STR_TIME_FORMAT)
             days.append(
                 DaySchedule(weekday=day,
                             start=start.time(),
                             end=end.time()))
     schedule = Schedule(days=days)
     condition = PromoCondition()
     condition.method = self.request.get_range('method')
     condition.schedule = schedule
     promo.conditions.append(condition)
     promo.put()
     self.redirect('/company/promos/list')
Example #21
0
 def get(self):
     promos = Promo.query().order(-Promo.priority).fetch()
     for promo in promos:
         if promo.start:
             promo.start_str = promo.start.strftime(STR_DATETIME_FORMAT)
         else:
             promo.start_str = u'Не задано'
         if promo.end:
             promo.end_str = promo.end.strftime(STR_DATETIME_FORMAT)
         else:
             promo.end_str = u'Не задано'
         conditions = []
         for condition in promo.conditions[:]:
             if condition.item_details and condition.item_details.item:
                 choice_titles = []
                 for choice_id in condition.item_details.group_choice_ids:
                     choice = GroupModifier.get_modifier_by_choice(
                         choice_id).get_choice_by_id(choice_id)
                     choice_titles.append(choice.title)
                 condition.item_details.title = condition.item_details.item.get(
                 ).title
                 if choice_titles:
                     condition.item_details.title += u'(%s)' % u', '.join(
                         choice_titles)
             condition.value_string = str(
                 condition.value) if condition.value else ""
             if condition.method == PromoCondition.CHECK_TYPE_DELIVERY:
                 condition.value_string = DELIVERY_MAP[condition.value]
                 conditions.append(condition)
             elif condition.method in [
                     PromoCondition.CHECK_HAPPY_HOURS,
                     PromoCondition.CHECK_HAPPY_HOURS_CREATED_TIME
             ]:
                 for day in (condition.schedule.days
                             if condition.schedule else []):
                     new_condition = PromoCondition(method=condition.method)
                     new_condition.value_string = day.str()
                     conditions.append(new_condition)
             else:
                 conditions.append(condition)
         for outcome in promo.outcomes[:]:
             if outcome.item_details and outcome.item_details.item:
                 choice_titles = []
                 for choice_id in outcome.item_details.group_choice_ids:
                     choice = GroupModifier.get_modifier_by_choice(
                         choice_id).get_choice_by_id(choice_id)
                     choice_titles.append(choice.title)
                 outcome.item_details.title = outcome.item_details.item.get(
                 ).title
                 if choice_titles:
                     outcome.item_details.title += u'(%s)' % u', '.join(
                         choice_titles)
         promo.conditions = conditions
     self.render(
         '/promos/list.html', **{
             'promo_api_key':
             config.PROMOS_API_KEY if config.PROMOS_API_KEY else '',
             'wallet_api_key':
             config.WALLET_API_KEY if config.WALLET_API_KEY else '',
             'promos':
             promos,
             'condition_map':
             CONDITION_MAP,
             'outcome_map':
             OUTCOME_MAP
         })
def promo(eigs):
    return Promo(promo_number=4, eigs=eigs)
Example #23
0
def load_promo(promo_number: int) -> Promo:
    p_csv_file = get_path_promo_file(promo_number=promo_number)
    eigs = load_eigs_from_file(p_csv_file)
    return Promo(promo_number=promo_number, eigs=eigs)
Example #24
0
 def post(self):
     promo = Promo()
     promo.title = self.request.get('name')
     promo.description = self.request.get('description')
     promo.priority = Promo.generate_priority()
     promo.image = self.request.get('image')
     start = self.request.get('start')
     if start:
         promo.start = datetime.strptime(start, HTML_STR_TIME_FORMAT)
     end = self.request.get('end')
     if end:
         promo.end = datetime.strptime(end, HTML_STR_TIME_FORMAT)
     promo.put()
     self.redirect('/company/promos/list')
Example #25
0
 def get(self):
     promo_id = self.request.get_range('promo_id')
     promo = Promo.get_by_id(promo_id)
     if not promo:
         self.abort(400)
     self.render('/promos/add.html', promo=promo)