Feat: dash setup and start home page
This commit is contained in:
parent
94f8080acd
commit
598086ddb0
0
recopytex/dashboard/__init__.py
Normal file
0
recopytex/dashboard/__init__.py
Normal file
20
recopytex/dashboard/app.py
Normal file
20
recopytex/dashboard/app.py
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import dash
|
||||
import flask
|
||||
|
||||
from .layout.layout import layout
|
||||
|
||||
server = flask.Flask(__name__)
|
||||
app = dash.Dash(
|
||||
__name__,
|
||||
server=server,
|
||||
suppress_callback_exceptions=True,
|
||||
meta_tags=[{"name": "viewport", "content": "width=device-width, initial-scale=1"}],
|
||||
)
|
||||
|
||||
|
||||
app.layout = layout
|
||||
server = app.server
|
||||
|
8
recopytex/dashboard/index.py
Normal file
8
recopytex/dashboard/index.py
Normal file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from .app import app, server
|
||||
from .routes import render_page_content
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run_server(debug=True)
|
9
recopytex/dashboard/layout/layout.py
Normal file
9
recopytex/dashboard/layout/layout.py
Normal file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import dash_html_components as html
|
||||
import dash_core_components as dcc
|
||||
|
||||
content = html.Div(id="page-content")
|
||||
|
||||
layout = html.Div([dcc.Location(id="url"), content])
|
0
recopytex/dashboard/pages/create_exam/__init__.py
Normal file
0
recopytex/dashboard/pages/create_exam/__init__.py
Normal file
0
recopytex/dashboard/pages/create_exam/app.py
Normal file
0
recopytex/dashboard/pages/create_exam/app.py
Normal file
0
recopytex/dashboard/pages/create_exam/callbacks.py
Normal file
0
recopytex/dashboard/pages/create_exam/callbacks.py
Normal file
0
recopytex/dashboard/pages/create_exam/models.py
Normal file
0
recopytex/dashboard/pages/create_exam/models.py
Normal file
0
recopytex/dashboard/pages/exam_scores/__init__.py
Normal file
0
recopytex/dashboard/pages/exam_scores/__init__.py
Normal file
0
recopytex/dashboard/pages/exam_scores/app.py
Normal file
0
recopytex/dashboard/pages/exam_scores/app.py
Normal file
0
recopytex/dashboard/pages/exam_scores/callbacks.py
Normal file
0
recopytex/dashboard/pages/exam_scores/callbacks.py
Normal file
0
recopytex/dashboard/pages/exam_scores/models.py
Normal file
0
recopytex/dashboard/pages/exam_scores/models.py
Normal file
0
recopytex/dashboard/pages/home/__init__.py
Normal file
0
recopytex/dashboard/pages/home/__init__.py
Normal file
50
recopytex/dashboard/pages/home/app.py
Normal file
50
recopytex/dashboard/pages/home/app.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import dash_html_components as html
|
||||
from ....database.filesystem.loader import CSVLoader
|
||||
from .models import get_tribes, get_exams, get_students
|
||||
|
||||
loader = CSVLoader("./test_config.yml")
|
||||
|
||||
|
||||
def listing(elements, formating=lambda x: x):
|
||||
|
||||
return html.Ul(
|
||||
children=[html.Li(children=formating(element)) for element in elements]
|
||||
)
|
||||
|
||||
|
||||
def format_tribe(tribe):
|
||||
children = [html.H3(tribe["name"])]
|
||||
exams = loader.get_exams([tribe["name"]])
|
||||
if exams.empty:
|
||||
children.append(html.P("Pas d'évaluation"))
|
||||
else:
|
||||
exams_html = listing([exam for id, exam in exams.iterrows()], format_exam)
|
||||
children.append(exams_html)
|
||||
return children
|
||||
|
||||
|
||||
def format_exam(exam):
|
||||
children = [html.P(exam["name"])]
|
||||
return children
|
||||
|
||||
|
||||
layout = html.Div(
|
||||
children=[
|
||||
html.H1("Recopytex"),
|
||||
html.H2("Tribes"),
|
||||
html.Div(
|
||||
children=[listing(loader.get_tribes().values(), format_tribe)],
|
||||
id="tribes",
|
||||
),
|
||||
html.H2("Config"),
|
||||
html.Div(
|
||||
children=[
|
||||
html.P(str(loader.get_config())),
|
||||
],
|
||||
id="config",
|
||||
),
|
||||
]
|
||||
)
|
6
recopytex/dashboard/pages/home/callbacks.py
Normal file
6
recopytex/dashboard/pages/home/callbacks.py
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from dash.dependencies import Input, Output
|
||||
from ...app import app
|
||||
|
14
recopytex/dashboard/pages/home/models.py
Normal file
14
recopytex/dashboard/pages/home/models.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
def get_tribes(loader):
|
||||
return loader.get_tribes()
|
||||
|
||||
|
||||
def get_exams(loader, tribe):
|
||||
return loader.get_exams([tribe])
|
||||
|
||||
|
||||
def get_students(loader, tribe):
|
||||
return loader.get_students([tribe])
|
25
recopytex/dashboard/routes.py
Normal file
25
recopytex/dashboard/routes.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from dash.dependencies import Input, Output
|
||||
|
||||
from .app import app
|
||||
from .pages.home import app as home
|
||||
|
||||
|
||||
@app.callback(Output("page-content", "children"), [Input("url", "pathname")])
|
||||
def render_page_content(pathname):
|
||||
if pathname == "/":
|
||||
return home.layout
|
||||
# elif pathname == gdp_page_location:
|
||||
# return gdp.layout
|
||||
# elif pathname == iris_page_location:
|
||||
# return iris.layout
|
||||
# # If the user tries to reach a different page, return a 404 message
|
||||
# return dbc.Jumbotron(
|
||||
# [
|
||||
# html.H1("404: Not found", className="text-danger"),
|
||||
# html.Hr(),
|
||||
# html.P(f"The pathname {pathname} was not recognised..."),
|
||||
# ]
|
||||
# )
|
16
recopytex/scripts/recopytex.py
Normal file
16
recopytex/scripts/recopytex.py
Normal file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import click
|
||||
from ..dashboard.app import app as dash
|
||||
|
||||
|
||||
@click.group()
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option("--debug", default=0, help="Debug mode for dash")
|
||||
def dashboard(debug):
|
||||
dash.run_server(debug=bool(debug))
|
Loading…
Reference in New Issue
Block a user