示例#1
0
def home():
    form = HomeForm()
    if not form.validate_on_submit():
        return render_template('home.html', form=form)
    type_of_routine = form.type_of_routine.data
    if request.method == "POST" and type_of_routine == 'Daily Routine':
        return redirect(url_for("daily_routine"))
    elif request.method == "POST" and type_of_routine == 'Weekly Routine':
        return redirect(url_for("weekly_routine"))
    else:
        return render_template("home.html")
示例#2
0
def home():
    form = HomeForm()
    if form.validate_on_submit():
        if not current_user.is_authenticated:
            flash("Only registered users may enter new items to inventory. "
                  "Visitors are welcome to experiment with "
                  "pre-existing items on other pages. "
                  "Find item names in Dropdown box links.")
            return redirect(url_for('home'))
        bulk_cost = form.bulk_cost.data
        bulk_weight = form.bulk_weight.data
        food_cost = bulk_cost / (bulk_weight * 16)
        new_item = FoodItem(
            item_name=form.item_name.data,
            item_cost_oz=f"{food_cost:.2f}",
        )
        db.session.add(new_item)
        db.session.commit()
        results = f"{new_item.item_name} costs ${food_cost:.2f} per oz."
        return redirect(url_for('food_cost_per_oz', results=results))
    return render_template('index.html', form=form)
示例#3
0
def publications():
    #sessionId = request.cookies.get('hash')
    nick = session['profile']['name']
    form = HomeForm()
    #Przekazuje na sztywno haslo ktore jest akceptowane przez usluge, aby nie zmieniac zbyt mocno logiki modulu web
    response = requests.get('http://service:80/publications',
                            headers={"Authorization": nick + ":password"})

    print(response.text)
    response = json.loads(response.text)
    files = requests.get('http://service:80/files',
                         headers={"Authorization": nick + ":password"})
    files = json.loads(files.text)
    pubs = []
    fs = []
    for _, v in response.items():
        href = v["_links"]["view"]["href"]
        id = v["id"]
        pubs.append((id, href))

    for _, v in files.items():
        download = v["_links"]["download"]["href"]
        delete = v["_links"]["delete"]["href"]
        id = v["id"]
        name = v["name"]
        fs.append((id, name, download, delete))

    if form.validate_on_submit():
        files = {'file': form.uploadFile.data}
        r = requests.post('http://service/files',
                          files=files,
                          headers={"Authorization": nick + ":password"})
        return r.text

    return render_template('publications.html',
                           pubs=pubs,
                           form=form,
                           fs=fs,
                           user=nick)