summaryrefslogtreecommitdiffstats
path: root/bitvend/__init__.py
blob: 8e4fb77700c38cef5c42c7e3bff239aaffbd6f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import flask

from bitvend.processor import PaymentProcessor
from bitvend.mdb import BitvendCashlessMDBDevice

dev = BitvendCashlessMDBDevice()
proc = PaymentProcessor(dev)

from bitvend.utils import to_local_currency, from_local_currency, format_btc, \
    sat_to_btc
from bitvend.models import db, Transaction
from bitvend.auth import login_manager

import bitvend.views


def create_app():
    app = flask.Flask(__name__)
    app.config.from_object('bitvend.default_settings')

    db.init_app(app)
    login_manager.init_app(app)
    dev.init_app(app)
    proc.init_app(app)

    app.register_blueprint(bitvend.views.bp)

    @app.context_processor
    def ctx_utils():
        return {
            'from_local_currency': from_local_currency,
            'to_local_currency': to_local_currency,
            'format_btc': format_btc,
            'sat_to_btc': sat_to_btc,
            'qrcode': lambda data: flask.url_for('bitvend.qrcode_gen', data=data),
            'current_transaction': Transaction.query.filter(Transaction.finished == False).first(),
            'mdb_online': dev.online,
            'proc_online': proc.online,
        }

    return app