How to use the fava.core.misc.align function in fava

To help you get started, we’ve selected a few fava examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beancount / fava / tests / test_json_api.py View on Github external
path = app.config["BEANCOUNT_FILES"][0]
    payload = open(path, encoding="utf-8").read()
    with app.test_request_context():
        app.preprocess_request()
        url = flask.url_for("json_api.format_source")
        old_currency_column = flask.g.ledger.fava_options["currency-column"]
        flask.g.ledger.fava_options["currency-column"] = 90

        result = test_client.put(
            url,
            data=flask.json.dumps({"source": payload}),
            content_type="application/json",
        )
        data = flask.json.loads(result.get_data(True))
        assert data == {
            "data": align(payload, {"currency-column": 90}),
            "success": True,
        }

        flask.g.ledger.fava_options["currency-column"] = old_currency_column
github beancount / fava / tests / test_json_api.py View on Github external
def test_api_format_source(app, test_client):
    with app.test_request_context():
        app.preprocess_request()
        url = flask.url_for("json_api.format_source")

    path = app.config["BEANCOUNT_FILES"][0]
    payload = open(path, encoding="utf-8").read()

    result = test_client.put(
        url,
        data=flask.json.dumps({"source": payload}),
        content_type="application/json",
    )
    data = flask.json.loads(result.get_data(True))
    assert data == {"data": align(payload, {}), "success": True}
github beancount / fava / fava / core / file.py View on Github external
def _format_entry(entry, fava_options):
    """Wrapper that strips unnecessary whitespace from format_entry."""
    meta = {
        key: entry.meta[key] for key in entry.meta if not key.startswith("_")
    }
    entry = entry._replace(meta=meta)
    string = align(format_entry(entry), fava_options)
    string = string.replace("", "")
    return "\n".join((line.rstrip() for line in string.split("\n")))
github beancount / fava / fava / json_api.py View on Github external
def format_source(request_data):
    """Format beancount file."""
    return align(request_data["source"], g.ledger.fava_options)