remove more tankerkönig references

This commit is contained in:
Joachim Lusiardi 2024-05-22 08:40:19 +02:00
parent a6aab66f55
commit 80264f1d02
6 changed files with 2 additions and 30 deletions

View File

@ -54,21 +54,10 @@ def user_registered_sighandler(application, user, confirm_token):
tools.db_log_add(new_vehicle) tools.db_log_add(new_vehicle)
def assure_consumable(name, ext_id, unit):
if not Consumable.query.filter(Consumable.ext_id == ext_id).first():
c = Consumable(name, ext_id, unit)
db.session.add(c)
@app.before_first_request @app.before_first_request
def before_first_request(): def before_first_request():
db.create_all() db.create_all()
# make sure all consumables from tankerkoenig exist: diesel, e5, e10
assure_consumable('Diesel', 'diesel', 'L')
assure_consumable('Super','e5', 'L')
assure_consumable('Super E10','e10', 'L')
user_datastore.find_or_create_role(name='admin', description='Role for administrators') user_datastore.find_or_create_role(name='admin', description='Role for administrators')
user_datastore.find_or_create_role(name='user', description='Role for all users.') user_datastore.find_or_create_role(name='user', description='Role for all users.')
db.session.commit() db.session.commit()

View File

@ -162,14 +162,12 @@ class Consumable(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), unique=True) name = db.Column(db.String(255), unique=True)
ext_id = db.Column(db.String(255))
unit = db.Column(db.String(255)) unit = db.Column(db.String(255))
vehicles = db.relationship("Vehicle", secondary=vehicles_consumables) vehicles = db.relationship("Vehicle", secondary=vehicles_consumables)
def __init__(self, name, ext_id, unit): def __init__(self, name, unit):
self.name = name self.name = name
self.ext_id = ext_id
self.unit = unit self.unit = unit
def __repr__(self): def __repr__(self):

View File

@ -10,14 +10,12 @@ class SelectConsumableForm(FlaskForm):
class CreateConsumableForm(FlaskForm): class CreateConsumableForm(FlaskForm):
name = StringField('Name', validators=[Length(1, 255)]) name = StringField('Name', validators=[Length(1, 255)])
ext_id = SelectField('Tankerkönig ID', coerce=int)
unit = StringField('Unit', validators=[Length(1, 255)]) unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!') submit = SubmitField(label='Do it!')
class EditConsumableForm(FlaskForm): class EditConsumableForm(FlaskForm):
name = StringField('Name', validators=[Length(1, 255)]) name = StringField('Name', validators=[Length(1, 255)])
ext_id = SelectField('Tankerkönig ID', coerce=int)
unit = StringField('Unit', validators=[Length(1, 255)]) unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!') submit = SubmitField(label='Do it!')

View File

@ -22,8 +22,6 @@ def get_admin_page():
@login_required @login_required
def create_consumable(): def create_consumable():
form = CreateConsumableForm() 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 # preinitialize the defaults with potentially existing values from a try before
if form.name.data is not None: if form.name.data is not None:
@ -32,7 +30,7 @@ def create_consumable():
form.unit.default = form.unit.data form.unit.default = form.unit.data
if form.validate_on_submit(): if form.validate_on_submit():
new_consumable = Consumable(form.name.data, choices[form.ext_id.data][1], form.unit.data) new_consumable = Consumable(form.name.data, form.unit.data)
db.session.add(new_consumable) db.session.add(new_consumable)
try: try:
db.session.commit() db.session.commit()
@ -72,28 +70,19 @@ def edit_consumable(cid):
return redirect(url_for('get_admin_page')) return redirect(url_for('get_admin_page'))
form = EditConsumableForm() form = EditConsumableForm()
choices = [(0, ''), (1, 'diesel'), (2, 'e5'), (3, 'e10')]
form.ext_id.choices = choices
form.name.default = consumable.name form.name.default = consumable.name
form.unit.default = consumable.unit 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 # preinitialize the defaults with potentially existing values from a try before
if form.name.data is not None: if form.name.data is not None:
form.name.default = form.name.data form.name.default = form.name.data
if form.unit.data is not None: if form.unit.data is not None:
form.unit.default = form.unit.data 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(): if form.validate_on_submit():
consumable.name = form.name.data consumable.name = form.name.data
consumable.unit = form.unit.data consumable.unit = form.unit.data
consumable.ext_id = choices[form.ext_id.data][1]
try: try:
db.session.commit() db.session.commit()
db_log_update(consumable) db_log_update(consumable)

View File

@ -9,7 +9,6 @@
<form class='form-horizontal' method="POST"> <form class='form-horizontal' method="POST">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ render_field_with_errors(form.name) }} {{ render_field_with_errors(form.name) }}
{{ render_field_with_errors(form.ext_id) }}
{{ render_field_with_errors(form.unit) }} {{ render_field_with_errors(form.unit) }}
{{ render_field_with_errors(form.submit) }} {{ render_field_with_errors(form.submit) }}
</form> </form>

View File

@ -9,7 +9,6 @@
<form class='form-horizontal' method="POST"> <form class='form-horizontal' method="POST">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ render_field_with_errors(form.name) }} {{ render_field_with_errors(form.name) }}
{{ render_field_with_errors(form.ext_id) }}
{{ render_field_with_errors(form.unit) }} {{ render_field_with_errors(form.unit) }}
{{ render_field_with_errors(form.submit) }} {{ render_field_with_errors(form.submit) }}
</form> </form>