Ejemplo n.º 1
0
@blueprint.route("/delete_old", methods=["GET"])
@login_required
def delete_old():
    MIN_KEEP = 25
    try:
        pid = int(request.args.get("project", -1))
    except ValueError:
        pid = -1
    logs = LogEntry.search(project_id=pid, level=0).order_by("timestamp desc")

    for i in range(logs.count() - MIN_KEEP, 0, -1):  # i = COUNT - MIN_KEEP -> 0
        logs[-1].delete(commit=(i == 1))  # Commit on last one (i==1)
    return redirect(url_for("baseapp.home"))


################################################################################
####           Add to App Context Manager                                   ####
################################################################################
def extra_init(app):
    """Extra blueprint initialization that requires application context."""
    if "header_links" not in app.jinja_env.globals:
        app.jinja_env.globals["header_links"] = []
    # Add links to 'header_links' var in jinja globals. This allows header_links
    # to be read by all templates in the app instead of just this blueprint.
    # a = app.jinja_env.globals['header_links']
    # a.extend([("Home", 'baseapp.home')])


# Tack it on to blueprint for easy access in app's __init__.py
blueprint.extra_init = extra_init