Merge branch 'add_app_step_log' into 'master'
Add app step log See merge request !6
This commit is contained in:
commit
662e5b5b63
|
@ -18,7 +18,7 @@ reloaded automatically. The sqlite file will be stored in *tmp* so it
|
||||||
can be inspected with tools like *sqlite3*. The switch *DEBUG* enables
|
can be inspected with tools like *sqlite3*. The switch *DEBUG* enables
|
||||||
debugging during development.
|
debugging during development.
|
||||||
|
|
||||||
`docker run --rm --name rollerverbrauch -ti -v `pwd`/app:/app -v `pwd`/../rollerverbrauch_config:/app/config -v /tmp/pitstops/:/data -e DEBUG=True -p 5000:5000 rollerverbrauch`
|
`docker run --rm --name rollerverbrauch -ti -v $PWD/app:/app -v $PWD/../rollerverbrauch_config:/app/config -v /tmp/pitstops/:/data -e DEBUG=True -p 5000:5000 rollerverbrauch`
|
||||||
|
|
||||||
## run in production
|
## run in production
|
||||||
`docker run --name pitstops -d -v /data/pitstops/:/data -v /configs/pitstops/:/app/config -p 80:5000 rollerverbrauch`
|
`docker run --name pitstops -d -v /data/pitstops/:/data -v /configs/pitstops/:/app/config -p 80:5000 rollerverbrauch`
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import os
|
import os
|
||||||
from rollerverbrauch import app
|
from rollerverbrauch import app
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logging():
|
||||||
|
logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', level=logging.INFO)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
DEBUG = 'DEBUG' in os.environ and os.environ['DEBUG'] != 'False'
|
DEBUG = 'DEBUG' in os.environ and os.environ['DEBUG'] != 'False'
|
||||||
|
setup_logging()
|
||||||
app.run(debug=DEBUG, host='0.0.0.0')
|
app.run(debug=DEBUG, host='0.0.0.0')
|
||||||
|
|
|
@ -9,7 +9,7 @@ from flask.ext.security import Security, SQLAlchemyUserDatastore, \
|
||||||
from flask.ext.security import user_registered
|
from flask.ext.security import user_registered
|
||||||
from flask_security.core import current_user
|
from flask_security.core import current_user
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
import logging
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/rollerverbrauch.db'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/rollerverbrauch.db'
|
||||||
|
@ -24,7 +24,10 @@ db = SQLAlchemy(app)
|
||||||
mail = Mail(app)
|
mail = Mail(app)
|
||||||
|
|
||||||
from rollerverbrauch.tools import \
|
from rollerverbrauch.tools import \
|
||||||
VehicleStats
|
VehicleStats, \
|
||||||
|
db_log_add, \
|
||||||
|
db_log_delete, \
|
||||||
|
db_log_update
|
||||||
|
|
||||||
from rollerverbrauch.forms import \
|
from rollerverbrauch.forms import \
|
||||||
CreatePitstopForm, \
|
CreatePitstopForm, \
|
||||||
|
@ -57,6 +60,8 @@ def user_registered_sighandler(app, user, confirm_token):
|
||||||
db.session.add(v)
|
db.session.add(v)
|
||||||
user.vehicles.append(v)
|
user.vehicles.append(v)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
db_log_add(user)
|
||||||
|
db_log_add(new_vehicle)
|
||||||
|
|
||||||
|
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
|
@ -87,6 +92,7 @@ def edit_vehicle(vid):
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
vehicle.name = form.name.data
|
vehicle.name = form.name.data
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
db_log_update(vehicle)
|
||||||
return redirect(url_for('get_account_page'))
|
return redirect(url_for('get_account_page'))
|
||||||
|
|
||||||
form.name.default = vehicle.name
|
form.name.default = vehicle.name
|
||||||
|
@ -108,6 +114,7 @@ def delete_vehicle(vid):
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
db.session.delete(vehicle)
|
db.session.delete(vehicle)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
db_log_delete(vehicle)
|
||||||
return redirect(url_for('get_account_page'))
|
return redirect(url_for('get_account_page'))
|
||||||
|
|
||||||
return render_template('deleteVehicleForm.html', form=form, vehicle=vehicle)
|
return render_template('deleteVehicleForm.html', form=form, vehicle=vehicle)
|
||||||
|
@ -123,6 +130,7 @@ def create_vehicle():
|
||||||
db.session.add(new_vehicle)
|
db.session.add(new_vehicle)
|
||||||
current_user.vehicles.append(new_vehicle)
|
current_user.vehicles.append(new_vehicle)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
db_log_add(new_vehicle)
|
||||||
return redirect(url_for('get_account_page'))
|
return redirect(url_for('get_account_page'))
|
||||||
|
|
||||||
return render_template('createVehicleForm.html', form=form)
|
return render_template('createVehicleForm.html', form=form)
|
||||||
|
@ -164,6 +172,7 @@ def create_pit_stop_form(vid):
|
||||||
db.session.add(new_stop)
|
db.session.add(new_stop)
|
||||||
vehicle.pitstops.append(new_stop)
|
vehicle.pitstops.append(new_stop)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
db_log_add(new_stop)
|
||||||
return redirect(url_for('get_pit_stops', _anchor= 'v' + str(vehicle.id)))
|
return redirect(url_for('get_pit_stops', _anchor= 'v' + str(vehicle.id)))
|
||||||
|
|
||||||
form.odometer.default = last_pitstop.odometer
|
form.odometer.default = last_pitstop.odometer
|
||||||
|
@ -195,7 +204,6 @@ def get_admin_page():
|
||||||
@app.route('/account', methods=['GET'])
|
@app.route('/account', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
def get_account_page():
|
def get_account_page():
|
||||||
print(current_user)
|
|
||||||
return render_template('account.html', data=g.data)
|
return render_template('account.html', data=g.data)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class User(db.Model, UserMixin):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<User %r>' % self.email
|
return '<User id="%r" email="%r" ' % (self.id, self.email)
|
||||||
|
|
||||||
|
|
||||||
class Vehicle(db.Model):
|
class Vehicle(db.Model):
|
||||||
|
@ -49,7 +49,7 @@ class Vehicle(db.Model):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Vehicle %r>' % self.name
|
return '<Vehicle id="%r" owner_id="%r" name="%r" />' % (self.id, self.owner_id, self.name)
|
||||||
|
|
||||||
|
|
||||||
class Pitstop(db.Model):
|
class Pitstop(db.Model):
|
||||||
|
@ -65,4 +65,4 @@ class Pitstop(db.Model):
|
||||||
self.date = date
|
self.date = date
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Pitstop %r km, %r l>' % (self.odometer, self.litres)
|
return '<Pitstop odometer="%r" litres="%r" date="%r" vehicle_id="%r">' % (self.odometer, self.litres, self.date, self.vehicle_id)
|
|
@ -1,3 +1,6 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class VehicleStats:
|
class VehicleStats:
|
||||||
def __init__(self, vehicle):
|
def __init__(self, vehicle):
|
||||||
self.name = vehicle.name
|
self.name = vehicle.name
|
||||||
|
@ -16,3 +19,15 @@ class VehicleStats:
|
||||||
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
||||||
self.average_distance = self.overall_distance / (self.pitstop_count - 1)
|
self.average_distance = self.overall_distance / (self.pitstop_count - 1)
|
||||||
self.average_litres_used = 100 * (self.overall_litres - vehicle.pitstops[0].litres) / self.overall_distance
|
self.average_litres_used = 100 * (self.overall_litres - vehicle.pitstops[0].litres) / self.overall_distance
|
||||||
|
|
||||||
|
|
||||||
|
def db_log_add(entity):
|
||||||
|
logging.info('db_add: %s' % str(entity))
|
||||||
|
|
||||||
|
|
||||||
|
def db_log_delete(entity):
|
||||||
|
logging.info('db_delete: %s' % str(entity))
|
||||||
|
|
||||||
|
|
||||||
|
def db_log_update(entity):
|
||||||
|
logging.info('db_update: %s' % str(entity))
|
||||||
|
|
Loading…
Reference in New Issue