Consumables can now be linked to the tankerkoenig api
This commit is contained in:
@@ -22,6 +22,8 @@ def get_admin_page():
|
||||
@login_required
|
||||
def create_consumable():
|
||||
form = CreateConsumableForm()
|
||||
choices = [(0, ''), (1, 'diesel'), (2, 'e5'), (3, 'e10')]
|
||||
form.ext_id.choices = choices
|
||||
|
||||
# preinitialize the defaults with potentially existing values from a try before
|
||||
if form.name.data is not None:
|
||||
@@ -30,7 +32,7 @@ def create_consumable():
|
||||
form.unit.default = form.unit.data
|
||||
|
||||
if form.validate_on_submit():
|
||||
new_consumable = Consumable(form.name.data, form.unit.data)
|
||||
new_consumable = Consumable(form.name.data, choices[form.ext_id.data][1], form.unit.data)
|
||||
db.session.add(new_consumable)
|
||||
try:
|
||||
db.session.commit()
|
||||
@@ -70,19 +72,30 @@ def edit_consumable(cid):
|
||||
return redirect(url_for('get_admin_page'))
|
||||
|
||||
form = EditConsumableForm()
|
||||
choices = [(0, ''), (1, 'diesel'), (2, 'e5'), (3, 'e10')]
|
||||
form.ext_id.choices = choices
|
||||
|
||||
form.name.default = consumable.name
|
||||
form.unit.default = consumable.unit
|
||||
form.ext_id.default = 3
|
||||
for c in choices:
|
||||
if c[1] == consumable.ext_id:
|
||||
form.ext_id.default = c[0]
|
||||
|
||||
# preinitialize the defaults with potentially existing values from a try before
|
||||
if form.name.data is not None:
|
||||
form.name.default = form.name.data
|
||||
if form.unit.data is not None:
|
||||
form.unit.default = form.unit.data
|
||||
if form.ext_id.data is not None:
|
||||
form.ext_id.default = form.ext_id.data
|
||||
|
||||
if form.validate_on_submit():
|
||||
consumable.name = form.name.data
|
||||
consumable.unit = form.unit.data
|
||||
print(form.ext_id.data)
|
||||
consumable.ext_id = choices[form.ext_id.data][1]
|
||||
print(consumable.ext_id)
|
||||
try:
|
||||
db.session.commit()
|
||||
db_log_update(consumable)
|
||||
|
||||
Reference in New Issue
Block a user