def batchSizeChange(userViewID, recipeName):
    displayRecipes = showUserRecipeList(userViewID)
    size = request.form.get("batchsize")
    units = request.form.get("unitSys")

    recipe = modelPG.Recipe.getRecipeIDByName(recipeName, userViewID)

    components = modelPG.Component.getComponentsByRecipeID(recipe.id)
    batchComp = []

    percent_list = []
    for comp in components:
        percent_list.append(comp.percentage)

    onehundred = converter.checkPercent(percent_list)
    newPercent = converter.getPercentMult(percent_list)

    if onehundred is False:
        messageToUser = "******"
    else:
        messageToUser = None

    x = 0
    for comp in components:
        batchComp.append(comp.percentage/100)
        x += 1

    sizeflt = float(size)
    wholeNumList = []
    frctnList = []
    kgchecked = ""
    lbschecked = ""
    priceList = []
    compList = []

    j = 0
    for i in range(len(batchComp)):

        batchComp[i] = (sizeflt * batchComp[i])*newPercent
        chemID = modelPG.Chem.getChemIDByName(components[j].chem.chem_name)

        wholeNumList.append(int(batchComp[i]))

        if units == "kg":
            frctnList.append(int(converter.frctnKilosToGrams(batchComp[i])))
            kgchecked = 'checked = "checked"'
            kgToPounds = converter.poundsToKilos(batchComp[i])
            chemPrice = pricecompute.getPrice(chemID, kgToPounds)
            priceList.append(chemPrice * batchComp[i])
        else:
            frctnList.append(int(converter.frctnPoundsToOunces(batchComp[i])))
            lbschecked = 'checked = "checked"'
            chemPrice = pricecompute.getPrice(chemID, batchComp[i])
            priceList.append(chemPrice * batchComp[i])

        dict_of_comp = {
            'a_name': components[j].chem.chem_name[:35],
            'b_percent': components[j].percentage,
            'c_whole': wholeNumList[i],
            'd_frctn': frctnList[i],
            'e_chemPrice': priceList[i]
        }

        compList.append(dict_of_comp)
        j += 1

    sumprice = sum(priceList)

    if units == "kg":
        surcharge = pricecompute.getSurChargeKilos(sizeflt) * len(batchComp)
        session["surcharge"] = surcharge
        shipping = pricecompute.getShipping(converter.poundsToKilos(sizeflt))
    else:
        surcharge = pricecompute.getSurChargeLbs(sizeflt) * len(batchComp)
        session["surcharge"] = surcharge
        shipping = pricecompute.getShipping(sizeflt)

    session["shipping"] = shipping
    session["pre-tax-cost"] = round(sumprice, 2)

    if sizeflt == 0:
        price_quote = 0
    else:
        price_quote = round((sumprice + surcharge), 2)

    orderItems = json.dumps(compList, sort_keys=True,
                            separators=(',', ': '))
    session["orderList"] = orderItems

    if (lbschecked == 'checked = "checked"'):
        session["unitSys"] = "lbs"
    else:
        session["unitSys"] = "kilos"

    return render_template("recipecomps.html", user_id=userViewID,
                           recipe_name=recipeName, batchComp=batchComp,
                           components=components,
                           displayRecipes=displayRecipes,
                           user_notes=recipe.user_notes,
                           messageToUser=messageToUser, batchsize=size,
                           wholeNumList=wholeNumList, frctnList=frctnList,
                           kgchecked=kgchecked, lbschecked=lbschecked,
                           unitSys=units, price_quote=price_quote,
                           compList=compList, orderItems=orderItems)
Exemple #2
0
def batchSizeChange(userViewID, recipeName):
    displayRecipes = showUserRecipeList(userViewID)
    size = request.form.get("batchsize")
    units = request.form.get("unitSys")

    recipe = model.Recipe.getRecipeIDByName(recipeName, userViewID)

    components = model.Component.getComponentsByRecipeID(recipe.id)
    batchComp = []

    percent_list = []
    for comp in components:
        percent_list.append(comp.percentage)

    onehundred = converter.checkPercent(percent_list)
    newPercent = converter.getPercentMult(percent_list)

    if onehundred is False:
        messageToUser = "******"
    else:
        messageToUser = None

    x = 0
    for comp in components:
        batchComp.append(comp.percentage / 100)
        x += 1

    sizeflt = float(size)
    wholeNumList = []
    frctnList = []
    kgchecked = ""
    lbschecked = ""
    priceList = []
    compList = []

    j = 0
    for i in range(len(batchComp)):

        batchComp[i] = (sizeflt * batchComp[i]) * newPercent
        chemID = model.Chem.getChemIDByName(components[j].chem.chem_name)

        wholeNumList.append(int(batchComp[i]))

        if units == "kg":
            frctnList.append(int(converter.frctnKilosToGrams(batchComp[i])))
            kgchecked = 'checked = "checked"'
            kgToPounds = converter.poundsToKilos(sizeflt)
            chemPrice = pricecompute.getPrice(chemID, kgToPounds)
            priceList.append(chemPrice * batchComp[i])
        else:
            frctnList.append(int(converter.frctnPoundsToOunces(batchComp[i])))
            lbschecked = 'checked = "checked"'
            chemPrice = pricecompute.getPrice(chemID, sizeflt)
            priceList.append(chemPrice * batchComp[i])

        dict_of_comp = {
            'a_name': components[j].chem.chem_name[:35],
            'b_percent': components[j].percentage,
            'c_whole': wholeNumList[i],
            'd_frctn': frctnList[i],
            'e_chemPrice': priceList[i]
        }

        compList.append(dict_of_comp)
        j += 1

    sumprice = sum(priceList)

    if units == "kg":
        surcharge = pricecompute.getSurChargeKilos(sizeflt) * len(batchComp)
        session["surcharge"] = surcharge
        shipping = pricecompute.getShipping(converter.poundsToKilos(sizeflt))
    else:
        surcharge = pricecompute.getSurChargeLbs(sizeflt) * len(batchComp)
        session["surcharge"] = surcharge
        shipping = pricecompute.getShipping(sizeflt)

    session["shipping"] = shipping
    session["pre-tax-cost"] = round(sumprice, 2)

    if sizeflt == 0:
        price_quote = 0
    else:
        price_quote = round((sumprice + surcharge), 2)

    orderItems = json.dumps(compList, sort_keys=True, separators=(',', ': '))
    session["orderList"] = orderItems

    if (lbschecked == 'checked = "checked"'):
        session["unitSys"] = "lbs"
    else:
        session["unitSys"] = "kilos"

    return render_template("recipecomps.html",
                           user_id=userViewID,
                           recipe_name=recipeName,
                           batchComp=batchComp,
                           components=components,
                           displayRecipes=displayRecipes,
                           user_notes=recipe.user_notes,
                           messageToUser=messageToUser,
                           batchsize=size,
                           wholeNumList=wholeNumList,
                           frctnList=frctnList,
                           kgchecked=kgchecked,
                           lbschecked=lbschecked,
                           unitSys=units,
                           price_quote=price_quote,
                           compList=compList,
                           orderItems=orderItems)
def enterRecipe():

    recipeName = request.form.get('recipename')
    batchsize = request.form.get('batchsize')

    newRecipe = modelPG.Recipe()
    newRecipe.recipe_name = recipeName

    batchComp = []
    sizeflt = float(batchsize)
    kgchecked = 'checked = "checked"'
    lbschecked = ""
    unitSys = "kg"
    percent_list = []
    wholeNumList = []
    frctnList = []
    messageToUser = None

    chem_list = request.values.getlist('chem')
    percentages = request.values.getlist('percentage')
    if percentages == []:
        flash("no entry")
        return redirect("/enterRecipe")

    i = 0
    for chem in chem_list:
        comp = modelPG.Component()
        comp.chem_name = chem
        comp.chem_id = modelPG.Chem.getChemIDByName(comp.chem_name)
        comp.percentage = float(percentages[i])
        percent_list.append(comp.percentage)
        i += 1
        comp.recipe_id = newRecipe.id
        batchComp.append(float(comp.percentage))

    onehundred = converter.checkPercent(percent_list)
    newPercent = converter.getPercentMult(percent_list)

    if onehundred is False:
        messageToUser = "******"
    else:
        messageToUser = None

    for i in range(len(batchComp)):
        batchComp[i] = (sizeflt * batchComp[i])*newPercent

        wholeNumList.append(int(batchComp[i]))
        if unitSys == "kg":
            frctnList.append(int(converter.frctnKilosToGrams(batchComp[i])))
            kgchecked = 'checked = "checked"'
        else:
            frctnList.append(int(converter.frctnPoundsToOunces(batchComp[i])))
            lbschecked = 'checked = "checked"'

    return render_template("calc_recipe.html",
                           recipe_name=newRecipe.recipe_name,
                           chem_list=chem_list, percentages=percentages,
                           batchComp=batchComp, batchsize=batchsize,
                           kgchecked=kgchecked, lbschecked=lbschecked,
                           unitSys=unitSys, wholeNumList=wholeNumList,
                           frctnList=frctnList, messageToUser=messageToUser)
Exemple #4
0
def enterRecipe():

    recipeName = request.form.get('recipename')
    batchsize = request.form.get('batchsize')

    newRecipe = model.Recipe()
    newRecipe.recipe_name = recipeName

    batchComp = []
    sizeflt = float(batchsize)
    kgchecked = 'checked = "checked"'
    lbschecked = ""
    unitSys = "kg"
    percent_list = []
    wholeNumList = []
    frctnList = []
    messageToUser = None

    chem_list = request.values.getlist('chem')
    percentages = request.values.getlist('percentage')
    if percentages == []:
        flash("no entry")
        return redirect("/enterRecipe")

    i = 0
    for chem in chem_list:
        comp = model.Component()
        comp.chem_name = chem
        comp.chem_id = model.Chem.getChemIDByName(comp.chem_name)
        comp.percentage = float(percentages[i])
        percent_list.append(comp.percentage)
        i += 1
        comp.recipe_id = newRecipe.id
        batchComp.append(float(comp.percentage))

    onehundred = converter.checkPercent(percent_list)
    newPercent = converter.getPercentMult(percent_list)

    if onehundred is False:
        messageToUser = "******"
    else:
        messageToUser = None

    for i in range(len(batchComp)):
        batchComp[i] = (sizeflt * batchComp[i]) * newPercent

        wholeNumList.append(int(batchComp[i]))
        if unitSys == "kg":
            frctnList.append(int(converter.frctnKilosToGrams(batchComp[i])))
            kgchecked = 'checked = "checked"'
        else:
            frctnList.append(int(converter.frctnPoundsToOunces(batchComp[i])))
            lbschecked = 'checked = "checked"'

    return render_template("calc_recipe.html",
                           recipe_name=newRecipe.recipe_name,
                           chem_list=chem_list,
                           percentages=percentages,
                           batchComp=batchComp,
                           batchsize=batchsize,
                           kgchecked=kgchecked,
                           lbschecked=lbschecked,
                           unitSys=unitSys,
                           wholeNumList=wholeNumList,
                           frctnList=frctnList,
                           messageToUser=messageToUser)