mirror of
https://github.com/Doctorado-ML/beflask.git
synced 2025-08-15 15:15:52 +00:00
Styles in flash
This commit is contained in:
BIN
app/app.db
BIN
app/app.db
Binary file not shown.
@@ -5,7 +5,7 @@ from flask_login import LoginManager
|
||||
from .config import Config
|
||||
from .models import User, db
|
||||
|
||||
from .results.main import results
|
||||
from .results.main_select import results
|
||||
from .main import main
|
||||
|
||||
bootstrap = Bootstrap5()
|
||||
|
25
app/main.py
25
app/main.py
@@ -9,10 +9,12 @@ from flask import (
|
||||
from flask_login import login_user, current_user, logout_user, login_required
|
||||
from werkzeug.urls import url_parse
|
||||
from .forms import LoginForm
|
||||
from .models import User, Benchmark
|
||||
from .models import User, Benchmark, db
|
||||
|
||||
main = Blueprint("main", __name__)
|
||||
|
||||
INDEX = "main.index"
|
||||
|
||||
|
||||
@main.route("/")
|
||||
@main.route("/index")
|
||||
@@ -27,6 +29,21 @@ def index():
|
||||
return render_template("index.html", benchmarks=benchmarks)
|
||||
|
||||
|
||||
@main.route("/set_benchmark/<benchmark_id>")
|
||||
@login_required
|
||||
def set_benchmark(benchmark_id):
|
||||
if current_user.admin:
|
||||
benchmark = Benchmark.query.filter_by(id=benchmark_id).first()
|
||||
if benchmark is None:
|
||||
flash("Benchmark not found.")
|
||||
return redirect(url_for(INDEX))
|
||||
current_user.benchmark = benchmark
|
||||
db.session.commit()
|
||||
else:
|
||||
flash("You are not an admin.", "danger")
|
||||
return redirect(url_for(INDEX))
|
||||
|
||||
|
||||
@main.route("/config")
|
||||
@login_required
|
||||
def config():
|
||||
@@ -36,7 +53,7 @@ def config():
|
||||
@main.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for("main.index"))
|
||||
return redirect(url_for(INDEX))
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(username=form.username.data).first()
|
||||
@@ -47,7 +64,7 @@ def login():
|
||||
flash("Logged in successfully.")
|
||||
next_page = request.args.get("next")
|
||||
if not next_page or url_parse(next_page).netloc != "":
|
||||
next_page = url_for("main.index")
|
||||
next_page = url_for(INDEX)
|
||||
return redirect(next_page)
|
||||
return render_template("login.html", title="Sign In", form=form)
|
||||
|
||||
@@ -55,4 +72,4 @@ def login():
|
||||
@main.route("/logout")
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for("main.index"))
|
||||
return redirect(url_for(INDEX))
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
from benchmark.Utils import Files, Folders
|
||||
from benchmark.ResultsBase import StubReport
|
||||
from flask_login import current_user
|
||||
from flask import Blueprint, current_app, send_file
|
||||
from flask import render_template, current_app, request, redirect, url_for
|
||||
from flask_login import login_required
|
||||
@@ -19,6 +20,7 @@ results = Blueprint("results", __name__, template_folder="templates")
|
||||
def select(compare="False"):
|
||||
# Get a list of files in a directory
|
||||
files = {}
|
||||
os.chdir(current_user.benchmark.folder)
|
||||
names = Files.get_all_results(hidden=False)
|
||||
for name in names:
|
||||
report = StubReport(os.path.join(Folders.results, name))
|
BIN
app/static/img/robert-lukeman-_RBcxo9AU-U-unsplash.jpg
Normal file
BIN
app/static/img/robert-lukeman-_RBcxo9AU-U-unsplash.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 MiB |
@@ -1,5 +1,5 @@
|
||||
{% from 'bootstrap5/nav.html' import render_nav_item %}
|
||||
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-4 justify-content-end">
|
||||
<nav class="navbar navbar-expand-sm navbar-dark bg-dark mb-4 justify-content-end">
|
||||
<div class="container">
|
||||
<button class="navbar-toggler"
|
||||
type="button"
|
||||
|
@@ -7,7 +7,6 @@
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
{% block styles %}
|
||||
{{ bootstrap.load_css() }}
|
||||
<link rel="stylesheet" href="/css/elina.css">
|
||||
<link rel="stylesheet"
|
||||
href="{{ url_for('static', filename='css/main.css') }}">
|
||||
{% endblock %}
|
||||
@@ -16,9 +15,14 @@
|
||||
</head>
|
||||
<body>
|
||||
{% include "_nav.html" %}
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for message in messages %}<div class="alert alert-info" role="alert">{{ message }}</div>{% endfor %}
|
||||
{% for category, message in messages %}
|
||||
{% if category == 'message' %}
|
||||
{% set category = "info" %}
|
||||
{% endif %}
|
||||
<div class="alert alert-{{ category }}" role="alert">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
<div class="container">
|
||||
|
@@ -5,9 +5,15 @@
|
||||
<ul>
|
||||
{% for benchmark in benchmarks %}
|
||||
<li>
|
||||
<a href="">{{ benchmark.name }} {{ benchmark.folder }}</a>
|
||||
<a href="{{ url_for('main.set_benchmark', benchmark_id=benchmark.id) }}">{{ benchmark.name }}
|
||||
{% if benchmark == current_user.benchmark %}*{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<img src="{{ url_for('static', filename='img/robert-lukeman-_RBcxo9AU-U-unsplash.jpg') }}"
|
||||
class="img-fluid"
|
||||
alt="image robert lukeman">
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
22
dbseed.py
22
dbseed.py
@@ -8,10 +8,28 @@ with app.app_context():
|
||||
db.create_all()
|
||||
b = Benchmark(
|
||||
name="discretizbench",
|
||||
folder="proyects/discretizbench",
|
||||
folder="/Users/rmontanana/Code/discretizbench",
|
||||
description="Experiments with local discretization and Bayesian classifiers",
|
||||
)
|
||||
u = User(username="rmontanana", email="rmontanana@gmail.com", admin=True)
|
||||
db.session.add(b)
|
||||
b = Benchmark(
|
||||
name="odtebench",
|
||||
folder="/Users/rmontanana/Code/odtebench",
|
||||
description="Experiments with STree and Ensemble classifiers",
|
||||
)
|
||||
db.session.add(b)
|
||||
b = Benchmark(
|
||||
name="covbench",
|
||||
folder="/Users/rmontanana/Code/covbench",
|
||||
description="Experiments with COVID-19 dataset",
|
||||
)
|
||||
db.session.add(b)
|
||||
u = User(
|
||||
username="rmontanana",
|
||||
email="rmontanana@gmail.com",
|
||||
admin=True,
|
||||
benchmark_id=1,
|
||||
)
|
||||
u.set_password("patata")
|
||||
u1 = User(
|
||||
username="guest",
|
||||
|
Reference in New Issue
Block a user