Exemple #1
0
def show_mybrews():
    """ Display users brewed recipes, all or by filter. """

    selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(session["user_id"])
    filtered = False

    # Filtered lists
    if request.method == "POST":
        filtered_brews = []
        # Recipe search:
        if request.form.get("recipe"):
            recipe_name = request.form.get("recipe")
            recipe_id = Recipe.query.filter_by(name=recipe_name).one().recipe_id
            all_brews = Brew.query.filter_by(user_id=session["user_id"], recipe_id=recipe_id).all()
            filtered = "Brews of " + recipe_name + ":"

        # Style search:
        if request.form.get("style"):
            style = request.form.get("style")
            all_brews = db.session.query(Brew).join(Brew.recipe).filter_by(style_name=style, user_id=session["user_id"]).all()
            filtered = style + " Style Brews:"

    # Unfiltered list of all brews
    else:
        all_brews = Brew.query.filter_by(user_id=session["user_id"]).all()

    # Add hex color attribute for view
    for brew in all_brews:
        brew.color = color_conversion(brew.recipe.calc_color())

    return render_template("mybrews.html", brewlist=all_brews,
                           filtered=filtered,
                           selectlist_user=selectlist_user,
                           sel_user_styles=sel_user_styles)
Exemple #2
0
def brew_process(brew_id):
    brew = Brew.query.filter_by(id=brew_id).one()
    recipe = Recipe.query.filter_by(recipe_id=brew.recipe_id).one().name
    if request.method == "POST":
        brew_update = update_brew(brew)
        return redirect("/mybrews")
    else:
        recipe, times, timerset, boiltime, steep, yeast, secondary, extracts = show_brew_recipe(
            recipe)
        rating = brew.rating
        c_gravity = brew.cg
        c_gravity_date = brew.cg_date
        color = color_conversion(recipe.srm_color)
    print yeast
    print secondary

    return render_template("brew.html",
                           brew=brew,
                           recipe=recipe,
                           times=times,
                           timerset=timerset,
                           boiltime=boiltime,
                           steep=steep,
                           yeast=yeast,
                           secondary=secondary,
                           extracts=extracts,
                           c_gravity=c_gravity,
                           c_gravity_date=c_gravity_date,
                           rating=rating)
Exemple #3
0
def calculate_color():
    """ Ajax call -Calculate color for recipe """

    data = request.get_json()
    batch_size, batch_units = normalize_batch_size(data["batch_size"], data["units"])

    srm = Fermentable.get_srm_from_ingredient_list(data["grains"], batch_size, batch_units) \
          + Extract.get_srm_from_ingredient_list(data["extracts"], batch_size, batch_units)

    color = color_conversion(srm)
    return color
def get_recipes(recipe):
    selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(session["user_id"])
    deleteable = False
    if Recipe.query.filter_by(name=recipe).one().user_id == session["user_id"]:
        deleteable = True
    name, source, style, batch_size, batch_units, notes, hop_steps, ext_steps, ferm_steps, misc_steps, yeast_steps, srm_color = get_recipe_info(recipe)
    color = color_conversion(srm_color)
    return render_template("explore_brews.html", selectlist_recipes=selectlist_recipes, batch_size=batch_size,
                           selectlist_styles=selectlist_styles, name=name, source=source, color=color, style=style,
                           notes=notes, hop_steps=hop_steps, ext_steps=ext_steps, ferm_steps=ferm_steps,
                           misc_steps=misc_steps, yeast_steps=yeast_steps, deleteable=deleteable)
Exemple #5
0
def get_recipes(recipe):
    """Show details of a single recipe """

    selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(session.get("user_id"))
    deleteable = False
    if Recipe.query.filter_by(name=recipe).one().user_id == session.get("user_id"):
        deleteable = True
    recipe, color = get_recipe_instructions(recipe)
    color = color_conversion(color)
    return render_template("explore_brews.html", selectlist_recipes=selectlist_recipes,
                           selectlist_styles=selectlist_styles, recipe=recipe,
                           color=color, deleteable=deleteable)
Exemple #6
0
def calculate_color():
    """ Ajax call -Calculate color for recipe """

    data = request.get_json()
    batch_size, batch_units = normalize_batch_size(data["batch_size"],
                                                   data["units"])

    srm = Fermentable.get_srm_from_ingredient_list(data["grains"], batch_size, batch_units) \
          + Extract.get_srm_from_ingredient_list(data["extracts"], batch_size, batch_units)

    color = color_conversion(srm)
    return color
Exemple #7
0
def show_explore():
    """ Display explore page """
    if session:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(
            session["user_id"])
        new = True
    else:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(
            9999)
        new = True

    # For recipe selected, show recipe.
    if request.method == "POST":
        # Render either recipe list for style selection or recipe
        if request.form.get("style"):
            style = request.form.get("style")
            list_recipes = [
                recipe.name
                for recipe in Recipe.query.filter_by(style_name=style).all()
            ]
            return render_template("explore_brews.html",
                                   list_recipes=list_recipes,
                                   selectlist_recipes=selectlist_recipes,
                                   selectlist_styles=selectlist_styles)
        elif request.form.get("recipe"):
            recipe_name = request.form.get("recipe")
            recipe, color = get_recipe_instructions(recipe_name)

            print "SERVER SRM ", color
            color = color or recipe.calc_color
            color = color_conversion(color)
            deleteable = False
            if "user_id" in session and Recipe.query.filter_by(
                    name=recipe_name).one().user_id == session["user_id"]:
                deleteable = True
            return render_template("explore_brews.html",
                                   selectlist_recipes=selectlist_recipes,
                                   selectlist_styles=selectlist_styles,
                                   recipe=recipe,
                                   color=color,
                                   deleteable=deleteable)

    return render_template("explore_brews.html",
                           new=new,
                           selectlist_recipes=selectlist_recipes,
                           selectlist_styles=selectlist_styles,
                           selectlisrt_user=selectlist_user,
                           sel_user_styles=sel_user_styles,
                           session=session)
def calculate_color():
    data = request.get_json()
    # print data
    batch_size, batch_units = normalize_batch_size(data["batch_size"], data["units"])

    srm = 0
    for ingredient_idx, fermentable in [('grains', Fermentable), ('extracts', Extract)]:
        ingredient_list = data[ingredient_idx]
        for i in range(0, len(ingredient_list), 3):
            name = ingredient_list[i]["value"]
            amount = float(ingredient_list[i+1]["value"])
            units = ingredient_list[i+2]["value"]
            srm += calc_srm_color(fermentable, name, amount, units, batch_size)

    print srm
    color = color_conversion(srm)
    return color
def brew_process(brew_id):
    brew = Brew.query.filter_by(id=brew_id).one()
    recipe = Recipe.query.filter_by(recipe_id=brew.recipe_id).one().name
    if request.method == "POST":
        brew_update = update_brew(brew)
        return redirect("/mybrews")
    else:
        recipe, batch_size, batch_units, times, timerset, boiltime, steep, yeast, secondary, extracts, og_min, og_max, notes, srm_color = show_brew_recipe(recipe)
        rating = brew.rating
        c_gravity = brew.cg
        c_gravity_date = brew.cg_date
        color = color_conversion(srm_color)

        return render_template("brew.html", brew=brew, recipe=recipe, batch_size=batch_size, batch_units=batch_units,
                               times=times, timerset=timerset, boiltime=boiltime, steep=steep, yeast=yeast, secondary=secondary,
                               extracts=extracts, og_min=og_min, og_max=og_max, c_gravity=c_gravity, c_gravity_date=c_gravity_date,
                               notes=notes, color=color, rating=rating)
Exemple #10
0
def get_recipes(recipe):
    """Show details of a single recipe """

    selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(
        session.get("user_id"))
    deleteable = False
    if Recipe.query.filter_by(
            name=recipe).one().user_id == session.get("user_id"):
        deleteable = True
    recipe, color = get_recipe_instructions(recipe)
    color = color_conversion(color)
    return render_template("explore_brews.html",
                           selectlist_recipes=selectlist_recipes,
                           selectlist_styles=selectlist_styles,
                           recipe=recipe,
                           color=color,
                           deleteable=deleteable)
Exemple #11
0
def show_mybrews():
    """ Display users brewed recipes, all or by filter. """

    selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(
        session["user_id"])
    filtered = False

    # Filtered lists
    if request.method == "POST":
        filtered_brews = []
        # Recipe search:
        if request.form.get("recipe"):
            recipe_name = request.form.get("recipe")
            recipe_id = Recipe.query.filter_by(
                name=recipe_name).one().recipe_id
            all_brews = Brew.query.filter_by(user_id=session["user_id"],
                                             recipe_id=recipe_id).all()
            filtered = "Brews of " + recipe_name + ":"

        # Style search:
        if request.form.get("style"):
            style = request.form.get("style")
            all_brews = db.session.query(Brew).join(Brew.recipe).filter_by(
                style_name=style, user_id=session["user_id"]).all()
            filtered = style + " Style Brews:"

    # Unfiltered list of all brews
    else:
        all_brews = Brew.query.filter_by(user_id=session["user_id"]).all()

    # Add hex color attribute for view
    for brew in all_brews:
        brew.color = color_conversion(brew.recipe.calc_color())

    return render_template("mybrews.html",
                           brewlist=all_brews,
                           filtered=filtered,
                           selectlist_user=selectlist_user,
                           sel_user_styles=sel_user_styles)
Exemple #12
0
def show_explore():
    """ Display explore page """
    if session:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(session["user_id"])
        new = True
    else:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(9999)
        new = True

    # For recipe selected, show recipe.
    if request.method == "POST":
        # Render either recipe list for style selection or recipe
        if request.form.get("style"):
            style = request.form.get("style")
            list_recipes = [recipe.name for recipe in Recipe.query.filter_by(style_name=style).all()]
            return render_template("explore_brews.html", list_recipes=list_recipes,
                                   selectlist_recipes=selectlist_recipes,
                                   selectlist_styles=selectlist_styles)
        elif request.form.get("recipe"):
            recipe_name = request.form.get("recipe")
            recipe, color = get_recipe_instructions(recipe_name)

            print "SERVER SRM ", color
            color = color or recipe.calc_color
            color = color_conversion(color)
            deleteable = False
            if "user_id" in session and Recipe.query.filter_by(name=recipe_name).one().user_id == session["user_id"]:
                deleteable = True
            return render_template("explore_brews.html", 
                                   selectlist_recipes=selectlist_recipes,
                                   selectlist_styles=selectlist_styles,
                                   recipe=recipe, color=color,
                                   deleteable=deleteable)

    return render_template("explore_brews.html", new=new, selectlist_recipes=selectlist_recipes,
                           selectlist_styles=selectlist_styles, selectlisrt_user=selectlist_user,
                           sel_user_styles=sel_user_styles, session=session)
Exemple #13
0
def show_explore():

    if session:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(session["user_id"])
        new = True
    else:
        selectlist_recipes, selectlist_styles, selectlist_user, sel_user_styles = get_selectlists(9999)
        new = True

    # For recipe selected, show recipe.
    if request.method == "POST":
        # Render either recipe list for style selection or recipe
        if request.form.get("style"):
            style = request.form.get("style")
            list_recipes = []
            for recipe in Recipe.query.filter_by(style_name=style).all():
                list_recipes.append(recipe.name)
            return render_template("explore_brews.html", list_recipes=list_recipes,
                                   selectlist_recipes=selectlist_recipes,
                                   selectlist_styles=selectlist_styles)
        elif request.form.get("recipe"):
            recipe = request.form.get("recipe")
            name, source, style, batch_size, batch_units, notes, hop_steps, ext_steps, ferm_steps, misc_steps, yeast_steps, srm_color = get_recipe_info(recipe)
            print "SERVER SRM ", srm_color
            color = color_conversion(srm_color)
            deleteable = False
            if session["user_id"] and Recipe.query.filter_by(name=recipe).one().user_id == session["user_id"]:
                deleteable = True
            return render_template("explore_brews.html", selectlist_recipes=selectlist_recipes, batch_size=batch_size,
                                   selectlist_styles=selectlist_styles, name=name, source=source, color=color, style=style,
                                   notes=notes, hop_steps=hop_steps, ext_steps=ext_steps, ferm_steps=ferm_steps,
                                   misc_steps=misc_steps, yeast_steps=yeast_steps, deleteable=deleteable)

    return render_template("explore_brews.html", new=new, selectlist_recipes=selectlist_recipes,
                           selectlist_styles=selectlist_styles, selectlisrt_user=selectlist_user,
                           sel_user_styles=sel_user_styles, session=session)