Exemplo n.º 1
0
def test_timestring_to_seconds():
    assert timestring_to_seconds('05') == 5
    assert timestring_to_seconds('45') == 45
    assert timestring_to_seconds('1:03') == 63
    assert timestring_to_seconds('1:37') == 97
    assert timestring_to_seconds('02:15') == 135
    assert timestring_to_seconds('01:00:00') == 3600
    assert timestring_to_seconds('1:0:1') == 3601
Exemplo n.º 2
0
def roast_add(roast_id=None):
    user = g.user
    form = RoastForm()
    form.bean_id.choices = [
        (b.id, "%s - %s (%dg)" % (b.purchase_date, b.name, b.weight))
        for b in Bean.query.filter_by(user_id=user.id).order_by(Bean.purchase_date.desc()).limit(10).all()
    ]
    if roast_id:
        roast = Roast.query.get(roast_id)
        form.bean_dose.data = roast.bean_dose
        form.drop_temp.data = roast.drop_temp
        form.dry_end_time.data = seconds_to_timestring(roast.dry_end_time)
        form.dry_end_temp.data = roast.dry_end_temp
        form.fc_begin_time.data = seconds_to_timestring(roast.fc_begin_time)
        form.fc_begin_temp.data = roast.fc_begin_temp
        form.fc_end_time.data = seconds_to_timestring(roast.fc_end_time)
        form.fc_end_temp.data = roast.fc_end_temp
        form.sc_begin_time.data = seconds_to_timestring(roast.sc_begin_time)
        form.sc_begin_temp.data = roast.sc_begin_temp
        form.sc_end_time.data = seconds_to_timestring(roast.sc_end_time)
        form.sc_end_temp.data = roast.sc_end_temp
        form.end_time.data = seconds_to_timestring(roast.end_time)
        form.end_temp.data = roast.end_temp
        form.end_weight.data = roast.end_weight
        form.roaster_machine.data = roast.roaster_machine
        form.roast_date.data = roast.roast_date
        form.notes.data = roast.notes
        form.bean_id.data = roast.bean_id
        form.roast_id.data = roast.id
    if form.validate_on_submit():
        form.roast_id.data = int(form.roast_id.data)
        if form.roast_id.data == 0:
            roast = Roast()
        else:
            roast = Roast.query.get(form.roast_id.data)
            if roast.user_id != user.id:
                return redirect(url_for("roast_list"))
        roast.bean_dose = form.bean_dose.data
        roast.drop_temp = form.drop_temp.data
        roast.dry_end_time = timestring_to_seconds(form.dry_end_time.data)
        roast.dry_end_temp = form.dry_end_temp.data
        roast.fc_begin_time = timestring_to_seconds(form.fc_begin_time.data)
        roast.fc_begin_temp = form.fc_begin_temp.data
        roast.fc_end_time = timestring_to_seconds(form.fc_end_time.data)
        roast.fc_end_temp = form.fc_end_temp.data
        roast.sc_begin_time = timestring_to_seconds(form.sc_begin_time.data)
        roast.sc_begin_temp = form.sc_begin_temp.data
        roast.sc_end_time = timestring_to_seconds(form.sc_end_time.data)
        roast.sc_end_temp = form.sc_end_temp.data
        roast.end_time = timestring_to_seconds(form.end_time.data)
        roast.end_temp = form.end_temp.data
        roast.end_weight = form.end_weight.data
        roast.roaster_machine = form.roaster_machine.data
        roast.roast_date = form.roast_date.data
        roast.notes = form.notes.data
        roast.bean_id = form.bean_id.data
        roast.user_id = user.id
        Roast.add_roast(roast)
        return redirect(url_for("roast_list"))
    return render_template("roast_add.html", form=form)
Exemplo n.º 3
0
def brew_add(brew_id=None):
    user = g.user
    form = BrewForm()
    form.roast_batch.choices = [
        (r.id, '%s - %s' % (r.roast_date, r.bean.name))
        for r in Roast.query.filter(
            Roast.user_id == user.id, Roast.bean_id > 0).order_by(
                Roast.roast_date.desc()).limit(10).all()
    ]
    form.roast_batch.choices.append((0, 'N/A'))
    form.bean_id.choices = [
        (b.id, '%s - %s (%dg)' % (b.purchase_date, b.name, b.weight))
        for b in Bean.query.filter_by(user_id=user.id).order_by(
            Bean.purchase_date.desc()).limit(10).all()
    ]
    if brew_id:
        brew = Brew.query.get(brew_id)
        form.roast_batch.data = brew.roast_id
        form.bean_id.data = brew.bean_id
        form.grind_size.data = brew.grind_size
        form.bean_dose.data = Decimal(brew.bean_dose) / 100
        form.water_dose.data = brew.water_dose
        form.extraction_time.data = seconds_to_timestring(brew.extraction_time)
        form.brew_method.data = brew.brew_method
        form.filter_type.data = brew.filter_type
        form.brew_date.data = brew.brew_date
        form.notes.data = brew.notes
        form.brew_id.data = brew.id
    if form.validate_on_submit():
        form.brew_id.data = int(form.brew_id.data)
        if form.brew_id.data == 0:
            brew = Brew()
        else:
            brew = Brew.query.get(form.brew_id.data)
            if brew.user_id != user.id:
                return redirect(url_for('brew_list'))
        brew.grind_size = form.grind_size.data
        brew.bean_dose = int(form.bean_dose.data * 100)
        brew.water_dose = form.water_dose.data
        brew.extraction_time = timestring_to_seconds(form.extraction_time.data)
        brew.brew_method = form.brew_method.data
        brew.filter_type = form.filter_type.data
        brew.brew_date = form.brew_date.data
        brew.notes = form.notes.data
        brew.user_id = user.id
        brew.bean_id = form.bean_id.data
        brew.roast_id = form.roast_batch.data
        Brew.add_brew(brew)
        return redirect(url_for('brew_list'))
    return render_template('brew_add.html', form=form)
Exemplo n.º 4
0
def brew_add(brew_id=None):
    user = g.user
    form = BrewForm()
    form.roast_batch.choices = [
        (r.id, "%s - %s" % (r.roast_date, r.bean.name))
        for r in Roast.query.filter(Roast.user_id == user.id, Roast.bean_id > 0)
        .order_by(Roast.roast_date.desc())
        .limit(10)
        .all()
    ]
    form.roast_batch.choices.append((0, "N/A"))
    form.bean_id.choices = [
        (b.id, "%s - %s (%dg)" % (b.purchase_date, b.name, b.weight))
        for b in Bean.query.filter_by(user_id=user.id).order_by(Bean.purchase_date.desc()).limit(10).all()
    ]
    if brew_id:
        brew = Brew.query.get(brew_id)
        form.roast_batch.data = brew.roast_id
        form.bean_id.data = brew.bean_id
        form.grind_size.data = brew.grind_size
        form.bean_dose.data = brew.bean_dose
        form.water_dose.data = brew.water_dose
        form.extraction_time.data = seconds_to_timestring(brew.extraction_time)
        form.brew_method.data = brew.brew_method
        form.filter_type.data = brew.filter_type
        form.brew_date.data = brew.brew_date
        form.notes.data = brew.notes
        form.brew_id.data = brew.id
    if form.validate_on_submit():
        form.brew_id.data = int(form.brew_id.data)
        if form.brew_id.data == 0:
            brew = Brew()
        else:
            brew = Brew.query.get(form.brew_id.data)
            if brew.user_id != user.id:
                return redirect(url_for("brew_list"))
        brew.grind_size = form.grind_size.data
        brew.bean_dose = form.bean_dose.data
        brew.water_dose = form.water_dose.data
        brew.extraction_time = timestring_to_seconds(form.extraction_time.data)
        brew.brew_method = form.brew_method.data
        brew.filter_type = form.filter_type.data
        brew.brew_date = form.brew_date.data
        brew.notes = form.notes.data
        brew.user_id = user.id
        brew.bean_id = form.bean_id.data
        brew.roast_id = form.roast_batch.data
        Brew.add_brew(brew)
        return redirect(url_for("brew_list"))
    return render_template("brew_add.html", form=form)
Exemplo n.º 5
0
def roast_add(roast_id=None):
    user = g.user
    form = RoastForm()
    form.bean_id.choices = [
        (b.id, '%s - %s (%dg)' % (b.purchase_date, b.name, b.weight))
        for b in Bean.query.filter_by(user_id=user.id).order_by(
            Bean.purchase_date.desc()).limit(10).all()
    ]
    if roast_id:
        roast = Roast.query.get(roast_id)
        form.bean_dose.data = Decimal(roast.bean_dose) / 100
        form.drop_temp.data = roast.drop_temp
        form.dry_end_time.data = seconds_to_timestring(roast.dry_end_time)
        form.dry_end_temp.data = roast.dry_end_temp
        form.fc_begin_time.data = seconds_to_timestring(roast.fc_begin_time)
        form.fc_begin_temp.data = roast.fc_begin_temp
        form.fc_end_time.data = seconds_to_timestring(roast.fc_end_time)
        form.fc_end_temp.data = roast.fc_end_temp
        form.sc_begin_time.data = seconds_to_timestring(roast.sc_begin_time)
        form.sc_begin_temp.data = roast.sc_begin_temp
        form.sc_end_time.data = seconds_to_timestring(roast.sc_end_time)
        form.sc_end_temp.data = roast.sc_end_temp
        form.end_time.data = seconds_to_timestring(roast.end_time)
        form.end_temp.data = roast.end_temp
        form.end_weight.data = Decimal(roast.end_weight) / 100
        form.roaster_machine.data = roast.roaster_machine
        form.roast_date.data = roast.roast_date
        form.notes.data = roast.notes
        form.bean_id.data = roast.bean_id
        form.roast_id.data = roast.id
    if form.validate_on_submit():
        form.roast_id.data = int(form.roast_id.data)
        if form.roast_id.data == 0:
            roast = Roast()
        else:
            roast = Roast.query.get(form.roast_id.data)
            if roast.user_id != user.id:
                return redirect(url_for('roast_list'))
        roast.bean_dose = int(form.bean_dose.data * 100)
        roast.drop_temp = form.drop_temp.data
        roast.dry_end_time = timestring_to_seconds(form.dry_end_time.data)
        roast.dry_end_temp = form.dry_end_temp.data
        roast.fc_begin_time = timestring_to_seconds(form.fc_begin_time.data)
        roast.fc_begin_temp = form.fc_begin_temp.data
        roast.fc_end_time = timestring_to_seconds(form.fc_end_time.data)
        roast.fc_end_temp = form.fc_end_temp.data
        roast.sc_begin_time = timestring_to_seconds(form.sc_begin_time.data)
        roast.sc_begin_temp = form.sc_begin_temp.data
        roast.sc_end_time = timestring_to_seconds(form.sc_end_time.data)
        roast.sc_end_temp = form.sc_end_temp.data
        roast.end_time = timestring_to_seconds(form.end_time.data)
        roast.end_temp = form.end_temp.data
        roast.end_weight = int(form.end_weight.data * 100)
        roast.roaster_machine = form.roaster_machine.data
        roast.roast_date = form.roast_date.data
        roast.notes = form.notes.data
        roast.bean_id = form.bean_id.data
        roast.user_id = user.id
        Roast.add_roast(roast)
        return redirect(url_for('roast_list'))
    return render_template('roast_add.html', form=form)