46 Commits

Author SHA1 Message Date
8b78dbe5b7 add DEBUG = False to default config 2017-11-25 11:12:16 +01:00
95a7e56a32 load openlayers via https 2017-11-25 11:11:55 +01:00
9eb4d5ada0 fixup! preparation commit for henni 2017-11-24 09:08:37 +01:00
f7cb273254 preparation commit for henni
This commit includes:
* sql conversion script
* fixes for the column type for lat and lng fields
* removes prints / console logs
* unneccessary comments
* if no home data is available, we center to germany
* hide non working brand logos
* on closed stations the word "closed" is printed instead of outdated
price
* updates on filling stations is done in chunks of max 10
* configuration separates between development and testing
2017-11-24 09:08:04 +01:00
543d3e1658 react to closed stations 2017-11-12 22:50:25 +01:00
9427ed50ad add page to plan a pitstop 2017-11-12 15:38:32 +01:00
28990f27fa moved static files to separate directories 2017-11-12 15:34:49 +01:00
d55fd3d9f6 Consumables can now be linked to the tankerkoenig api 2017-11-12 10:17:36 +01:00
e9bb7986f4 moves routes for filling stations to extra file 2017-11-12 09:44:51 +01:00
eaacd3f42e adds functionality to handle favourit filling stations 2017-11-10 10:38:15 +01:00
8a99e4a616 adds icons & logos
adds icons for filling stations and favorites
adds logos for various brands
2017-11-10 10:37:39 +01:00
028b52d12f Adds setting home in account 2017-11-07 22:33:14 +01:00
958a9bdd9f DEBUG flag can now be set via config and environment 2017-11-07 22:31:31 +01:00
b02938cafe Moves MySQL DB to production 2017-11-07 22:30:44 +01:00
47e81c7517 start implementing a proxy layer for the API of creativecommons.tankerkoenig.de 2017-10-30 06:49:56 +01:00
af6f271b29 Merge branch 'development' into 'master'
Development

See merge request !30
2016-11-15 21:42:08 +01:00
c9b1a1b095 Merge branch 'special_costs' into 'development'
Special costs

See merge request !29
2016-11-15 21:33:10 +01:00
2e4c815a10 Add of db update script 2016-11-15 21:31:37 +01:00
5859763a14 Fixed deprecation warning for Form 2016-11-06 18:53:13 +01:00
6e665b9f2f finished handling of services 2016-11-06 13:22:54 +01:00
60a1b307e4 changes to beautify the generated markdown 2016-11-06 13:14:28 +01:00
3f458937d9 adds markdown filter 2016-11-06 13:14:03 +01:00
bceb9181ee sorting for events 2016-11-01 19:48:24 +01:00
086c643365 fixed shadowing warning 2016-11-01 19:48:08 +01:00
d8c6a0a59b splitted routes into package 2016-11-01 18:01:52 +01:00
43d9fc412e moved forms to extra package 2016-11-01 16:36:28 +01:00
71412bf487 integrate services into rollerverbrauch 2016-11-01 11:19:26 +01:00
dd11419305 add the crud forms for services 2016-11-01 11:18:40 +01:00
d132dc72de Add Entitiy for the Service Object 2016-11-01 11:17:54 +01:00
43fa41aace Add input type TextAreaField
adds a possibility to add longer texts in the style of
rollerverbrauch
2016-11-01 11:16:13 +01:00
b8a6f69090 add gitattributes to handle line ending settings and expose ports on docker compose 2016-08-28 15:45:08 +02:00
bb7c2780e8 Merge branch '11_Redirect_to_edit_vehicle_page_if_no_consumable_is_configured' into 'development'
11 redirect to edit vehicle page if no consumable is configured



See merge request !28
2016-08-28 14:01:37 +02:00
088d1f24a0 add redirect if vehicle is not configured and flash messages 2016-08-16 13:21:54 +02:00
87b3b02f3e add sqlite files to gitignore 2016-08-07 13:19:26 +02:00
c8a9404bf6 fixed use of os.environ 2016-08-07 13:18:39 +02:00
4acf36112c add ids to pitstop elements 2016-08-07 13:18:04 +02:00
4b73699750 Added ids to important elements 2016-08-06 10:59:20 +02:00
d393f19b47 Fixed wrong text 2016-08-06 10:59:03 +02:00
44b92e58b5 use config variable to identify admin account while it is created 2016-08-03 08:13:39 +02:00
1e7db29de9 add config variable to identify admin account while it is created 2016-08-03 08:12:06 +02:00
938a7fc140 Removed dependency to mysql for testing 2016-08-03 08:09:58 +02:00
49a45ba8a4 Merge branch 'development' into 'selenium_tests'
Sync Development to selenium tests



See merge request !27
2016-07-30 09:23:14 +02:00
bcc0541be3 Merge branch 'development' into selenium_tests 2016-07-17 10:09:01 +02:00
936fbf30f6 worked on tests 2016-05-28 18:59:23 +02:00
3f8f30f5d1 improved tests
test code waits for selenium to be available
screenshots get named more precisely
2016-05-27 11:33:15 +02:00
cc414092a3 Adds first steps towards auto tests 2016-05-27 03:24:44 +02:00
82 changed files with 2030 additions and 741 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.sh text eol=lf

2
.gitignore vendored
View File

@@ -1,4 +1,6 @@
.idea/ .idea/
tests/results/
**.DS_Store **.DS_Store
**.swp **.swp
**.pyc **.pyc
*.sqlite

View File

@@ -1,63 +1,58 @@
from datetime import date from flask import Flask, make_response
from flask import g
from flask import Flask
from flask import redirect, g
from flask import render_template
from flask import url_for
from flask_mail import Mail from flask_mail import Mail
from flask_security import Security, SQLAlchemyUserDatastore, \ from flask_security import Security, SQLAlchemyUserDatastore, user_registered
login_required, roles_required, user_registered
from flask_security.core import current_user
from flask_security.forms import LoginForm
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
import os import os
from config import config from config import config
from sqlalchemy.exc import IntegrityError from flask_security.forms import LoginForm
from flask.ext.security.forms import LoginForm from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from .forms import \ from .forms import *
CreatePitstopForm, \
EditVehicleForm, \
DeleteVehicleForm, \
SelectVehicleForm, \
DeleteAccountForm, \
DeletePitStopForm, \
EditPitstopForm, \
CreateConsumableForm, \
EditConsumableForm, \
DeletConsumableForm, \
SelectConsumableForm
app = Flask(__name__) app = Flask(__name__)
app.config.from_object(config[os.getenv('FLASK_CONFIG') or 'default']) app.config.from_object(config[os.getenv('FLASK_CONFIG') or 'default'])
limiter = Limiter(
app,
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"]
)
@app.errorhandler(429)
def ratelimit_handler(e):
return make_response(
jsonify(error="ratelimit exceeded %s" % e.description)
, 429
)
db = SQLAlchemy(app) db = SQLAlchemy(app)
mail = Mail(app) mail = Mail(app)
from .entities import \ from .entities import *
User, \
Role, \
Pitstop, \
Vehicle, \
Consumable
# required to activate the filters
from .filters import *
from .tools import *
user_datastore = SQLAlchemyUserDatastore(db, User, Role) user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore) security = Security(app, user_datastore)
# required to activate the filters
from .filters import *
from .tools import *
from .routes import *
@user_registered.connect_via(app) @user_registered.connect_via(app)
def user_registered_sighandler(app, user, confirm_token): def user_registered_sighandler(application, user, confirm_token):
""" """
Called after a user was created Called after a user was created
""" """
role = user_datastore.find_role('user') role = user_datastore.find_role('user')
user_datastore.add_role_to_user(user, role) user_datastore.add_role_to_user(user, role)
if user.email == application.config['ADMIN_MAIL']:
# if the user selected the preconfigured email for the admin account
role = user_datastore.find_role('admin')
user_datastore.add_role_to_user(user, role)
new_vehicle = Vehicle('default vehicle') new_vehicle = Vehicle('default vehicle')
db.session.add(new_vehicle) db.session.add(new_vehicle)
user.vehicles.append(new_vehicle) user.vehicles.append(new_vehicle)
@@ -66,9 +61,21 @@ def user_registered_sighandler(app, 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()
@@ -112,377 +119,3 @@ def index():
return render_template('index.html', login_user_form=LoginForm(), data=data) return render_template('index.html', login_user_form=LoginForm(), data=data)
@app.route('/account/vehicle/edit/<int:vid>', methods=['GET', 'POST'])
@login_required
def edit_vehicle(vid):
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
# prevent edit of foreign vehicles
if vehicle not in current_user.vehicles:
return redirect(url_for('get_account_page'))
form = EditVehicleForm()
form.consumables.choices = [(g.id, g.name) for g in Consumable.query.all()]
if not form.consumables.data:
form.consumables.default = [g.id for g in vehicle.consumables]
if form.name.data is not None:
form.name.default = form.name.data
if form.validate_on_submit():
vehicle.name = form.name.data
# we cannot delete consumables where there are pitstops for => report error
vehicle.consumables = []
for consumable_id in form.consumables.data:
consumable = Consumable.query.get(consumable_id)
if consumable is not None:
vehicle.consumables.append(consumable)
try:
db.session.commit()
tools.db_log_update(vehicle)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('editVehicleForm.html', form=form)
return redirect(url_for('get_account_page'))
form.name.default = vehicle.name
form.process()
return render_template('editVehicleForm.html', form=form, vehicle=vehicle)
@app.route('/account/vehicle/delete/<int:vid>', methods=['GET', 'POST'])
@login_required
def delete_vehicle(vid):
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
# prevent deletion of foreign vehicles
if vehicle not in current_user.vehicles:
return redirect(url_for('get_account_page'))
if len(current_user.vehicles) == 1:
return redirect(url_for('get_account_page'))
form = DeleteVehicleForm()
if form.validate_on_submit():
db.session.delete(vehicle)
db.session.commit()
tools.db_log_delete(vehicle)
return redirect(url_for('get_account_page'))
return render_template('deleteVehicleForm.html', form=form, vehicle=vehicle)
@app.route('/account/vehicle/create', methods=['GET', 'POST'])
@login_required
def create_vehicle():
form = EditVehicleForm()
form.consumables.choices = [(g.id, g.name) for g in Consumable.query.all()]
if form.name.data is not None:
form.name.default = form.name.data
if form.consumables.data:
form.consumables.default = form.consumables.data
else:
form.consumables.default = []
if form.validate_on_submit():
if len(form.consumables.data) == 0:
form.consumables.errors.append('At least one consumable must be selected.')
return render_template('createVehicleForm.html', form=form)
vehicle_name = form.name.data
new_vehicle = Vehicle(vehicle_name)
for consumable_id in form.consumables.data:
consumable = Consumable.query.get(consumable_id)
if consumable is not None:
new_vehicle.consumables.append(consumable)
db.session.add(new_vehicle)
current_user.vehicles.append(new_vehicle)
try:
db.session.commit()
tools.db_log_add(new_vehicle)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('createVehicleForm.html', form=form)
return redirect(url_for('get_account_page'))
return render_template('createVehicleForm.html', form=form)
@app.route('/pitstops/vehicle/select', methods=['GET', 'POST'])
@login_required
def select_vehicle_for_new_pitstop():
if len(current_user.vehicles) == 1:
return redirect(url_for('select_consumable_for_new_pitstop', vid=current_user.vehicles[0].id))
form = SelectVehicleForm()
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
if form.validate_on_submit():
return redirect(url_for('select_consumable_for_new_pitstop', vid=form.vehicle.data))
return render_template('selectVehicle.html', form=form)
@app.route('/pitstops/vehicle/<int:vid>/consumable/select', methods=['GET', 'POST'])
@login_required
def select_consumable_for_new_pitstop(vid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
if len(vehicle.consumables) == 1:
return redirect(url_for('create_pit_stop_form', vid=vid, cid=vehicle.consumables[0].id))
form = SelectConsumableForm()
form.consumable.choices = [(g.id, g.name) for g in vehicle.consumables]
if form.validate_on_submit():
return redirect(url_for('create_pit_stop_form', vid=vid, cid=form.consumable.data))
return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form)
@app.route('/pitstops/vehicle/<int:vid>/consumable/<int:cid>/create', methods=['GET', 'POST'])
@login_required
def create_pit_stop_form(vid, cid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
consumable = Consumable.query.get(cid)
if consumable not in vehicle.consumables:
return redirect(url_for('select_consumable_for_new_pitstop', vid=vid))
form = CreatePitstopForm()
# the last pitstop is required to be able to check the monotonicy of date and odometer
last_pitstop = tools.get_latest_pitstop_for_vehicle(vid)
last_pitstop_consumable = tools.get_latest_pitstop_for_vehicle_and_consumable(vid, cid)
# we can enter the same odometer if the pitstops are not equal
form.same_odometer_allowed = (last_pitstop != last_pitstop_consumable)
# set the lower limits for odometer andd date and the values for amount and costs of the last stop
form.set_pitstop(tools.compute_lower_limits_for_new_pitstop(last_pitstop, last_pitstop_consumable, cid))
# set the label of the litres field to make the user comfortable
form.set_consumable(consumable)
# preinitialize the defaults with potentially existing values from a try before
form.preinit_with_data()
#
# Validate should accept same odometer on different consumables
#
if form.validate_on_submit():
new_stop = Pitstop(form.odometer.data, form.litres.data, form.date.data, form.costs.data, cid)
db.session.add(new_stop)
vehicle.pitstops.append(new_stop)
try:
db.session.commit()
tools.db_log_add(new_stop)
except IntegrityError:
db.session.rollback()
form.odometer.errors.append('Pitstop already present for %s at odometer %s km!' % (consumable.name, form.odometer.data))
return render_template('createPitStopForm.html', form=form, vehicle=vehicle, messages=form.get_hint_messages())
return redirect(url_for('get_pit_stops', _anchor= 'v' + str(vehicle.id)))
form.process()
return render_template('createPitStopForm.html', form=form, vehicle=vehicle, messages=form.get_hint_messages())
@app.route('/pitstops/delete/<int:pid>', methods=['GET', 'POST'])
@login_required
def delete_pit_stop_form(pid):
pitstop = Pitstop.query.filter(Pitstop.id == pid).first()
if pitstop is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == pitstop.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
form = DeletePitStopForm()
if form.validate_on_submit():
db.session.delete(pitstop)
db.session.commit()
tools.db_log_delete(pitstop)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
return render_template('deletePitstopForm.html', form=form, pitstop=pitstop )
@app.route('/pitstops/edit/<int:pid>', methods=['GET', 'POST'])
@login_required
def edit_pit_stop_form(pid):
edit_pitstop = Pitstop.query.get(pid)
if edit_pitstop is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == edit_pitstop.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
last_pitstop_pos = vehicle.pitstops.index(edit_pitstop) - 1
if last_pitstop_pos > 0:
last_pitstop = vehicle.pitstops[last_pitstop_pos]
else:
last_pitstop = Pitstop(0, 0, date(1970, 1, 1), 0, 0)
form = EditPitstopForm()
form.set_pitstop(last_pitstop)
if form.validate_on_submit():
edit_pitstop.costs = form.costs.data
edit_pitstop.date = form.date.data
edit_pitstop.amount = form.litres.data
edit_pitstop.odometer = form.odometer.data
db.session.commit()
tools.db_log_update(edit_pitstop)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
form.odometer.default = edit_pitstop.odometer
form.litres.default = edit_pitstop.amount
form.date.default = edit_pitstop.date
form.costs.default = edit_pitstop.costs
form.process()
messages = {
'date': 'Date must be between %s and %s (including).' % (str(last_pitstop.date), str(date.today())),
'odometer': 'Odometer must be greater than %s km.' % (str(last_pitstop.odometer))
}
if edit_pitstop.costs is not None and edit_pitstop.costs > 0:
messages['costs'] = 'Costs must be higher than 0.01 €.'
return render_template('editPitStopForm.html', form=form, vehicle=vehicle, messages=messages)
@app.route('/pitstops', methods=['GET'])
@login_required
def get_pit_stops():
return render_template('pitstops.html', user=current_user)
@app.route('/manual', methods=['GET'])
@login_required
def get_manual():
return render_template('manual.html', data=g.data)
@app.route('/admin', methods=['GET'])
@roles_required('admin')
def get_admin_page():
users = User.query.all()
consumables = Consumable.query.all()
for consumable in consumables:
consumable.in_use = len(consumable.vehicles) > 0
return render_template('admin.html', users=users, consumables=consumables)
@app.route('/admin/consumable/create', methods=['GET', 'POST'])
@login_required
def create_consumable():
form = CreateConsumableForm()
# 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.validate_on_submit():
new_consumable = Consumable(form.name.data, form.unit.data)
db.session.add(new_consumable)
try:
db.session.commit()
tools.db_log_add(new_consumable)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('createConsumableForm.html', form=form)
return redirect(url_for('get_admin_page'))
return render_template('createConsumableForm.html', form=form)
@app.route('/admin/consumable/delete/<int:cid>', methods=['GET', 'POST'])
@login_required
def delete_consumable(cid):
consumable = Consumable.query.filter(Consumable.id == cid).first()
if consumable is None:
return redirect(url_for('get_admin_page'))
form = DeletConsumableForm()
if form.validate_on_submit():
db.session.delete(consumable)
db.session.commit()
tools.db_log_delete(consumable)
return redirect(url_for('get_admin_page'))
return render_template('deleteConsumableForm.html', form=form, consumable=consumable)
@app.route('/admin/consumable/edit/<int:cid>', methods=['GET', 'POST'])
@login_required
def edit_consumable(cid):
consumable = Consumable.query.filter(Consumable.id == cid).first()
if consumable is None:
return redirect(url_for('get_admin_page'))
form = EditConsumableForm()
form.name.default = consumable.name
form.unit.default = consumable.unit
# 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.validate_on_submit():
consumable.name = form.name.data
consumable.unit = form.unit.data
try:
db.session.commit()
tools.db_log_update(consumable)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('editConsumableForm.html', form=form)
return redirect(url_for('get_admin_page'))
return render_template('editConsumableForm.html', form=form)
@app.route('/account', methods=['GET'])
@login_required
def get_account_page():
return render_template('account.html', data=g.data)
@app.route('/statistics', methods=['GET'])
@login_required
def get_statistics():
stats = []
for vehicle in current_user.vehicles:
stats.append(tools.VehicleStats(vehicle))
return render_template('statistics.html', data=stats)
@app.route('/account/delete', methods=['GET', 'POST'])
@login_required
def delete_account():
form = DeleteAccountForm()
if form.validate_on_submit():
user_datastore.delete_user(current_user)
db.session.commit()
return redirect(url_for('index'))
return render_template('deleteAccountForm.html', form=form)

View File

@@ -10,6 +10,11 @@ vehicles_consumables = db.Table('vehicles_consumables',
db.Column('consumable_id', db.Integer(), db.ForeignKey('consumable.id'))) db.Column('consumable_id', db.Integer(), db.ForeignKey('consumable.id')))
users_fillingstations = db.Table('users_fillingstations',
db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
db.Column('fillingstation_id', db.Integer(), db.ForeignKey('filling_station.int_id')))
class Role(db.Model, RoleMixin): class Role(db.Model, RoleMixin):
""" """
Entity to handle different roles for users: Typically user and admin exist Entity to handle different roles for users: Typically user and admin exist
@@ -34,6 +39,9 @@ class User(db.Model, UserMixin):
password = db.Column(db.String(255)) password = db.Column(db.String(255))
active = db.Column(db.Boolean()) active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime()) confirmed_at = db.Column(db.DateTime())
home_lat = db.Column(db.Numeric(8, 5), default=0)
home_long = db.Column(db.Numeric(8, 5), default=0)
home_zoom = db.Column(db.Integer(), default=0)
vehicles = db.relationship( vehicles = db.relationship(
'Vehicle' 'Vehicle'
@@ -43,6 +51,10 @@ class User(db.Model, UserMixin):
secondary=roles_users, secondary=roles_users,
backref=db.backref('users', lazy='dynamic') backref=db.backref('users', lazy='dynamic')
) )
favourite_filling_stations = db.relationship(
'FillingStation',
secondary=users_fillingstations
)
def __repr__(self): def __repr__(self):
return '<User id="%r" email="%r" ' % (self.id, self.email) return '<User id="%r" email="%r" ' % (self.id, self.email)
@@ -63,6 +75,9 @@ class Vehicle(db.Model):
pitstops = db.relationship( pitstops = db.relationship(
'Pitstop' 'Pitstop'
) )
services = db.relationship(
'Service'
)
consumables = db.relationship( consumables = db.relationship(
'Consumable', 'Consumable',
secondary=vehicles_consumables secondary=vehicles_consumables
@@ -127,6 +142,7 @@ 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( vehicles = db.relationship(
@@ -134,9 +150,59 @@ class Consumable(db.Model):
secondary=vehicles_consumables secondary=vehicles_consumables
) )
def __init__(self, name, unit): def __init__(self, name, ext_id, unit):
self.name = name self.name = name
self.ext_id = ext_id
self.unit = unit self.unit = unit
def __repr__(self): def __repr__(self):
return '<Consumable name="%s" unit="%s" />' % (self.name, self.unit) return '<Consumable name="%s" unit="%s" />' % (self.name, self.unit)
class Service(db.Model):
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.Date)
odometer = db.Column(db.Integer)
vehicle_id = db.Column(db.Integer, db.ForeignKey('vehicle.id'))
costs = db.Column(db.Numeric(10, 2), default=0)
description = db.Column(db.String(4096))
def __init__(self, date, odometer, vehicle_id, costs, description):
self.description = description
self.costs = costs
self.date = date
self.odometer = odometer
self.vehicle_id = vehicle_id
def __repr__(self):
return '<Service odometer="%r" date="%r" vehicle_id="%r" costs="%r" description="%r">' % \
(self.odometer, self.date, self.vehicle_id, self.costs, self.description)
class FillingStation(db.Model):
int_id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.String(40), unique=True, nullable=False)
name = db.Column(db.Text(), nullable=False)
street = db.Column(db.Text(), nullable=False)
place = db.Column(db.Text(), nullable=False)
houseNumber = db.Column(db.Text())
postCode = db.Column(db.Integer(), nullable=False)
brand = db.Column(db.Text(), nullable=False)
lat = db.Column(db.Numeric(8, 5), nullable=False)
lng = db.Column(db.Numeric(8, 5), nullable=False)
last_update = db.Column(db.DateTime)
diesel = db.Column(db.Numeric(10, 3), default=0)
e5 = db.Column(db.Numeric(10, 3), default=0)
e10 = db.Column(db.Numeric(10, 3), default=0)
open = db.Column(db.Boolean())
def as_dict(self):
res = {}
for c in self.__table__.columns:
val = getattr(self, c.name)
import decimal
if isinstance(val, decimal.Decimal):
val = float(val)
val = str(val)
res[c.name] = val
return res

View File

@@ -1,5 +1,6 @@
from app import app from app import app
import hashlib import hashlib
import markdown
@app.template_filter('none_filter') @app.template_filter('none_filter')
@@ -20,3 +21,8 @@ def md5_filter(value):
@app.template_filter('str') @app.template_filter('str')
def str_filter(value): def str_filter(value):
return str(value) return str(value)
@app.template_filter('markdown')
def md(value):
return markdown.markdown(value)

View File

@@ -1,169 +0,0 @@
from flask_wtf import Form
from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField, SelectMultipleField, BooleanField
from wtforms.validators import ValidationError, Length
from datetime import date
def date_check(form, field):
"""
Checks that the date of the pitstop is not before the date of the latest pitstop and not after today.
:param form: the form where the field is in
:param field: the field to check
:return: Nothing or a ValidationError if the limits are not kept
"""
if field.data < form.last_pitstop.date:
raise ValidationError('The new date must not be before %s' % form.last_pitstop.date)
if field.data > date.today():
raise ValidationError('The new date must not be after %s' % date.today())
def odometer_check(form, field):
"""
:param form:
:param field:
:return:
"""
if not form.same_odometer_allowed and field.data <= form.last_pitstop.odometer:
raise ValidationError('The new odometer value must be higher than %i km' % form.last_pitstop.odometer)
if form.same_odometer_allowed and field.data < form.last_pitstop.odometer:
raise ValidationError('The new odometer value must be higher than %i km' % form.last_pitstop.odometer)
def litres_check(form, field):
if field.data is not None and field.data <= 0:
raise ValidationError('You must fuel at least 0.1 l')
def costs_check(form, field):
if field.data is not None and field.data <= 0:
raise ValidationError('Costs must be above 0.01 €.')
def edit_costs_check(form, field):
"""
Costs must be given, if a default value was given to the form field.
:param form:
:param field:
:return:
"""
costs_check_required = (form.costs.default is not None and form.costs.default > 0)
if costs_check_required and field.data is not None and field.data <= 0:
raise ValidationError('Costs must be above 0.01 €.')
class SelectVehicleForm(Form):
vehicle = SelectField('Vehicle', coerce=int)
submit = SubmitField(label='Do it!')
class SelectConsumableForm(Form):
consumable = SelectField('Consumable', coerce=int)
submit = SubmitField(label='Do it!')
class CreatePitstopForm(Form):
date = DateField('Date of Pitstop', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
submit = SubmitField(label='Do it!')
last_pitstop = None
same_odometer_allowed = True
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_consumable(self, consumable):
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
else:
self.date.default = date.today()
if self.odometer.data:
self.odometer.default = self.odometer.data
else:
self.odometer.default = self.last_pitstop.odometer
if self.litres.data:
self.litres.default = self.litres.data
else:
self.litres.default = self.last_pitstop.amount
if self.costs.data:
self.costs.default = self.costs.data
else:
self.costs.default = self.last_pitstop.costs
def get_hint_messages(self):
if self.same_odometer_allowed:
or_equal = ' or equal to'
else:
or_equal = ''
messages = {
'date': 'Date must be between %s and %s (including).' % (str(self.last_pitstop.date), str(date.today())),
'odometer': 'Odometer must be greater than%s %s km.' % (or_equal, str(self.last_pitstop.odometer)),
'costs': 'Costs must be higher than 0.01 €.'
}
return messages
class EditVehicleForm(Form):
name = StringField('Name', validators=[Length(1, 255)])
consumables = SelectMultipleField('Consumables', coerce=int,validators=[])
submit = SubmitField(label='Do it!')
class DeleteVehicleForm(Form):
submit = SubmitField(label='Do it!')
class DeleteAccountForm(Form):
submit = SubmitField(label='Really delete my account!')
class DeletePitStopForm(Form):
submit = SubmitField(label='Really delete this pitstop!')
class EditPitstopForm(Form):
date = DateField('Date of Pitstop', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[edit_costs_check])
submit = SubmitField(label='Update it!')
last_pitstop = None
same_odometer_allowed = True
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_consumable(self, consumable):
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
if self.odometer.data:
self.odometer.default = self.odometer.data
if self.litres.data:
self.litres.default = self.litres.data
if self.costs.data:
self.costs.default = self.costs.data
class CreateConsumableForm(Form):
name = StringField('Name', validators=[Length(1, 255)])
unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!')
class EditConsumableForm(Form):
name = StringField('Name', validators=[Length(1, 255)])
unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!')
class DeletConsumableForm(Form):
submit = SubmitField(label='Do it!')

6
app/forms/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
from .misc import *
from .pitstop import *
from .checks import *
from .consumable import *
from .service import *
from .vehicle import *

53
app/forms/checks.py Normal file
View File

@@ -0,0 +1,53 @@
from wtforms.validators import ValidationError
from datetime import date
def date_check(form, field):
"""
Checks that the date of the pitstop is not before the date of the latest pitstop and not after today.
:param form: the form where the field is in
:param field: the field to check
:return: Nothing or a ValidationError if the limits are not kept
"""
if field.data < form.last_pitstop.date:
raise ValidationError('The new date must not be before %s' % form.last_pitstop.date)
if field.data > date.today():
raise ValidationError('The new date must not be after %s' % date.today())
def odometer_check(form, field):
"""
:param form:
:param field:
:return:
"""
if not form.same_odometer_allowed and field.data <= form.last_pitstop.odometer:
raise ValidationError('The new odometer value must be higher than %i km' % form.last_pitstop.odometer)
if form.same_odometer_allowed and field.data < form.last_pitstop.odometer:
raise ValidationError('The new odometer value must be higher than %i km' % form.last_pitstop.odometer)
def litres_check(form, field):
if field.data is not None and field.data <= 0:
raise ValidationError('You must fuel at least 0.1 l')
def costs_check(form, field):
if field.data is not None and field.data <= 0:
raise ValidationError('Costs must be above 0.01 €.')
def edit_costs_check(form, field):
"""
Costs must be given, if a default value was given to the form field.
:param form:
:param field:
:return:
"""
costs_check_required = (form.costs.default is not None and form.costs.default > 0)
if costs_check_required and field.data is not None and field.data <= 0:
raise ValidationError('Costs must be above 0.01 €.')

26
app/forms/consumable.py Normal file
View File

@@ -0,0 +1,26 @@
from flask_wtf import FlaskForm
from wtforms import SelectField, StringField, SubmitField
from wtforms.validators import Length
class SelectConsumableForm(FlaskForm):
consumable = SelectField('Consumable', coerce=int)
submit = SubmitField(label='Do it!')
class CreateConsumableForm(FlaskForm):
name = StringField('Name', validators=[Length(1, 255)])
ext_id = SelectField('Tankerkönig ID', coerce=int)
unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!')
class EditConsumableForm(FlaskForm):
name = StringField('Name', validators=[Length(1, 255)])
ext_id = SelectField('Tankerkönig ID', coerce=int)
unit = StringField('Unit', validators=[Length(1, 255)])
submit = SubmitField(label='Do it!')
class DeletConsumableForm(FlaskForm):
submit = SubmitField(label='Do it!')

6
app/forms/misc.py Normal file
View File

@@ -0,0 +1,6 @@
from flask_wtf import FlaskForm
from wtforms import SubmitField
class DeleteAccountForm(FlaskForm):
submit = SubmitField(label='Really delete my account!')

82
app/forms/pitstop.py Normal file
View File

@@ -0,0 +1,82 @@
from flask_wtf import FlaskForm
from wtforms import DateField, IntegerField, DecimalField, SubmitField
from .checks import *
class DeletePitStopForm(FlaskForm):
submit = SubmitField(label='Really delete this pitstop!')
class EditPitstopForm(FlaskForm):
date = DateField('Date of Pitstop', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[edit_costs_check])
submit = SubmitField(label='Update it!')
last_pitstop = None
same_odometer_allowed = True
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_consumable(self, consumable):
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
if self.odometer.data:
self.odometer.default = self.odometer.data
if self.litres.data:
self.litres.default = self.litres.data
if self.costs.data:
self.costs.default = self.costs.data
class CreatePitstopForm(FlaskForm):
date = DateField('Date of Pitstop', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
submit = SubmitField(label='Do it!')
last_pitstop = None
same_odometer_allowed = True
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def set_consumable(self, consumable):
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
else:
self.date.default = date.today()
if self.odometer.data:
self.odometer.default = self.odometer.data
else:
self.odometer.default = self.last_pitstop.odometer
if self.litres.data:
self.litres.default = self.litres.data
else:
self.litres.default = self.last_pitstop.amount
if self.costs.data:
self.costs.default = self.costs.data
else:
self.costs.default = self.last_pitstop.costs
def get_hint_messages(self):
if self.same_odometer_allowed:
or_equal = ' or equal to'
else:
or_equal = ''
messages = {
'date': 'Date must be between %s and %s (including).' % (str(self.last_pitstop.date), str(date.today())),
'odometer': 'Odometer must be greater than%s %s km.' % (or_equal, str(self.last_pitstop.odometer)),
'costs': 'Costs must be higher than 0.01 €.'
}
return messages

68
app/forms/service.py Normal file
View File

@@ -0,0 +1,68 @@
from flask_wtf import FlaskForm
from wtforms import DateField, IntegerField, DecimalField, SubmitField, TextAreaField
from wtforms.validators import Length
from .checks import *
class CreateServiceForm(FlaskForm):
date = DateField('Date of Service', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
description = TextAreaField('Description', validators=[Length(1, 4096)])
submit = SubmitField(label='Do it!')
last_pitstop = None
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
else:
self.date.default = date.today()
if self.odometer.data:
self.odometer.default = self.odometer.data
else:
self.odometer.default = self.last_pitstop.odometer
if self.costs.data:
self.costs.default = self.costs.data
else:
self.costs.default = 0
class DeleteServiceForm(FlaskForm):
submit = SubmitField(label='Really delete this service!')
class EditServiceForm(FlaskForm):
date = DateField('Date of Service', validators=[date_check])
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
description = TextAreaField('Description', validators=[Length(1, 4096)])
submit = SubmitField(label='Do it!')
last_pitstop = None
same_odometer_allowed = True
def set_pitstop(self, last_pitstop):
self.last_pitstop = last_pitstop
def preinit_with_data(self):
if self.date.data:
self.date.default = self.date.data
else:
self.date.default = date.today()
if self.odometer.data:
self.odometer.default = self.odometer.data
else:
self.odometer.default = self.last_pitstop.odometer
if self.costs.data:
self.costs.default = self.costs.data
else:
self.costs.default = 0

20
app/forms/vehicle.py Normal file
View File

@@ -0,0 +1,20 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField, SelectMultipleField
from wtforms.validators import Length
class SelectVehicleForm(FlaskForm):
vehicle = SelectField('Vehicle', coerce=int)
submit = SubmitField(label='Do it!')
class EditVehicleForm(FlaskForm):
name = StringField('Name', validators=[Length(1, 255)])
consumables = SelectMultipleField('Consumables', coerce=int,validators=[])
submit = SubmitField(label='Do it!')
class DeleteVehicleForm(FlaskForm):
submit = SubmitField(label='Do it!')

6
app/routes/__init__.py Normal file
View File

@@ -0,0 +1,6 @@
from .account import *
from .admin import *
from .misc import *
from .pitstop import *
from .service import *
from .filling_stations import *

155
app/routes/account.py Normal file
View File

@@ -0,0 +1,155 @@
from flask import url_for, redirect, render_template, request, jsonify
from flask_security import login_required
from flask_security.core import current_user
from sqlalchemy.exc import IntegrityError
import json
from ..entities import Vehicle, Consumable
from ..forms import EditVehicleForm, DeleteVehicleForm, DeleteAccountForm
from ..tools import db_log_update, db_log_delete, db_log_add
from .. import app, db, user_datastore
@app.route('/account', methods=['GET'])
@login_required
def get_account_page():
stations = [x.as_dict() for x in current_user.favourite_filling_stations]
for station in stations:
station['state'] = 'favourite'
return render_template('account.html',
map_pos=(current_user.home_lat, current_user.home_long, current_user.home_zoom),
fs=json.dumps(stations))
@app.route('/account/vehicle/edit/<int:vid>', methods=['GET', 'POST'])
@login_required
def edit_vehicle(vid):
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
# prevent edit of foreign vehicles
if vehicle not in current_user.vehicles:
return redirect(url_for('get_account_page'))
form = EditVehicleForm()
form.consumables.choices = [(g.id, g.name) for g in Consumable.query.all()]
if not form.consumables.data:
form.consumables.default = [g.id for g in vehicle.consumables]
if form.name.data is not None:
form.name.default = form.name.data
if form.validate_on_submit():
vehicle.name = form.name.data
# we cannot delete consumables where there are pitstops for => report error
vehicle.consumables = []
for consumable_id in form.consumables.data:
consumable = Consumable.query.get(consumable_id)
if consumable is not None:
vehicle.consumables.append(consumable)
try:
db.session.commit()
db_log_update(vehicle)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('editVehicleForm.html', form=form)
return redirect(url_for('get_account_page'))
form.name.default = vehicle.name
form.process()
return render_template('editVehicleForm.html', form=form, vehicle=vehicle)
@app.route('/account/vehicle/delete/<int:vid>', methods=['GET', 'POST'])
@login_required
def delete_vehicle(vid):
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
# prevent deletion of foreign vehicles
if vehicle not in current_user.vehicles:
return redirect(url_for('get_account_page'))
if len(current_user.vehicles) == 1:
return redirect(url_for('get_account_page'))
form = DeleteVehicleForm()
if form.validate_on_submit():
db.session.delete(vehicle)
db.session.commit()
db_log_delete(vehicle)
return redirect(url_for('get_account_page'))
return render_template('deleteVehicleForm.html', form=form, vehicle=vehicle)
@app.route('/account/vehicle/create', methods=['GET', 'POST'])
@login_required
def create_vehicle():
form = EditVehicleForm()
form.consumables.choices = [(g.id, g.name) for g in Consumable.query.all()]
if form.name.data is not None:
form.name.default = form.name.data
if form.consumables.data:
form.consumables.default = form.consumables.data
else:
form.consumables.default = []
if form.validate_on_submit():
if len(form.consumables.data) == 0:
form.consumables.errors.append('At least one consumable must be selected.')
return render_template('createVehicleForm.html', form=form)
vehicle_name = form.name.data
new_vehicle = Vehicle(vehicle_name)
for consumable_id in form.consumables.data:
consumable = Consumable.query.get(consumable_id)
if consumable is not None:
new_vehicle.consumables.append(consumable)
db.session.add(new_vehicle)
current_user.vehicles.append(new_vehicle)
try:
db.session.commit()
db_log_add(new_vehicle)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('createVehicleForm.html', form=form)
return redirect(url_for('get_account_page'))
return render_template('createVehicleForm.html', form=form)
@app.route('/account/delete', methods=['GET', 'POST'])
@login_required
def delete_account():
form = DeleteAccountForm()
if form.validate_on_submit():
user_datastore.delete_user(current_user)
db.session.commit()
return redirect(url_for('index'))
return render_template('deleteAccountForm.html', form=form)
@app.route('/account/home', methods=['GET'])
@login_required
def get_users_home():
return jsonify(
{'lat': float(current_user.home_lat), 'long': float(current_user.home_long), 'zoom': current_user.home_zoom})
@app.route('/account/home', methods=['POST'])
@login_required
def set_users_home():
current_user.home_lat = request.json['lat']
current_user.home_long = request.json['long']
current_user.home_zoom = request.json['zoom']
db.session.commit()
return jsonify({})

107
app/routes/admin.py Normal file
View File

@@ -0,0 +1,107 @@
from flask import url_for, redirect, render_template
from flask_security import login_required, roles_required
from sqlalchemy.exc import IntegrityError
from ..entities import User, Consumable
from ..forms import CreateConsumableForm, DeletConsumableForm, EditConsumableForm
from ..tools import db_log_update, db_log_delete, db_log_add
from .. import app, db
@app.route('/admin', methods=['GET'])
@roles_required('admin')
def get_admin_page():
users = User.query.all()
consumables = Consumable.query.all()
for consumable in consumables:
consumable.in_use = len(consumable.vehicles) > 0
return render_template('admin.html', users=users, consumables=consumables)
@app.route('/admin/consumable/create', methods=['GET', 'POST'])
@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:
form.name.default = form.name.data
if form.unit.data is not None:
form.unit.default = form.unit.data
if form.validate_on_submit():
new_consumable = Consumable(form.name.data, choices[form.ext_id.data][1], form.unit.data)
db.session.add(new_consumable)
try:
db.session.commit()
db_log_add(new_consumable)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('createConsumableForm.html', form=form)
return redirect(url_for('get_admin_page'))
return render_template('createConsumableForm.html', form=form)
@app.route('/admin/consumable/delete/<int:cid>', methods=['GET', 'POST'])
@login_required
def delete_consumable(cid):
consumable = Consumable.query.filter(Consumable.id == cid).first()
if consumable is None:
return redirect(url_for('get_admin_page'))
form = DeletConsumableForm()
if form.validate_on_submit():
db.session.delete(consumable)
db.session.commit()
db_log_delete(consumable)
return redirect(url_for('get_admin_page'))
return render_template('deleteConsumableForm.html', form=form, consumable=consumable)
@app.route('/admin/consumable/edit/<int:cid>', methods=['GET', 'POST'])
@login_required
def edit_consumable(cid):
consumable = Consumable.query.filter(Consumable.id == cid).first()
if consumable is None:
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
consumable.ext_id = choices[form.ext_id.data][1]
try:
db.session.commit()
db_log_update(consumable)
except IntegrityError:
db.session.rollback()
form.name.errors.append('"%s" is not unique.' % (form.name.data))
return render_template('editConsumableForm.html', form=form)
return redirect(url_for('get_admin_page'))
return render_template('editConsumableForm.html', form=form)

View File

@@ -0,0 +1,62 @@
from flask import request, jsonify
from flask_security import login_required
from flask_security.core import current_user
import requests
from ..entities import FillingStation
from .. import app, db, limiter
@app.route('/filling_stations/favourites/toggle/<fsid>')
def add_favourite_filling_stations(fsid):
favourite_ids = {x.id: x for x in current_user.favourite_filling_stations}
if fsid in favourite_ids:
current_user.favourite_filling_stations.remove(favourite_ids[fsid])
state = 'normal'
else:
fs = FillingStation.query.filter(FillingStation.id == fsid).first()
current_user.favourite_filling_stations.append(fs)
state = 'favourite'
db.session.commit()
return jsonify({'state': state})
@app.route('/filling_stations', methods=['GET'])
@login_required
@limiter.limit('1 per second')
def query_filling_stations():
api_key = app.config['TANKERKOENIG_API_KEY']
latitude = request.args.get('latitude')
longitude = request.args.get('longitude')
radius = request.args.get('radius', default=1.5)
gas_type = request.args.get('type', default='all')
sort = request.args.get('sort', default='dist')
url = 'https://creativecommons.tankerkoenig.de/json/list.php'
params = {
'lat': latitude, 'lng': longitude, 'rad': radius, 'apikey': api_key, 'type': gas_type, 'sort': sort
}
response = requests.get(url, params=params)
data = response.json()
for station in data['stations']:
fs = FillingStation.query.filter(FillingStation.id == station['id']).first()
if not fs:
fs = FillingStation()
fs.id = station['id']
fs.brand = station['brand']
fs.lat = station['lat']
fs.lng = station['lng']
fs.name = station['name']
fs.street = station['street']
fs.place = station['place']
fs.houseNumber = station['houseNumber']
fs.postCode = station['postCode']
db.session.add(fs)
if fs in current_user.favourite_filling_stations:
station['state'] = 'favourite'
else:
station['state'] = 'normal'
db.session.commit()
return jsonify(data)

22
app/routes/misc.py Normal file
View File

@@ -0,0 +1,22 @@
from flask import render_template
from flask_security import login_required
from flask_security.core import current_user
from ..tools import VehicleStats
from .. import app
@app.route('/statistics', methods=['GET'])
@login_required
def get_statistics():
stats = []
for vehicle in current_user.vehicles:
stats.append(VehicleStats(vehicle))
return render_template('statistics.html', data=stats)
@app.route('/manual', methods=['GET'])
@login_required
def get_manual():
return render_template('manual.html')

243
app/routes/pitstop.py Normal file
View File

@@ -0,0 +1,243 @@
from flask import url_for, redirect, render_template, flash
from flask_security import login_required
from flask_security.core import current_user
from sqlalchemy.exc import IntegrityError
from datetime import date
from ..entities import Vehicle, Consumable, Pitstop
from ..forms import SelectVehicleForm, SelectConsumableForm, CreatePitstopForm, EditPitstopForm, DeletePitStopForm
from ..tools import db_log_update, db_log_delete, db_log_add, pitstop_service_key, \
get_event_line_for_vehicle, update_filling_station_prices
from .. import app, db
@app.route('/pitstops/vehicle/select', methods=['GET', 'POST'])
@login_required
def select_vehicle_for_new_pitstop():
if len(current_user.vehicles) == 1:
return redirect(url_for('select_consumable_for_new_pitstop', vid=current_user.vehicles[0].id))
form = SelectVehicleForm()
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
if form.validate_on_submit():
return redirect(url_for('select_consumable_for_new_pitstop', vid=form.vehicle.data))
return render_template('selectVehicle.html', form=form)
@app.route('/pitstops/vehicle/<int:vid>/consumable/select', methods=['GET', 'POST'])
@login_required
def select_consumable_for_new_pitstop(vid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
if len(vehicle.consumables) == 0:
flash('Please choose at least one consumable!', 'warning')
return redirect(url_for('edit_vehicle', vid=vid))
if len(vehicle.consumables) == 1:
return redirect(url_for('create_pit_stop_form', vid=vid, cid=vehicle.consumables[0].id))
form = SelectConsumableForm()
form.consumable.choices = [(g.id, g.name) for g in vehicle.consumables]
if form.validate_on_submit():
return redirect(url_for('create_pit_stop_form', vid=vid, cid=form.consumable.data))
return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form)
@app.route('/pitstops/vehicle/<int:vid>/consumable/<int:cid>/create', methods=['GET', 'POST'])
@login_required
def create_pit_stop_form(vid, cid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
consumable = Consumable.query.get(cid)
if consumable not in vehicle.consumables:
return redirect(url_for('select_consumable_for_new_pitstop', vid=vid))
form = CreatePitstopForm()
data = get_event_line_for_vehicle(vehicle)
if len(data) > 0:
form.set_pitstop(Pitstop(data[-1].odometer, 0, data[-1].date, 0, cid))
form.same_odometer_allowed = (type(data[-1]) != Pitstop) or (data[-1].consumable.id != cid)
else:
form.set_pitstop(Pitstop(date(1970, 1, 1), 0, vid, 0, ''))
form.set_pitstop(Pitstop(0, 0, date(1970, 1, 1), 0, cid))
form.same_odometer_allowed = True
# set the label of the litres field to make the user comfortable
form.set_consumable(consumable)
# preinitialize the defaults with potentially existing values from a try before
form.preinit_with_data()
#
# Validate should accept same odometer on different consumables
#
if form.validate_on_submit():
new_stop = Pitstop(form.odometer.data, form.litres.data, form.date.data, form.costs.data, cid)
db.session.add(new_stop)
vehicle.pitstops.append(new_stop)
try:
db.session.commit()
db_log_add(new_stop)
except IntegrityError:
db.session.rollback()
form.odometer.errors.append('Pitstop already present for %s at odometer %s km!' % (consumable.name, form.odometer.data))
return render_template('createPitStopForm.html', form=form, vehicle=vehicle, messages=form.get_hint_messages())
return redirect(url_for('get_pit_stops', _anchor= 'v' + str(vehicle.id)))
form.process()
return render_template('createPitStopForm.html', form=form, vehicle=vehicle, messages=form.get_hint_messages())
@app.route('/pitstops/delete/<int:pid>', methods=['GET', 'POST'])
@login_required
def delete_pit_stop_form(pid):
pitstop = Pitstop.query.filter(Pitstop.id == pid).first()
if pitstop is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == pitstop.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
form = DeletePitStopForm()
if form.validate_on_submit():
db.session.delete(pitstop)
db.session.commit()
db_log_delete(pitstop)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
return render_template('deletePitstopForm.html', form=form, pitstop=pitstop )
@app.route('/pitstops/edit/<int:pid>', methods=['GET', 'POST'])
@login_required
def edit_pit_stop_form(pid):
edit_pitstop = Pitstop.query.get(pid)
if edit_pitstop is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == edit_pitstop.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
last_pitstop_pos = vehicle.pitstops.index(edit_pitstop) - 1
if last_pitstop_pos > 0:
last_pitstop = vehicle.pitstops[last_pitstop_pos]
else:
last_pitstop = Pitstop(0, 0, date(1970, 1, 1), 0, 0)
form = EditPitstopForm()
form.set_pitstop(last_pitstop)
if form.validate_on_submit():
edit_pitstop.costs = form.costs.data
edit_pitstop.date = form.date.data
edit_pitstop.amount = form.litres.data
edit_pitstop.odometer = form.odometer.data
db.session.commit()
db_log_update(edit_pitstop)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
form.odometer.default = edit_pitstop.odometer
form.litres.default = edit_pitstop.amount
form.date.default = edit_pitstop.date
form.costs.default = edit_pitstop.costs
form.process()
messages = {
'date': 'Date must be between %s and %s (including).' % (str(last_pitstop.date), str(date.today())),
'odometer': 'Odometer must be greater than %s km.' % (str(last_pitstop.odometer))
}
if edit_pitstop.costs is not None and edit_pitstop.costs > 0:
messages['costs'] = 'Costs must be higher than 0.01 €.'
return render_template('editPitStopForm.html', form=form, vehicle=vehicle, messages=messages)
@app.route('/pitstops', methods=['GET'])
@login_required
def get_pit_stops():
user = {
'vehicles': []
}
for vehicle in current_user.vehicles:
data = []
for pitstop in vehicle.pitstops:
data.append(pitstop)
for service in vehicle.services:
data.append(service)
data.sort(key=pitstop_service_key)
v = {
'id': vehicle.id,
'name': vehicle.name,
'data': data
}
user['vehicles'].append(v)
return render_template('pitstops.html', user=user)
@app.route('/pitstops/plan/vehicle/select', methods=['GET', 'POST'])
@login_required
def select_vehicle_for_plan_pitstop():
if len(current_user.vehicles) == 1:
return redirect(url_for('select_consumable_for_plan_pitstop', vid=current_user.vehicles[0].id))
form = SelectVehicleForm()
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
if form.validate_on_submit():
return redirect(url_for('select_consumable_for_plan_pitstop', vid=form.vehicle.data))
return render_template('selectVehicle.html', form=form)
@app.route('/pitstops/plan/vehicle/<int:vid>/consumable/select', methods=['GET', 'POST'])
@login_required
def select_consumable_for_plan_pitstop(vid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_consumable_for_plan_pitstop'))
if len(vehicle.consumables) == 0:
flash('Please choose at least one consumable!', 'warning')
return redirect(url_for('edit_vehicle', vid=vid))
if len(vehicle.consumables) == 1:
return redirect(url_for('plan_pit_stop_form', vid=vid, cid=vehicle.consumables[0].id))
form = SelectConsumableForm()
form.consumable.choices = [(g.id, g.name) for g in vehicle.consumables]
if form.validate_on_submit():
return redirect(url_for('plan_pit_stop_form', vid=vid, cid=form.consumable.data))
return render_template('selectConsumableForVehicle.html', vehicle=vehicle, form=form)
@app.route('/pitstops/plan/vehicle/<int:vid>/consumable/<int:cid>', methods=['GET', 'POST'])
@login_required
def plan_pit_stop_form(vid, cid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('select_vehicle_for_new_pitstop'))
consumable = Consumable.query.get(cid)
if consumable not in vehicle.consumables:
return redirect(url_for('select_consumable_for_new_pitstop', vid=vid))
update_filling_station_prices([x.id for x in current_user.favourite_filling_stations])
offers = []
for fs in current_user.favourite_filling_stations:
offers.append((fs, getattr(fs, consumable.ext_id),))
return render_template('planPitStopForm.html', vehicle=vehicle, consumable=consumable, offers=offers)

120
app/routes/service.py Normal file
View File

@@ -0,0 +1,120 @@
from flask import url_for, redirect, render_template
from flask_security import login_required, current_user
from datetime import date
from ..entities import Vehicle, Service
from ..forms import CreateServiceForm, DeleteServiceForm, EditServiceForm, SelectVehicleForm
from ..tools import db_log_update, db_log_delete, get_event_line_for_vehicle, get_latest_pitstop_for_vehicle
from .. import app, db
@app.route('/service/vehicle/<int:vid>/create', methods=['GET', 'POST'])
@login_required
def create_service_for_vehicle(vid):
vehicle = Vehicle.query.get(vid)
if vehicle is None or vehicle not in current_user.vehicles:
return redirect(url_for('get_account_page'))
form = CreateServiceForm()
data = get_event_line_for_vehicle(vehicle)
if len(data) > 0:
form.set_pitstop(Service(data[-1].date, data[-1].odometer, vid, 0, ''))
form.same_odometer_allowed = type(data[-1]) != Service
else:
form.set_pitstop(Service(date(1970, 1, 1), 0, vid, 0, ''))
form.same_odometer_allowed = True
form.preinit_with_data()
if form.validate_on_submit():
new_service = Service(form.date.data, form.odometer.data, vid, form.costs.data, form.description.data)
db.session.add(new_service)
vehicle.services.append(new_service)
db.session.commit()
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
form.process()
return render_template('createServiceForm.html', form=form, vehicle=vehicle, messages=[])
@app.route('/service/delete/<int:sid>', methods=['GET', 'POST'])
@login_required
def delete_service_form(sid):
service = Service.query.filter(Service.id == sid).first()
if service is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == service.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
form = DeleteServiceForm()
if form.validate_on_submit():
db.session.delete(service)
db.session.commit()
db_log_delete(service)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
return render_template('deleteServiceForm.html', form=form, service=service )
@app.route('/service/edit/<int:sid>', methods=['GET', 'POST'])
@login_required
def edit_service_form(sid):
edit_service = Service.query.get(sid)
if edit_service is None:
return redirect(url_for('get_pit_stops'))
vehicle = Vehicle.query.filter(Vehicle.id == edit_service.vehicle_id).first()
if vehicle not in current_user.vehicles:
return redirect(url_for('get_pit_stops'))
form = EditServiceForm()
data = get_event_line_for_vehicle(vehicle)
data.reverse()
if len(data) > 0:
last_pitstop = Service(data[-1].date, data[-1].odometer, vehicle.id, 0, '')
else:
last_pitstop = Service(date(1970, 1, 1), 0, vehicle.id, 0, '')
form.set_pitstop(last_pitstop)
form.same_odometer_allowed = True
if form.validate_on_submit():
edit_service.costs = form.costs.data
edit_service.date = form.date.data
edit_service.description = form.description.data
edit_service.odometer = form.odometer.data
db.session.commit()
db_log_update(edit_service)
return redirect(url_for('get_pit_stops', _anchor='v' + str(vehicle.id)))
form.odometer.default = edit_service.odometer
form.description.default = edit_service.description
form.date.default = edit_service.date
form.costs.default = edit_service.costs
form.process()
messages = {
'date': 'Date must be between %s and %s (including).' % (str(last_pitstop.date), str(date.today())),
'odometer': 'Odometer must be greater than %s km.' % (str(last_pitstop.odometer))
}
if edit_service.costs is not None and edit_service.costs > 0:
messages['costs'] = 'Costs must be higher than 0.01 €.'
return render_template('editServiceForm.html', form=form, vehicle=vehicle, messages=messages)
@app.route('/service/vehicle/select', methods=['GET', 'POST'])
@login_required
def select_vehicle_for_new_service():
if len(current_user.vehicles) == 1:
return redirect(url_for('create_service_for_vehicle', vid=current_user.vehicles[0].id))
form = SelectVehicleForm()
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
if form.validate_on_submit():
return redirect(url_for('create_service_for_vehicle', vid=form.vehicle.data))
return render_template('selectVehicle.html', form=form)

View File

@@ -1,9 +1,18 @@
.markdown > h1 {
font-size: 14px;
font-weight: bold;
}
.markdown {
text-align: left
}
body { body {
padding-top: 50px; padding-top: 50px;
} }
.starter-template { .starter-template {
padding-top: 30px; padding-top: 0px;
padding-bottom: 60px; padding-bottom: 60px;
text-align: center; text-align: center;
} }
@@ -59,6 +68,14 @@ h3:after{
text-align: left; text-align: left;
} }
.alert {
margin-bottom:0px;
}
.topspace {
margin-top: 5px;
}
// for small devices // for small devices
@media only screen @media only screen
and (min-device-width : 320px) and (min-device-width : 320px)
@@ -75,4 +92,35 @@ and (max-device-width : 568px) {
#charts_tabs-content { #charts_tabs-content {
display:none; display:none;
} }
}
.filling_station_info {
margin: 5px;
border: 1px solid;
}
.filling_station_info img{
margin-top: 6px;
height:48px;
}
/*
* styling for sortable tables
*/
th.header {
background-image: url(../img/updown.gif);
background-repeat: no-repeat;
background-position: center right;
}
th.headerSortUp {
background-image: url(../img/down.gif);
}
th.headerSortDown {
background-image: url(../img/up.gif);
}
.filling_station_closed {
text-decoration: line-through;
} }

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
app/static/img/down.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

View File

Before

Width:  |  Height:  |  Size: 980 B

After

Width:  |  Height:  |  Size: 980 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
app/static/img/up.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

BIN
app/static/img/updown.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 B

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,184 @@
// initially display germany
var lat = 50.75653081787912,
lon = 9.262980794432847,
zoom = 5;
var map;
var filling_stations = {};
var filling_station_markers;
query_location = function(updater) {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
zoom = 11;
if(updater){
updater(lat, lon);
}
});
}
}
update_map = function() {
var lonLat = new OpenLayers.LonLat( lon, lat )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
map.setCenter (lonLat, zoom);
}
load_filling_stations = function() {
var url = '/filling_stations?latitude=' + lat + '&longitude='+ lon + '&type=all&radius=5&sort=dist';
$.ajax({
type: 'GET',
url: url,
success: function(data) {
data.stations.forEach(function(station) {
if (!(station.id in filling_stations)) {
filling_stations[station.id] = station;
filling_stations[station.id].marker = false;
}
});
update_filling_station_markers();
}
});
}
clicked_on_filling_station_marker = function(station, marker) {
return function(data) {
$.ajax({
type: 'GET',
url: '/filling_stations/favourites/toggle/'+station.id,
dataType: 'json',
timeout: 1000,
success: function(data) {
if (data.state == 'favourite') {
marker.setUrl('/static/img/filling_station_favourite_marker.png');
} else {
marker.setUrl('/static/img/filling_station_marker.png');
}
},
contentType : 'application/json'
});
}
}
display_station_information = function(station) {
return function(event) {
var info = $('#station_info');
info.empty();
info.addClass('filling_station_info');
var cell1 = $('<div>', {'class':'col-md-8'})
var cell2 = $('<div>', {'class':'col-md-4'})
var img = $('<img>', {'src': '/static/logos/'+station.brand.toLowerCase()+'.png'});
// hide if the brand icon loads with error
img.error(function(){
$(this).hide();
});
var name = $('<div>').text(station.name);
var street_number = $('<div>').text(station.street + ' ' + station.houseNumber);
var postcode_place = $('<div>').text(station.postCode + ' ' + station.place);
info.append(cell1
.append(name)
.append(street_number)
.append(postcode_place))
.append(cell2
.append(img));
cell2.height(cell1.height());
};
}
update_filling_station_markers = function() {
for(id in filling_stations) {
var station = filling_stations[id];
if(!station.marker) {
var lonLat = new OpenLayers.LonLat(station.lng, station.lat)
.transform(new OpenLayers.Projection('EPSG:4326'), map.getProjectionObject());
if (station.state == 'favourite') {
var icon = new OpenLayers.Icon('/static/img/filling_station_favourite_marker.png');
} else {
var icon = new OpenLayers.Icon('/static/img/filling_station_marker.png');
}
var marker = new OpenLayers.Marker(lonLat, icon);
marker.events.register('click', marker, clicked_on_filling_station_marker(station, marker));
marker.events.register('mouseover', null, display_station_information(station));
filling_station_markers.addMarker(marker);
station.marker = true;
}
}
}
activate_map = function(map_div_id, button_ids, home_lat, home_long, home_zoom, init_stations) {
// resize to reasonable height
$('#' + map_div_id).css('height',0.75*($('#' + map_div_id).css('width')));
// init map
map = new OpenLayers.Map(map_div_id);
map.addLayer(new OpenLayers.Layer.OSM());
map.events.register('moveend', null, function(e){
var p = e.object.center.clone();
var p = p.transform(map.getProjectionObject(), 'EPSG:4326');
lon = p.lon;
lat = p.lat;
zoom = e.object.zoom;
});
filling_station_markers = new OpenLayers.Layer.Markers('Filling Stations');
map.addLayer(filling_station_markers);
// handle initial / favourite stations
filling_stations = init_stations;
update_filling_station_markers();
update_map();
if ((home_lat == 0) && (home_long == 0)) {
query_location(update_map);
} else {
lat = home_lat;
lon = home_long;
zoom = home_zoom;
update_map();
}
// get button
$('#'+button_ids[0]).click(function(e){
load_filling_stations();
});
// set home button
$('#'+button_ids[1]).click(function(e){
$.ajax({
type: 'POST',
url: '/account/home',
data: JSON.stringify({'long': lon, 'lat': lat, 'zoom': zoom}),
dataType: 'json',
timeout: 1000,
contentType : 'application/json'
});
});
// go home button
$('#'+button_ids[2]).click(function(e){
$.ajax({
type: 'GET',
url: '/account/home',
dataType: 'json',
timeout: 1000,
success: function(data) {
lat = data.lat;
lon = data.long;
zoom = data.zoom;
update_map();
},
contentType : 'application/json'
});
});
}

File diff suppressed because one or more lines are too long

BIN
app/static/logos/agip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
app/static/logos/aral.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
app/static/logos/avia.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
app/static/logos/bft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
app/static/logos/esso.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
app/static/logos/hem.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
app/static/logos/jet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
app/static/logos/omv.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

BIN
app/static/logos/shell.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
app/static/logos/total.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
/*! normalize.css v3.0.2 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{height:auto}input[type=search]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:700}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

View File

@@ -5,7 +5,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Password</div> <div class="panel-heading">Password</div>
<div class="panel-body"> <div class="panel-body">
<a href='{{ url_for('security.change_password') }}' class="btn btn-primary " role="button"> <a href="{{ url_for('security.change_password') }}" id="change_password" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Change <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Change
</a> </a>
</div> </div>
@@ -13,7 +13,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Vehicles</div> <div class="panel-heading">Vehicles</div>
<div class="panel-body"> <div class="panel-body">
<a href="{{ url_for('create_vehicle') }}" class="btn btn-primary " role="button"> <a href="{{ url_for('create_vehicle') }}" id="create_vehicle" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create
</a> </a>
</div> </div>
@@ -37,14 +37,21 @@
</td> </td>
<td> <td>
{{ vehicle.pitstops | length }} pitstops<br /> {{ vehicle.pitstops | length }} pitstops<br />
{{ vehicle.services | length }} special expenses<br />
{{ vehicle.consumables | length }} consumables {{ vehicle.consumables | length }} consumables
</td> </td>
<td> <td>
<a href="{{ url_for('edit_vehicle', vid=vehicle.id) }}" class="btn btn-primary " role="button"> <a href="{{ url_for('create_service_for_vehicle', vid=vehicle.id) }}" id="pitstop_{{loop.index}}" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> add service
</a>
<a href="{{ url_for('select_consumable_for_new_pitstop', vid=vehicle.id) }}" id="pitstop_{{loop.index}}" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> add pitstop
</a>
<a href="{{ url_for('edit_vehicle', vid=vehicle.id) }}" id="edit_vehicle_{{loop.index}}" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a> </a>
{% if current_user.vehicles | length > 1 %} {% if current_user.vehicles | length > 1 %}
<a href="{{ url_for('delete_vehicle', vid=vehicle.id) }}" class="btn btn-primary btn-warning " role="button"> <a href="{{ url_for('delete_vehicle', vid=vehicle.id) }}" id="delete_vehicle_{{loop.index}}" class="btn btn-primary btn-warning " role="button">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a> </a>
{% else %} {% else %}
@@ -56,10 +63,36 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="panel panel-default">
<div class="panel-heading">Filling Stations</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6 olMap" style="height: 400px" id="mapdiv"></div>
<div class="col-md-6">
<div class="row">
<div class="btn-group col-md-12" role="group">
<button type="button" class="btn btn-default glyphicon glyphicon-home" id="go_home_button" />
<button type="button" class="btn btn-default glyphicon glyphicon-screenshot " id="set_home_button" />
<button type="button" class="btn btn-default glyphicon glyphicon-download" id="get_button" />
</div>
</div>
<div id="station_info" class="row">
</div>
</div>
</div>
</div>
<script>
var lat = {{ map_pos[0] or 0 }};
var long = {{ map_pos[1] or 0 }};
var zoom = {{ map_pos[2] or 0 }};
var init_filling_station = JSON.parse({{ fs|tojson }});
activate_map('mapdiv', ['get_button', 'set_home_button', 'go_home_button'], lat, long, zoom, init_filling_station);
</script>
</div>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Account</div> <div class="panel-heading">Account</div>
<div class="panel-body"> <div class="panel-body">
<a href='{{ url_for('delete_account') }}' class="btn btn-primary " role="button"> <a href="{{ url_for('delete_account') }}" id="delete_account" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete
</a> </a>
</div> </div>

View File

@@ -16,7 +16,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">Consumables</div> <div class="panel-heading">Consumables</div>
<div class="panel-body"> <div class="panel-body">
<a href="{{ url_for('create_consumable') }}" class="btn btn-primary " role="button"> <a href="{{ url_for('create_consumable') }}" id="create_consumable" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create
</a> </a>
</div> </div>
@@ -38,22 +38,16 @@
</tr> </tr>
{% for consumable in consumables %} {% for consumable in consumables %}
<tr> <tr>
<td> <td id="name_{{loop.index}}">{{ consumable.name }}</td>
{{ consumable.name }} <td id="unit_{{loop.index}}">{{ consumable.unit }}</td>
</td> <td id="count_{{loop.index}}">{{ consumable.vehicles | length }} vehicles</td>
<td>
{{ consumable.unit }}
</td>
<td>
{{ consumable.vehicles | length }} vehicles
</td>
<td> <td>
{% if not consumable.in_use %} {% if not consumable.in_use %}
<a href="{{ url_for('delete_consumable', cid=consumable.id) }}" class="btn btn-primary btn-warning " role="button"> <a href="{{ url_for('delete_consumable', cid=consumable.id) }}" id="delete_consumable{{loop.index}}" class="btn btn-primary btn-warning " role="button">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a> </a>
{% endif %} {% endif %}
<a href="{{ url_for('edit_consumable', cid=consumable.id) }}" class="btn btn-primary " role="button"> <a href="{{ url_for('edit_consumable', cid=consumable.id) }}" id="edit_consumable{{loop.index}}" class="btn btn-primary " role="button">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a> </a>
</td> </td>

View File

@@ -9,6 +9,7 @@
<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

@@ -0,0 +1,30 @@
{% extends "layout.html" %}
{% block body %}
<div class="col-md-2" ></div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<h3>New Service for '{{ vehicle.name }}'</h3>
<form class='form-horizontal' method="POST">
{{ form.hidden_tag() }}
{{ render_field_with_errors(form.date) }}
<span id="{{form.date.id}}_help" class="help-block">
{{messages['date']}}
</span>
{{ render_field_with_errors(form.odometer) }}
<span id="{{form.odometer.id}}_help" class="help-block">
{{messages['odometer']}}
</span>
{{ render_field_with_errors(form.costs) }}
<span id="{{form.costs.id}}_help" class="help-block">
{{messages['costs']}}
</span>
{{ render_field_with_errors(form.description) }}
{{ render_field_with_errors(form.submit) }}
</form>
</div>
</div>
</div>
<div class="col-md-2" ></div>
{% endblock %}

View File

@@ -5,7 +5,7 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<h3>Delete vehicle '{{consumable.name}}'?</h3> <h3>Delete consumable '{{consumable.name}}'?</h3>
<form class='form-horizontal' method="POST"> <form class='form-horizontal' method="POST">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{{ render_field_with_errors(form.submit) }} {{ render_field_with_errors(form.submit) }}

View File

@@ -6,7 +6,7 @@
<div class='panel panel-default'> <div class='panel panel-default'>
<div class='panel-body'> <div class='panel-body'>
<h3>Delete pitstop?</h3> <h3>Delete pitstop?</h3>
<table style='width: 100%'> <table style='width: 100%' class="table table-striped table-bordered table-condensed">
<tr> <tr>
<th style='text-align:right'>Date of Pitstop</th> <th style='text-align:right'>Date of Pitstop</th>
<td style='text-align: left'>{{ pitstop.date }}</td> <td style='text-align: left'>{{ pitstop.date }}</td>

View File

@@ -0,0 +1,42 @@
{% extends 'layout.html' %}
{% block body %}
<div class='col-md-2' ></div>
<div class='col-md-8'>
<div class='panel panel-default'>
<div class='panel-body'>
<h3>Delete service?</h3>
<table style='width: 100%' class="table table-striped table-bordered table-condensed">
<tr>
<th style='text-align:right'>Date of Pitstop</th>
<td style='text-align: left'>{{ service.date }}</td>
</tr>
<tr>
<th style='text-align:right'>Odometer</th>
<td style='text-align: left'>{{ service.odometer }} km</td>
</tr>
<tr>
<th style='text-align:right'>Description</th>
<td style='text-align: left' class="markdown">{{ service.description | markdown | safe}}</td>
</tr>
<tr>
<th style='text-align:right'>Costs (overall)</th>
<td style='text-align: left'>
{% if service.costs %}
{{service.costs}}
{% else %}
--
{% endif %}
</td>
</tr>
</table>
<form class='form-horizontal' method='POST'>
{{ form.hidden_tag() }}
{{ render_field_with_errors(form.submit) }}
</form>
</div>
</div>
</div>
<div class='col-md-2' ></div>
{% endblock %}

View File

@@ -5,10 +5,11 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<h3>Edit consumable </h3> <h3>Edit consumable</h3>
<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

@@ -0,0 +1,29 @@
{% extends "layout.html" %}
{% block body %}
<div class="col-md-2" ></div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<h3>Edit Pitstop for '{{ vehicle.name }}'</h3>
<form class='form-horizontal' method="POST">
{{ form.hidden_tag() }}
{{ render_field_with_errors(form.date) }}
<span id="{{form.date.id}}_help" class="help-block">
{{messages['date']}}
</span>
{{ render_field_with_errors(form.odometer) }}
<span id="{{form.odometer.id}}_help" class="help-block">
{{messages['odometer']}}
</span>
{{ render_field_with_errors(form.description) }}
{{ render_field_with_errors(form.costs) }}
<span id="{{form.costs.id}}_help" class="help-block">
{{messages['costs']}}
</span>
{{ render_field_with_errors(form.submit) }}
</form>
</div>
</div>
</div>
{% endblock %}

View File

@@ -5,7 +5,7 @@
<div class="col-md-8"> <div class="col-md-8">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
<h3>Edit vehicle</h3> <h3>Edit vehicle '{{vehicle.name}}'</h3>
<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) }}

View File

@@ -1,15 +1,17 @@
{% macro navigation() -%} {% macro navigation() -%}
{% if current_user.email %} {% if current_user.email %}
<li><a href='{{ url_for('select_vehicle_for_new_pitstop') }}'>Create Pitstop</a></li> <li><a id='plan_pitstop_link' href='{{ url_for('select_vehicle_for_plan_pitstop') }}'>Plan Pitstop</a></li>
<li><a href='{{ url_for('get_statistics') }}'>Statistics</a></li> <li><a id='new_pitstop_link' href='{{ url_for('select_vehicle_for_new_pitstop') }}'>Create Pitstop</a></li>
<li><a href='{{ url_for('get_account_page') }}'>Account</a></li> <li><a id='new_service_link' href='{{ url_for('select_vehicle_for_new_service') }}'>Create Service</a></li>
<li><a id='statistics_limk' href='{{ url_for('get_statistics') }}'>Statistics</a></li>
<li><a id='account_link' href='{{ url_for('get_account_page') }}'>Account</a></li>
{% if current_user.has_role('admin') %} {% if current_user.has_role('admin') %}
<li><a href='{{ url_for('get_admin_page') }}'>Admin</a></li> <li><a id='admin_link' href='{{ url_for('get_admin_page') }}'>Admin</a></li>
{% endif %} {% endif %}
<li><a href='{{ url_for('security.logout') }}'>Logout</a></li> <li><a id='logout_link' href='{{ url_for('security.logout') }}'>Logout</a></li>
{% else %} {% else %}
<li><a href='{{ url_for('security.login') }}'>Login</a></li> <li><a id='login_link' href='{{ url_for('security.login') }}'>Login</a></li>
<li><a href='{{ url_for('security.register') }}'>Register</a></li> <li><a id='register_link' href='{{ url_for('security.register') }}'>Register</a></li>
{% endif %} {% endif %}
{%- endmacro %} {%- endmacro %}
@@ -56,6 +58,8 @@
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="1" aria-describedby="{{ field.id }}_help" /> <input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="1" aria-describedby="{{ field.id }}_help" />
{% elif field.type == 'DecimalField' %} {% elif field.type == 'DecimalField' %}
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="{{ 1 / 10 ** field.places}}" aria-describedby="{{ field.id }}_help" /> <input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="{{ 1 / 10 ** field.places}}" aria-describedby="{{ field.id }}_help" />
{% elif field.type == 'TextAreaField' %}
<textarea class="form-control" id="{{ field.id }}" name="{{ field.id }}">{{ field.default|none_filter }}</textarea>
{% else %} {% else %}
{{ field(**kwargs)|safe }} {{ field(**kwargs)|safe }}
{% endif %} {% endif %}
@@ -103,19 +107,19 @@
<title>refuel journal</title> <title>refuel journal</title>
<meta name="description" content=""> <meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-57.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-57.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-60.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-60.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-72.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-72.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-76.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-76.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-114.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-114.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-120.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-120.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-144.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-144.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-152.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-152.png') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon-180.png') }}"> <link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon-180.png') }}">
<link rel="icon" type="image/png" sizes="192x192" href="{{ url_for('static', filename='android-icon-192x192.png') }}"> <link rel="icon" type="image/png" sizes="192x192" href="{{ url_for('static', filename='img/android-icon-192x192.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='favicon-32x32.png') }}"> <link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='img/favicon-32x32.png') }}">
<link rel="icon" type="image/png" sizes="96x96" href="{{ url_for('static', filename='favicon-96x96.png') }}"> <link rel="icon" type="image/png" sizes="96x96" href="{{ url_for('static', filename='img/favicon-96x96.png') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='favicon-16x16.png') }}"> <link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='img/favicon-16x16.png') }}">
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
@@ -124,13 +128,17 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="{{ url_for('static', filename='js/jquery.tablesorter.min.js') }}"></script>
<!-- Latest compiled and minified JavaScript --> <!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script> <script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script> <script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/patterns.js"></script> <script src="https://www.amcharts.com/lib/3/themes/patterns.js"></script>
<script src="{{ url_for('static', filename='main.js') }}"></script> <script src="https://openlayers.org/api/OpenLayers.js"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
<script src="{{ url_for('static', filename='js/fillingstations.js') }}"></script>
</head> </head>
<body> <body>
<nav class="navbar navbar-inverse navbar-fixed-top"> <nav class="navbar navbar-inverse navbar-fixed-top">
@@ -151,8 +159,23 @@
</div><!--/.nav-collapse --> </div><!--/.nav-collapse -->
</div> </div>
</nav> </nav>
{% with messages = get_flashed_messages(with_categories=true) %}
<div class="container"> {% if messages %}
{% for category, message in messages %}
<div class="row topspace">
<div class="col-md-4" ></div>
<div class="col-md-4">
<div class="alert alert-{{category}} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{{ message }}
</div>
</div>
<div class="col-md-4" ></div>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="container topspace">
<div class="starter-template"> <div class="starter-template">
{% block body %} {% block body %}
{% endblock %} {% endblock %}

View File

@@ -1,9 +1,95 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% macro pitstop(field, vindex, loop) -%}
<div class="panel panel-default">
<div class="panel-body">
<div style="text-align: left; font-size: 20px;">
<span class="glyphicon glyphicon-filter" aria-hidden="true" style="border: 1px solid black; padding: 5px 5px 3px; border-radius: 5px;"></span>
</div>
<table class="table table-striped table-bordered table-condensed">
<tr>
<th>Date</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_date">{{field.date}}</td>
</tr>
<tr>
<th>Odometer</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_odo">{{field.odometer}} km</td>
</tr>
<tr>
<th>{{ field.consumable.name }}</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_anmount">{{field.amount}} {{ field.consumable.unit }}</td>
</tr>
<tr>
<th>Costs</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_cost">
{% if field.costs %}
{{field.costs}} €
{% else %}
-- €
{% endif %}
</td>
</tr>
</table>
{% if loop.first %}
<a id="vehicle_{{vindex}}_edit_pitstop_{{loop.index}}" href="{{ url_for('edit_pit_stop_form', pid=field.id) }}" class="btn btn-primary">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a>
<a id="vehicle_{{vindex}}_delete_pitstop_{{loop.index}}" href="{{ url_for('delete_pit_stop_form', pid=field.id) }}" class="btn btn-primary btn-warning ">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a>
{% endif %}
</div>
</div>
{%- endmacro %}
{% macro service(field, vindex, loop) -%}
<div class="panel panel-default">
<div class="panel-body">
<div style="text-align: left; font-size: 20px;">
<span class="glyphicon glyphicon-wrench" aria-hidden="true" style="border: 1px solid black; padding: 5px 5px 3px; border-radius: 5px;"></span>
</div>
<table class="table table-striped table-bordered table-condensed">
<tr>
<th>Date</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_date">{{field.date}}</td>
</tr>
<tr>
<th>Odometer</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_desc">{{field.odometer}} km</td>
</tr>
<tr>
<th>Description</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_anmount" class="markdown">{{field.description | markdown | safe}}</td>
</tr>
<tr>
<th>Costs</th>
<td id="vehicle_{{vindex}}_pitstop_{{loop.index}}_cost">
{% if field.costs %}
{{field.costs}} €
{% else %}
-- €
{% endif %}
</td>
</tr>
</table>
{% if loop.first %}
<a id="vehicle_{{vindex}}_edit_pitstop_{{loop.index}}" href="{{ url_for('edit_service_form', sid=field.id) }}" class="btn btn-primary">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a>
<a id="vehicle_{{vindex}}_delete_pitstop_{{loop.index}}" href="{{ url_for('delete_service_form', sid=field.id) }}" class="btn btn-primary btn-warning ">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a>
{% endif %}
</div>
</div>
{%- endmacro %}
{% block body %} {% block body %}
<div class="col-md-2" ></div> <div class="col-md-2" ></div>
<div class="col-md-8"> <div class="col-md-8">
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs"> <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
{% for vehicle in current_user.vehicles %} {% for vehicle in user.vehicles %}
<li {% if loop.first %}class="active" {%endif %}> <li {% if loop.first %}class="active" {%endif %}>
<a href="#v{{vehicle.id}}" id="i{{vehicle.id}}" data-toggle="tab"> <a href="#v{{vehicle.id}}" id="i{{vehicle.id}}" data-toggle="tab">
{{ vehicle.name }} {{ vehicle.name }}
@@ -12,47 +98,18 @@
{% endfor %} {% endfor %}
</ul> </ul>
<div id="my-tab-content" class="tab-content"> <div id="my-tab-content" class="tab-content">
{% for vehicle in current_user.vehicles %} {% for vehicle in user.vehicles %}
{% set vehicleloop = loop %}
<div class="tab-pane {% if loop.first %}active{% endif %}" id="v{{vehicle.id}}"> <div class="tab-pane {% if loop.first %}active{% endif %}" id="v{{vehicle.id}}">
<h3>{{vehicle.name}}</h3> <h3>{{vehicle.name}}</h3>
{% if vehicle.pitstops %} {% if vehicle.data %}
{% for pitstop in vehicle.pitstops|reverse %} {% for data in vehicle.data|reverse %}
<div class="panel panel-default"> {% if 'Pitstop' in data.__class__.__name__ %}
<div class="panel-body"> {{ pitstop(data, vehicleloop.index, loop) }}
<table class="table table-striped table-bordered table-condensed"> {% endif %}
<tr> {% if 'Service' in data.__class__.__name__ %}
<th>Date</th> {{ service(data, vehicleloop.index, loop) }}
<td>{{pitstop.date}}</td> {% endif %}
</tr>
<tr>
<th>Odometer</th>
<td>{{pitstop.odometer}} km</td>
</tr>
<tr>
<th>{{ pitstop.consumable.name }}</th>
<td>{{pitstop.amount}} {{ pitstop.consumable.unit }}</td>
</tr>
<tr>
<th>Costs</th>
<td>
{% if pitstop.costs %}
{{pitstop.costs}} €
{% else %}
-- €
{% endif %}
</td>
</tr>
</table>
{% if loop.first %}
<a href="{{ url_for('edit_pit_stop_form', pid=pitstop.id) }}" class="btn btn-primary">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a>
<a href="{{ url_for('delete_pit_stop_form', pid=pitstop.id) }}" class="btn btn-primary btn-warning ">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
</a>
{% endif %}
</div>
</div>
{% endfor %} {% endfor %}
{% else %} {% else %}
<div class="alert alert-warning" role="alert"> <div class="alert alert-warning" role="alert">

View File

@@ -0,0 +1,57 @@
{% extends "layout.html" %}
{% block body %}
<div class="col-md-2" ></div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-body">
<h3>Plan Pitstop for '{{ vehicle.name }}'</h3>
Price comparision for {{ consumable.name }}:
<div class="table-responsive">
<table id="compare" class="table table-striped table-bordered table-condensed tablesorter">
<thead>
<tr>
<th>Filling Station</th>
<th>Price/{{ consumable.unit }}</th>
</tr>
</thead>
<tbody>
{% for offer in offers %}
<tr>
<td>
<div class="row filling_station_info " style="border: 0px">
<div class="col-md-8">
<div>{{ offer[0].name }}</div>
<div>{{ offer[0].street }} {{ offer[0].houseNumber }}</div>
<div>{{ offer[0].postCode }} {{ offer[0].place }}</div>
</div>
<div class="col-md-4" style="height: 60px;">
<img src="/static/logos/{{ offer[0].brand|lower }}.png">
</div>
</div>
</td>
<td>
{% if offer[0].open %}
{{ offer[1] }} €/{{ consumable.unit }}
{% else %}
Closed
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$("#compare").tablesorter({sortList: [[1,0]]});
$("img").error(function(){
$(this).hide();
});
});
</script>
<div class="col-md-2" ></div>
{% endblock %}

View File

@@ -1,7 +1,10 @@
from sqlalchemy import or_
import requests
import logging import logging
from datetime import date from datetime import date, datetime, timedelta
from .entities import Pitstop from .entities import Pitstop, FillingStation
from . import db, app
class ConsumableStats: class ConsumableStats:
@@ -34,7 +37,7 @@ class ConsumableStats:
self.average_amount.append( self.average_amount.append(
StatsEvent( StatsEvent(
current_ps.date, current_ps.date,
round(100 * current_ps.amount/(current_ps.odometer - last_ps.odometer), 2))) round(100 * current_ps.amount / (current_ps.odometer - last_ps.odometer), 2)))
class VehicleStats: class VehicleStats:
@@ -49,16 +52,17 @@ class VehicleStats:
for consumable in vehicle.consumables: for consumable in vehicle.consumables:
self.consumables.append(ConsumableStats(vehicle, consumable)) self.consumables.append(ConsumableStats(vehicle, consumable))
pitstop_count = len(vehicle.pitstops) events = get_event_line_for_vehicle(vehicle)
pitstop_count = len(events)
if pitstop_count > 0: if pitstop_count > 0:
for pitstop in vehicle.pitstops: for pitstop in events:
self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer)) self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer))
if pitstop.costs is not None: if pitstop.costs is not None:
self.overall_costs += pitstop.costs self.overall_costs += pitstop.costs
if pitstop_count > 1: if pitstop_count > 1:
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer self.overall_distance = events[-1].odometer - events[0].odometer
class StatsEvent: class StatsEvent:
@@ -103,9 +107,9 @@ def get_latest_pitstop_for_vehicle(vehicle_id):
:param vehicle_id: the id of the vehicle :param vehicle_id: the id of the vehicle
:return: the latest pitstop or None if no pitstop exists :return: the latest pitstop or None if no pitstop exists
""" """
latest_pitstop = Pitstop.query\ latest_pitstop = Pitstop.query \
.filter(Pitstop.vehicle_id == vehicle_id)\ .filter(Pitstop.vehicle_id == vehicle_id) \
.order_by(Pitstop.id.desc())\ .order_by(Pitstop.id.desc()) \
.first() .first()
return latest_pitstop return latest_pitstop
@@ -117,10 +121,10 @@ def get_latest_pitstop_for_vehicle_and_consumable(vehicle_id, consumable_id):
:param consumable_id: the id of the consumable :param consumable_id: the id of the consumable
:return: the latest pitstop or None if no pitstop exists :return: the latest pitstop or None if no pitstop exists
""" """
latest_pitstop_consumable = Pitstop.query\ latest_pitstop_consumable = Pitstop.query \
.filter(Pitstop.vehicle_id == vehicle_id)\ .filter(Pitstop.vehicle_id == vehicle_id) \
.filter(Pitstop.consumable_id == consumable_id)\ .filter(Pitstop.consumable_id == consumable_id) \
.order_by(Pitstop.id.desc())\ .order_by(Pitstop.id.desc()) \
.first() .first()
return latest_pitstop_consumable return latest_pitstop_consumable
@@ -149,29 +153,62 @@ def compute_lower_limits_for_new_pitstop(latest_pitstop, last_pitstop_consumable
return Pitstop(odometer, amount, date_of_pitstop, costs, consumable_id) return Pitstop(odometer, amount, date_of_pitstop, costs, consumable_id)
# if latest_pitstop is not None: def pitstop_service_key(x):
# if last_pitstop_consumable is not None and last_pitstop_consumable != latest_pitstop: return x.odometer, x.date
# if latest_pitstop.id > last_pitstop_consumable.id:
# return Pitstop(latest_pitstop.odometer,
# last_pitstop_consumable.overall_amount,
# latest_pitstop.date,
# last_pitstop_consumable.costs,
# consumable_id)
# else:
# return Pitstop(last_pitstop_consumable.odometer,
# last_pitstop_consumable.overall_amount,
# last_pitstop_consumable.date,
# last_pitstop_consumable.costs,
# consumable_id)
# else:
# # either only one pitstop exists or both are the same
# litres = 0
# costs = 0
# if latest_pitstop.consumable_id == last_pitstop_consumable.consumable_id:
# litres = latest_pitstop.overall_amount
# costs = latest_pitstop.costs
# return Pitstop(latest_pitstop.odometer, litres, latest_pitstop.date, costs, consumable_id)
# else:
# # No existing pitstop at all: insert fake data
# return Pitstop(0, 0, date(1970, 1, 1), 0, None)
def get_event_line_for_vehicle(vehicle):
data = []
for pitstop in vehicle.pitstops:
data.append(pitstop)
for service in vehicle.services:
data.append(service)
data.sort(key=pitstop_service_key)
return data
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
def update_filling_station_prices(ids):
max_age = (datetime.now() - timedelta(minutes=15)).strftime('%Y-%m-%d %H:%M')
res = db.session. \
query(FillingStation). \
filter(FillingStation.id.in_(ids)). \
filter(or_(FillingStation.last_update == None, FillingStation.last_update < max_age)). \
all()
if len(res) > 0:
id_map = {x.id: x for x in res}
query_ids = [x.id for x in res]
api_key = app.config['TANKERKOENIG_API_KEY']
url = 'https://creativecommons.tankerkoenig.de/json/prices.php'
# documentation tells us to query max 10 filling stations at a time...
for c in chunks(query_ids, 10):
params = {
'apikey': api_key, 'ids': ','.join(c)
}
response = requests.get(url, params=params)
response_json = response.json()
if response_json['ok']:
print(response_json)
prices = response_json['prices']
for price in prices:
id = price
station_status = prices[id]
id_map[id].open = station_status['status'] == 'open'
if id_map[id].open:
id_map[id].diesel = station_status['diesel']
id_map[id].e10 = station_status['e10']
id_map[id].e5 = station_status['e5']
id_map[id].last_update = datetime.now()
else:
logging.error(
'could not update filling stations because of {r} on URL {u}.'.format(r=str(response_json),
u=response.url))
db.session.commit()

View File

@@ -1,4 +1,5 @@
import os import os
basedir = os.path.abspath(os.path.dirname(__file__)) basedir = os.path.abspath(os.path.dirname(__file__))
@@ -17,6 +18,9 @@ class Config:
MAIL_USE_SSL = False MAIL_USE_SSL = False
MAIL_USERNAME = os.environ.get('MAIL_USERNAME') MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD') MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
ADMIN_MAIL = 'joachim@lusiardi.de'
TANKERKOENIG_API_KEY = os.environ.get('TANKERKOENIG_API_KEY')
DEBUG = False
@staticmethod @staticmethod
def init_app(app): def init_app(app):
@@ -26,16 +30,19 @@ class Config:
class DevelopmentConfig(Config): class DevelopmentConfig(Config):
SECURITY_SEND_REGISTER_EMAIL = False SECURITY_SEND_REGISTER_EMAIL = False
DEBUG = True DEBUG = True
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:%s@database/pitstops' % (os.environ['DATABASE_ENV_MYSQL_ROOT_PASSWORD']) SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
class TestingConfig(Config): class TestingConfig(Config):
TESTING = True SECURITY_SEND_REGISTER_EMAIL = False
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data_testing.sqlite') DEBUG = True
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:{p}@{h}/pitstops'.format(p=os.environ.get('MYSQL_PASSWORD'),
h=os.environ.get('MYSQL_HOST'))
class ProductionConfig(Config): class ProductionConfig(Config):
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data.sqlite') SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:{h}@database/pitstops'.format(
h=os.environ.get('DATABASE_ENV_MYSQL_ROOT_PASSWORD'))
config = { config = {
@@ -43,4 +50,4 @@ config = {
'testing': TestingConfig, 'testing': TestingConfig,
'production': ProductionConfig, 'production': ProductionConfig,
'default': DevelopmentConfig 'default': DevelopmentConfig
} }

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS `service` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` date DEFAULT NULL,
`odometer` int(11) DEFAULT NULL,
`vehicle_id` int(11) DEFAULT NULL,
`costs` decimal(10,2) DEFAULT NULL,
`description` varchar(4096) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `vehicle_id` (`vehicle_id`),
CONSTRAINT `service_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;

View File

@@ -0,0 +1,39 @@
CREATE TABLE `filling_station` (
`int_id` int(11) NOT NULL AUTO_INCREMENT,
`id` varchar(40) NOT NULL,
`name` text NOT NULL,
`street` text NOT NULL,
`place` text NOT NULL,
`houseNumber` text,
`postCode` int(11) NOT NULL,
`brand` text NOT NULL,
`lat` decimal(8,5) NOT NULL,
`lng` decimal(8,5) NOT NULL,
`last_update` datetime DEFAULT NULL,
`diesel` decimal(10,3) DEFAULT NULL,
`e5` decimal(10,3) DEFAULT NULL,
`e10` decimal(10,3) DEFAULT NULL,
`open` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`int_id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1;
CREATE TABLE `users_fillingstations` (
`user_id` int(11) DEFAULT NULL,
`fillingstation_id` int(11) DEFAULT NULL,
KEY `user_id` (`user_id`),
KEY `fillingstation_id` (`fillingstation_id`),
CONSTRAINT `users_fillingstations_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`),
CONSTRAINT `users_fillingstations_ibfk_2` FOREIGN KEY (`fillingstation_id`) REFERENCES `filling_station` (`int_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `consumable` ADD COLUMN `ext_id` varchar(255) DEFAULT NULL;
update consumable set ext_id = 'e5' where id = 1;
update consumable set ext_id = 'e10' where id = 34;
update consumable set ext_id = 'diesel' where id = 32;
ALTER TABLE `user` ADD COLUMN `home_lat` decimal(8,5) DEFAULT NULL;
ALTER TABLE `user` ADD COLUMN `home_long` decimal(8,5) DEFAULT NULL;
ALTER TABLE `user` ADD COLUMN `home_zoom` int(11) DEFAULT NULL;

View File

@@ -2,19 +2,9 @@ version: '2'
services: services:
rollerverbrauch: rollerverbrauch:
build: . build: .
depends_on:
- database
volumes:
- ./compose_config/:/config
environment: environment:
- config=/config/config.py - config=/config/config.py
- DATABASE_ENV_MYSQL_ROOT_PASSWORD=foobar123 - DATABASE_ENV_MYSQL_ROOT_PASSWORD=foobar123
- FLASK_CONFIG=testing
ports: ports:
- 5000 - 127.0.0.1:5000:5000
database:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=foobar123
- MYSQL_DATABASE=pitstops
ports:
- 3306

View File

@@ -1,12 +1,17 @@
import os import os
from app import app from app import app
import logging import logging
from config import config
def setup_logging(): def setup_logging():
logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', level=logging.INFO) 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' c = config[os.getenv('FLASK_CONFIG') or 'default']
DEBUG = c.DEBUG
DEBUG = os.environ.get('DEBUG', DEBUG)
setup_logging() setup_logging()
app.run(debug=DEBUG, host='0.0.0.0') app.run(debug=DEBUG, host='0.0.0.0')

View File

@@ -3,3 +3,6 @@ Flask-SQLAlchemy
Flask-Security Flask-Security
Flask-WTF Flask-WTF
PyMySQL PyMySQL
markdown
Flask-Limiter
requests

12
tests/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM debian8_python3
COPY app/requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt; \
mkdir /data
ADD app /app
VOLUME ["/data"]
VOLUME ["/app/config]
EXPOSE 5000
ENTRYPOINT python3 /app/main.py

137
tests/app/main.py Normal file
View File

@@ -0,0 +1,137 @@
import unittest
import inspect
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
def wait_net_service(server, port, timeout=None):
""" Wait for network service to appear
@param timeout: in seconds, if None or 0 wait forever
@return: True of False, if timeout is None may return only True or
throw unhandled network exception
"""
import socket
import errno
s = socket.socket()
if timeout:
from time import time as now
# time module is needed to calc timeout shared between two exceptions
end = now() + timeout
while True:
try:
if timeout:
next_timeout = end - now()
if next_timeout < 0:
return False
else:
s.settimeout(next_timeout)
s.connect((server, port))
except socket.timeout as err:
# this exception occurs only if timeout is set
if timeout:
return False
except socket.error as err:
# catch timeout exception from underlying network library
# this one is different from socket.timeout
if type(err.args) != tuple or err[0] != errno.ETIMEDOUT:
raise
else:
s.close()
return True
class BaseTestCase(unittest.TestCase):
def setUp(self):
self.screen_shot_counter = 0
self.driver = webdriver.Remote(
command_executor='http://selenium:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
self.driver.get("http://rollerverbrauch:5000")
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "email")))
def create_screenshot(self):
self.driver.get_screenshot_as_file(
'/results/%s_%s_%s.png' % (self.__class__.__name__, inspect.stack()[1][3], str(self.screen_shot_counter)))
self.screen_shot_counter += 1
def tearDown(self):
self.driver.close()
class RegisterCheck(BaseTestCase):
def setUp(self):
self.screen_shot_counter = 0
self.driver = webdriver.Remote(
command_executor='http://selenium:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)
self.driver.get("http://rollerverbrauch:5000")
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "email")))
def test_page_loads(self):
self.driver.get("http://rollerverbrauch:5000")
self.create_screenshot()
self.assertIn("refuel", self.driver.title, "Title must contain reload")
def test_can_register(self):
self.driver.get("http://rollerverbrauch:5000")
self.driver.find_element_by_partial_link_text('Register').click()
self.create_screenshot()
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "submit")))
self.create_screenshot()
self.driver.find_element_by_id('email').send_keys('test@test.com')
self.driver.find_element_by_id('password').send_keys('test123')
self.driver.find_element_by_id('password_confirm').send_keys('test123')
self.create_screenshot()
self.driver.find_element_by_id('submit').click()
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "i1")))
self.create_screenshot()
def test_register_must_repeat_pwd(self):
self.driver.get("http://rollerverbrauch:5000")
self.driver.find_element_by_partial_link_text('Register').click()
self.create_screenshot()
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "submit")))
self.create_screenshot()
self.driver.find_element_by_id('email').send_keys('test1@test.com')
self.driver.find_element_by_id('password').send_keys('test123')
self.create_screenshot()
self.driver.find_element_by_id('submit').click()
self.create_screenshot()
error = self.driver.find_elements_by_class_name('error')
self.assertIsNotNone(error[0], 'we expect an error')
self.assertIn('Passwords do not match', error[0].text, 'wrong error message')
def test_register_must_be_equal_pwd(self):
self.driver.get("http://rollerverbrauch:5000")
self.driver.find_element_by_partial_link_text('Register').click()
self.create_screenshot()
WebDriverWait(self.driver, 10).until(expected_conditions.presence_of_element_located((By.ID, "submit")))
self.create_screenshot()
self.driver.find_element_by_id('email').send_keys('test1@test.com')
self.driver.find_element_by_id('password').send_keys('test123')
self.driver.find_element_by_id('password_confirm').send_keys('test1234')
self.create_screenshot()
self.driver.find_element_by_id('submit').click()
self.create_screenshot()
error = self.driver.find_elements_by_class_name('error')
self.assertIsNotNone(error[0], 'we expect an error')
self.assertIn('Passwords do not match', error[0].text, 'wrong error message')
class LoginCheck(BaseTestCase):
def can_login(self):
pass
if __name__ == "__main__":
wait_net_service('selenium', 4444)
unittest.main()

View File

@@ -0,0 +1 @@
selenium

View File

@@ -0,0 +1,16 @@
import os
#SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:%s@database/pitstops' % (os.environ['DATABASE_ENV_MYSQL_ROOT_PASSWORD'])
SQLALCHEMY_DATABASE_URI = 'sqlite:////data/rollerverbrauch.db'
MAIL_SERVER = ''
MAIL_PORT= 25
MAIL_USE_TLS = True
MAIL_USE_SSL = False
MAIL_USERNAME = ''
MAIL_PASSWORD = ''
SECURITY_EMAIL_SENDER = ''
SECURITY_PASSWORD_SALT = 'SecretSalt'
SECRET_KEY = 'SecretKey'
SECURITY_SEND_REGISTER_EMAIL = False

22
tests/docker-compose.yml Normal file
View File

@@ -0,0 +1,22 @@
version: '2'
services:
tests:
build: .
depends_on:
- selenium
volumes:
- ./results:/results
selenium:
image: selenium/standalone-firefox
depends_on:
- rollerverbrauch
rollerverbrauch:
build: ..
volumes:
- ./compose_config/:/config
environment:
- config=/config/config.py
- DATABASE_ENV_MYSQL_ROOT_PASSWORD=foobar123
ports:
- 5000

7
tests/run_test.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
rm -f results/*
docker-compose build
docker-compose up --abort-on-container-exit
docker-compose down
docker-compose rm --all