コード例 #1
0
def admin_drink_edit(id):

    saved = int(request.args.get('saved', "0"))

    class F(DrinkForm):
        pass

    boozes = db.session.query(Booze).order_by(Booze.id).all()
    booze_list = [(b.id, b.name) for b in boozes]

    sorted_booze_list = sorted(booze_list, key=itemgetter(1))
    drink = Drink.query.filter_by(id=int(id)).first()

    # convert size to fl oz
    drink.sugg_size = drink.sugg_size / constant.ML_PER_FL_OZ

    kwargs = {}
    fields = []
    null_drink_booze = DrinkBooze(Drink("dummy"), boozes[0], 0, 0)
    for i in xrange(MAX_BOOZES_PER_DRINK):
        if i < len(drink.drink_boozes):
            booze = drink.drink_boozes[i]
            show = 1
        else:
            booze = null_drink_booze
            show = 0

        bf = "booze_name_%d" % i
        bp = "booze_parts_%d" % i
        dbi = "drink_booze_id_%d" % i
        setattr(F, bf, SelectField("booze", choices=sorted_booze_list))
        setattr(
            F, bp,
            DecimalField("parts", [validators.NumberRange(min=1, max=100)],
                         places=0))
        setattr(F, dbi, HiddenField("id"))
        kwargs[bf] = booze.booze.name
        kwargs[bp] = booze.value
        kwargs[dbi] = booze.id
        fields.append((bf, bp, dbi, show))

    form = F(obj=drink, drink_name=drink.name.name, **kwargs)
    for i, booze in enumerate(drink.drink_boozes):
        form["booze_name_%d" %
             i].data = "%d" % booze_list[booze.booze_id - 1][0]
    drinks = db.session.query(Drink).join(DrinkName).filter(Drink.name_id == DrinkName.id) \
                                 .order_by(DrinkName.name).all()
    return render_template("admin/drink",
                           drinks=drinks,
                           form=form,
                           fields=fields,
                           title="Drinks",
                           saved=saved)
コード例 #2
0
def admin_drink():
    drinks = db.session.query(Drink).join(DrinkName).filter(Drink.name_id == DrinkName.id) \
                                 .order_by(DrinkName.name).all()

    class F(DrinkForm):
        pass

    boozes = db.session.query(Booze).order_by(Booze.id).all()
    booze_list = [(b.id, b.name) for b in boozes]
    sorted_booze_list = sorted(booze_list, key=itemgetter(1))
    fields = []
    kwargs = {}
    null_drink_booze = DrinkBooze(Drink("dummy"), boozes[0], 0, 0)
    for i in xrange(MAX_BOOZES_PER_DRINK):
        booze = null_drink_booze
        show = 0

        bf = "booze_name_%d" % i
        bp = "booze_parts_%d" % i
        dbi = "drink_booze_id_%d" % i
        setattr(F, bf, SelectField("booze", choices=sorted_booze_list))
        setattr(
            F, bp,
            DecimalField("parts", [validators.NumberRange(min=1, max=100)],
                         places=0))
        setattr(F, dbi, HiddenField("id"))
        kwargs[bf] = booze.booze.name
        kwargs[bp] = booze.value
        kwargs[dbi] = booze.id
        fields.append((bf, bp, dbi, show))
    form = F(**kwargs)

    return render_template("admin/drink",
                           fields=fields,
                           drinks=drinks,
                           form=form,
                           title="Drinks")
コード例 #3
0
ファイル: drink.py プロジェクト: npahucki/peesco-8
def admin_drink_save():

    cancel = request.form.get("cancel")
    if cancel: return redirect('/admin/drink')

    form = DrinkForm(request.form)
    if request.method == 'POST' and form.validate():
        id = int(request.form.get("id") or '0')
        if id:
            drink = Drink.query.filter_by(id=int(id)).first()
        else:
            drink = Drink()
            db.session.add(drink)

        drink.name.name = form.data['drink_name']
        drink.desc = form.data['desc']
        drink.popular = form.data['popular']
        drink.available = form.data['available']

        for i in xrange(MAX_BOOZES_PER_DRINK):
            try:
                parts = request.form['booze_parts_%d' % i]
                parts = int(parts)
            except KeyError:
                parts = -1

            try:
                dbi = int(request.form['drink_booze_id_%d' % i] or "-1")
                dbi = int(dbi)
            except KeyError:
                dbi = -1

            try:
                dbn = int(request.form['booze_name_%d' % i] or "-1")
                dbn = int(dbn)
            except KeyError:
                dbn = -1

            if parts == 0:
                if dbi != 0:
                    for i, dbooze in enumerate(drink.drink_boozes):
                        if dbooze.id == dbi:
                            db.session.delete(drink.drink_boozes[i])
                            break
                continue

            if dbi > 0:
                for dbooze in drink.drink_boozes:
                    if dbi == dbooze.id:
                        dbooze.value = parts
                        newid = dbn
                        if (newid != dbooze.booze_id):
                            dbooze.booze = Booze.query.filter_by(id=newid).first()
                        break

            else:
                booze = Booze.query.filter_by(id=dbn).first()
                DrinkBooze(drink, booze, parts, 0)

        db.session.commit()
        mc = app.mc
        mc.delete("top_drinks")
        mc.delete("other_drinks")
        mc.delete("available_drink_list")
        return redirect('/admin/drink/edit/%d?saved=1' % drink.id)

    drinks = db.session.query(Drink).join(DrinkName).filter(Drink.name_id == DrinkName.id) \
                                 .order_by(DrinkName.name).all()
    return render_template("admin/drink", drinks=drinks, form=form, title="")
コード例 #4
0
ファイル: root.py プロジェクト: chriswhsu/bartendro
def index():
    if app.globals.get_state() == fsm.STATE_ERROR:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro is in trouble!<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")

    try:
        can_make = app.mixer.get_available_drink_list()
    except OperationalError:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro database errror.<br/><br/>There doesn't seem to be a valid database installed.",
                               title="Bartendro error")

    can_make_dict = {}
    for drink in can_make:
        can_make_dict[drink] = 1

    top_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 1)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 

    top_drinks = filter_drink_list(can_make_dict, top_drinks)
    process_ingredients(top_drinks)

    other_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 0)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 
    other_drinks = filter_drink_list(can_make_dict, other_drinks)
    process_ingredients(other_drinks)

    print "%d, %d" % (len(top_drinks), len(other_drinks))

    if (not len(top_drinks) and not len(other_drinks)) or app.globals.get_state() == fsm.STATE_HARD_OUT:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Drinks can't be made with the available boozes.<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")
            
    if app.options.show_feeling_lucky:
        lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        lucky.name = DrinkName("I'm feeling lucky!")
        # Todo: This generates an error with 'Drink' conflicting with a persistent drink?
        # FlushError: New instance <Drink at 0x10adcc710> with identity key (<class 'bartendro.model.drink.Drink'>, (54,)) conflicts with persistent instance <Drink at 0x10adf7990>
        #lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
        lucky.set_lucky(True)
        lucky.set_ingredients_text("Pour a random drink now (possibly broken see root.py line 88")
        top_drinks.insert(0, lucky)

        #lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        #lucky.name = DrinkName("I'm feeling lucky!")
        #lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
	#lucky.id = 1
        #lucky.set_lucky(True)
        #lucky.set_ingredients_text("Pour a random drink now")
        #top_drinks.insert(0, lucky)
	# Todo: I'm feeling lucky is broken for me.

    return render_template("index", 
                           options=app.options, 
                           top_drinks=top_drinks, 
                           other_drinks=other_drinks,
                           title="Bartendro")
コード例 #5
0
ファイル: drink.py プロジェクト: joshrenner/bartendro
def ws_drink_save(drink):

    data = request.json["drink"]
    id = int(data["id"] or 0)
    if id > 0:
        drink = Drink.query.filter_by(id=int(id)).first()
    else:
        id = 0
        drink = Drink()
        db.session.add(drink)

    try:
        drink.name.name = data["name"]
        drink.desc = data["desc"]
        if data["popular"]:
            drink.popular = True
        else:
            drink.popular = False

        if data["available"]:
            drink.available = True
        else:
            drink.available = False
    except ValueError:
        raise BadRequest

    for selected_booze_id, parts, old_booze_id in data["boozes"]:
        try:
            selected_booze_id = int(selected_booze_id)  # this is the id that comes from the most recent selection
            old_booze_id = int(old_booze_id)  # this id is the id that was previously used by this slot. Used for
            # cleaning up or updateing existing entries
            parts = int(parts)
        except ValueError:
            raise BadRequest

        # if the parts are set to zero, remove this drink_booze from this drink
        if parts == 0:
            if old_booze_id != 0:
                for i, dbooze in enumerate(drink.drink_boozes):
                    if dbooze.booze_id == old_booze_id:
                        db.session.delete(drink.drink_boozes[i])
                        break
            continue

        # if there is an old_booze_id, then update the existing entry
        if old_booze_id > 0:
            for drink_booze in drink.drink_boozes:
                if old_booze_id == drink_booze.booze_id:
                    drink_booze.value = parts
                    if selected_booze_id != drink_booze.booze_id:
                        drink_booze.booze = Booze.query.filter_by(id=selected_booze_id).first()
                    break
        else:
            # Create a new drink-booze entry
            booze = Booze.query.filter_by(id=selected_booze_id).first()
            DrinkBooze(drink, booze, parts, 0)

    db.session.commit()
    mc = app.mc
    mc.delete("top_drinks")
    mc.delete("other_drinks")
    mc.delete("available_drink_list")

    return drink_load(drink.id)
コード例 #6
0
ファイル: root.py プロジェクト: joshrenner/bartendro
def index():
    if app.globals.get_state() == STATE_ERROR:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro is in trouble!<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")

    try:
        can_make = app.mixer.get_available_drink_list()
    except OperationalError:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro database errror.<br/><br/>There doesn't seem to be a valid database installed.",
                               title="Bartendro error")
        


    if not len(can_make):
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Drinks can't be made with the available boozes.<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")

    can_make_dict = {}
    for drink in can_make:
        can_make_dict[drink] = 1

    top_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 1)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 
    top_drinks = filter_drink_list(can_make_dict, top_drinks)
    process_ingredients(top_drinks)

    if app.options.show_feeling_lucky:
        lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        lucky.name = DrinkName("I'm feeling lucky!")
        lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
        lucky.set_lucky(True)
        lucky.set_ingredients_text("Pour a random drink now")
        top_drinks.insert(0, lucky)

    other_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 0)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 
    other_drinks = filter_drink_list(can_make_dict, other_drinks)
    process_ingredients(other_drinks)
            
    return render_template("index", 
                           options=app.options, 
                           top_drinks=top_drinks, 
                           other_drinks=other_drinks,
                           title="Bartendro")
コード例 #7
0
def ws_drink_save(drink):

    data = request.json['drink']
    id = int(data["id"] or 0)
    if id > 0:
        drink = Drink.query.filter_by(id=int(id)).first()
    else:
        id = 0
        drink = Drink()
        db.session.add(drink)

    try:
        drink.name.name = data['name']
        drink.desc = data['desc']
        if data['popular']:
            drink.popular = True
        else:
            drink.popular = False
            
        if data['available']:
            drink.available = True
        else:
            drink.available = False
    except ValueError:
        raise BadRequest

    for selected_booze_id, parts, old_booze_id in data['boozes']:
        try:
            selected_booze_id = int(selected_booze_id) # this is the id that comes from the most recent selection
            old_booze_id = int(old_booze_id)     # this id is the id that was previously used by this slot. Used for
                                                 # cleaning up or updateing existing entries
            parts = int(parts)                   
        except ValueError:
            raise BadRequest

        # if the parts are set to zero, remove this drink_booze from this drink
        if parts == 0:
            if old_booze_id != 0:
                for i, dbooze in enumerate(drink.drink_boozes):
                    if dbooze.booze_id == old_booze_id:
                        db.session.delete(drink.drink_boozes[i])
                        break
            continue

        # if there is an old_booze_id, then update the existing entry
        if old_booze_id > 0:
            for drink_booze in drink.drink_boozes:
                if old_booze_id == drink_booze.booze_id:
                    drink_booze.value = parts
                    if (selected_booze_id != drink_booze.booze_id):
                        drink_booze.booze = Booze.query.filter_by(id=selected_booze_id).first()
                    break
        else:
            # Create a new drink-booze entry
            booze = Booze.query.filter_by(id=selected_booze_id).first()
            DrinkBooze(drink, booze, parts, 0)

    db.session.commit()
    mc = app.mc
    mc.delete("top_drinks")
    mc.delete("other_drinks")
    mc.delete("available_drink_list")

    return drink_load(drink.id) 
コード例 #8
0
ファイル: root.py プロジェクト: RichGibson/bartendro
def index():
    if app.globals.get_state() == fsm.STATE_ERROR:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro is in trouble!<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")

    try:
        can_make = app.mixer.get_available_drink_list()
    except OperationalError:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro database errror.<br/><br/>There doesn't seem to be a valid database installed.",
                               title="Bartendro error")

    can_make_dict = {}
    for drink in can_make:
        can_make_dict[drink] = 1

    top_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 1)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 

    top_drinks = filter_drink_list(can_make_dict, top_drinks)
    process_ingredients(top_drinks)

    other_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 0)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 
    other_drinks = filter_drink_list(can_make_dict, other_drinks)
    process_ingredients(other_drinks)

    print "%d, %d" % (len(top_drinks), len(other_drinks))

    if (not len(top_drinks) and not len(other_drinks)) or app.globals.get_state() == fsm.STATE_HARD_OUT:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Drinks can't be made with the available boozes.<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")
            
    if app.options.show_feeling_lucky:
        lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        lucky.name = DrinkName("I'm feeling lucky!")
        # Todo: This generates an error with 'Drink' conflicting with a persistent drink?
        # FlushError: New instance <Drink at 0x10adcc710> with identity key (<class 'bartendro.model.drink.Drink'>, (54,)) conflicts with persistent instance <Drink at 0x10adf7990>
        #lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
        lucky.set_lucky(True)
        lucky.set_ingredients_text("Pour a random drink now (possibly broken see root.py line 88")
        top_drinks.insert(0, lucky)

        #lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        #lucky.name = DrinkName("I'm feeling lucky!")
        #lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
	#lucky.id = 1
        #lucky.set_lucky(True)
        #lucky.set_ingredients_text("Pour a random drink now")
        #top_drinks.insert(0, lucky)
	# Todo: I'm feeling lucky is broken for me.

    return render_template("index", 
                           options=app.options, 
                           top_drinks=top_drinks, 
                           other_drinks=other_drinks,
                           title="Bartendro")
コード例 #9
0
ファイル: root.py プロジェクト: fivef/bartendro
def index():
    print("render index")
    if app.globals.get_state() == fsm.STATE_ERROR:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro is in trouble!<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")

    try:
        can_make = app.mixer.get_available_drink_list()
    except OperationalError:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Bartendro database errror.<br/><br/>There doesn't seem to be a valid database installed.",
                               title="Bartendro error")

    can_make_dict = {}
    for drink in can_make:
        can_make_dict[drink] = 1

    top_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 1)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 

    top_drinks = filter_drink_list(can_make_dict, top_drinks)
    process_ingredients(top_drinks)

    other_drinks = db.session.query(Drink) \
                        .join(DrinkName) \
                        .filter(Drink.name_id == DrinkName.id)  \
                        .filter(Drink.popular == 0)  \
                        .filter(Drink.available == 1)  \
                        .order_by(asc(func.lower(DrinkName.name))).all() 
    other_drinks = filter_drink_list(can_make_dict, other_drinks)
    process_ingredients(other_drinks)

    print "%d, %d" % (len(top_drinks), len(other_drinks))

    if (not len(top_drinks) and not len(other_drinks)) or app.globals.get_state() == fsm.STATE_HARD_OUT:
        return render_template("index", 
                               options=app.options, 
                               top_drinks=[], 
                               other_drinks=[],
                               error_message="Drinks can't be made with the available boozes.<br/><br/>I need some attention! Please find my master, so they can make me feel better.",
                               title="Bartendro error")
            
    if app.options.show_feeling_lucky:
        lucky = Drink("<em>Make sure there is a cup under the spout, the drink will pour immediately!</em>")
        lucky.name = DrinkName("I'm feeling lucky!")
        lucky.id = can_make[int(random.randint(0, len(can_make) - 1))]
        lucky.set_lucky(True)
        lucky.set_ingredients_text("Pour a random drink now")
        top_drinks.insert(0, lucky)


    return render_template("index", 
                           options=app.options, 
                           top_drinks=top_drinks, 
                           other_drinks=other_drinks,
                           title="Bartendro",
                           allowed_to_pour=is_ip_allowed_to_pour_drinks(request.remote_addr))
コード例 #10
0
def admin_drink_save():

    cancel = request.form.get("cancel")
    if cancel: return redirect('/admin/drink')

    form = DrinkForm(request.form)
    if request.method == 'POST' and form.validate():
        id = int(request.form.get("id") or '0')
        if id:
            drink = Drink.query.filter_by(id=int(id)).first()
        else:
            drink = Drink()
            db.session.add(drink)

        drink.name.name = form.data['drink_name']
        drink.desc = form.data['desc']
        drink.sugg_size = int(form.data['sugg_size'] * constant.ML_PER_FL_OZ)
        drink.popular = form.data['popular']
        drink.available = form.data['available']

        for i in xrange(MAX_BOOZES_PER_DRINK):
            try:
                parts = request.form['booze_parts_%d' % i]
                parts = int(parts)
            except KeyError:
                parts = -1

            try:
                dbi = int(request.form['drink_booze_id_%d' % i] or "-1")
                dbi = int(dbi)
            except KeyError:
                dbi = -1

            try:
                dbn = int(request.form['booze_name_%d' % i] or "-1")
                dbn = int(dbn)
            except KeyError:
                dbn = -1

            if parts == 0:
                if dbi != 0:
                    for i, dbooze in enumerate(drink.drink_boozes):
                        if dbooze.id == dbi:
                            db.session.delete(drink.drink_boozes[i])
                            break
                continue

            if dbi > 0:
                for dbooze in drink.drink_boozes:
                    if dbi == dbooze.id:
                        dbooze.value = parts
                        newid = dbn
                        if (newid != dbooze.booze_id):
                            dbooze.booze = Booze.query.filter_by(
                                id=newid).first()
                        break

            else:
                booze = Booze.query.filter_by(id=dbn).first()
                DrinkBooze(drink, booze, parts, 0)

        db.session.commit()
        mc = app.mc
        mc.delete("top_drinks")
        mc.delete("other_drinks")
        mc.delete("available_drink_list")
        return redirect('/admin/drink/edit/%d?saved=1' % drink.id)

    drinks = db.session.query(Drink).join(DrinkName).filter(Drink.name_id == DrinkName.id) \
                                 .order_by(DrinkName.name).all()
    return render_template("admin/drink", drinks=drinks, form=form, title="")