Beispiel #1
0
 def add_promo_code_helper(session, code, description, expiration_time,
                           rules):
     pc = PromoCode(code=code,
                    description=description,
                    expiration_time=expiration_time,
                    rules=rules)
     session.add(pc)
     return pc.code
Beispiel #2
0
 def add_codes_helper(sess, chunk, n):
     codes = []
     for i in range(chunk, min(chunk + chunk_size, num_codes)):
         code = "_".join(datagen.words(nb=3)) + "_" + str(time.time())
         codes.append(PromoCode(code=code,
                                description=datagen.paragraph(),
                                expiration_time=datetime.datetime.now(
                                ) + datetime.timedelta(days=random.randint(0, 30)),
                                rules={"type": "percent_discount", "value": "10%"}))
     sess.bulk_save_objects(codes)
def create_promo_code():
    """
    Allows admin to create Promo Code for User's discount
    :param promo_code:
    :param promo_value:
    :param promo_max_usage:
    :param promo_valid:
    :param promo_multiple_use:
    :return:
    """
    req = request.get_json()
    try:
        promo_code = PromoCode(**req)
        db.session.add(promo_code)
        db.session.commit()
        return ""
    except exc.IntegrityError:
        return Error('Promo Code already exists', 400)()
Beispiel #4
0
def promocode():
    if current_user.is_activated == False:
        return redirect(url_for('home'))

    if request.method == 'POST':
        name = request.form.get('name')
        type = request.form.get('type')
        amount = request.form.get('amount')
        code_check = PromoCode.query.filter_by(name=name).first()
        if code_check:
            flash("This code exists!", "danger")
            return redirect(url_for('promocode'))

        promocode = PromoCode(name=name, type=type, value=amount)
        db.session.add(promocode)
        db.session.commit()
        return redirect(url_for('home'))

    return render_template('promocode.html')