mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-04 22:40:30 +00:00
Compare commits
4 commits
65213ec0e3
...
c1593abd86
Author | SHA1 | Date | |
---|---|---|---|
c1593abd86 | |||
341c00cfb0 | |||
ce7653186a | |||
6a40098922 |
4 changed files with 71 additions and 101 deletions
|
@ -1,5 +1,6 @@
|
|||
from flask_migrate import Migrate
|
||||
from flask_security.datastore import SQLAlchemyUserDatastore
|
||||
from flask_security.core import Security
|
||||
|
||||
from .config import get_settings, get_data_dir
|
||||
from .models import db, User, Role
|
||||
|
@ -11,6 +12,8 @@ settings = get_settings(data_dir)
|
|||
|
||||
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
|
||||
|
||||
security = Security(datastore=user_datastore)
|
||||
|
||||
|
||||
def create_app(create_for_server: bool = True):
|
||||
from flask import Flask
|
||||
|
@ -23,16 +26,13 @@ def create_app(create_for_server: bool = True):
|
|||
set_config(app, data_dir)
|
||||
|
||||
# Setup Flask-SQLAlchemy
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
# Setup Flask-Migrate
|
||||
migrate.init_app(app, db)
|
||||
|
||||
# Setup Flask-Security-Too
|
||||
from flask_security.core import Security
|
||||
|
||||
Security(app, user_datastore)
|
||||
security.init_app(app)
|
||||
|
||||
if create_for_server:
|
||||
# Setup views
|
||||
|
|
|
@ -2,7 +2,7 @@ from flask import Blueprint, redirect, url_for
|
|||
from flask_login import current_user
|
||||
from flask_security.decorators import auth_required
|
||||
|
||||
from . import settings
|
||||
from . import settings, security
|
||||
from .model_dependent_funs import active_semester_str
|
||||
|
||||
bp = Blueprint("main", __name__, root_path="/", template_folder="templates")
|
||||
|
@ -18,6 +18,11 @@ def util_processor():
|
|||
return dict(active_semester_str=active_semester_str, current_user=current_user, footer=footer)
|
||||
|
||||
|
||||
@security.login_context_processor
|
||||
def login_context_processor():
|
||||
return dict(message=settings.get("login_view_message"))
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def index():
|
||||
if current_user.has_role("admin"):
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% block content %}
|
||||
{% for error in form.file.errors %}
|
||||
<div class="alert alert-danger">
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<strong>Error!</strong> {{ error }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -22,42 +22,24 @@
|
|||
</p>
|
||||
<p>
|
||||
You can take a look at the file
|
||||
<a
|
||||
href="{{ url_for('static', filename='example_database_import.txt') }}"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<a href="{{ url_for('static', filename='example_database_import.txt') }}"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">
|
||||
example_database_import.txt
|
||||
</a>
|
||||
for an example.
|
||||
</p>
|
||||
|
||||
<h4>Required manipulation using the web interface</h4>
|
||||
<p>
|
||||
The following tables can not be imported from a file and have to be manipulated using the web interface.
|
||||
</p>
|
||||
<p>The following tables can not be imported from a file and have to be manipulated using the web interface.</p>
|
||||
<ul>
|
||||
<li>
|
||||
Semester
|
||||
</li>
|
||||
<li>
|
||||
Program
|
||||
</li>
|
||||
<li>
|
||||
Part
|
||||
</li>
|
||||
<li>
|
||||
User
|
||||
</li>
|
||||
<li>
|
||||
Assistant
|
||||
</li>
|
||||
<li>
|
||||
Experiment
|
||||
</li>
|
||||
<li>
|
||||
Semester Experiment
|
||||
</li>
|
||||
<li>Semester</li>
|
||||
<li>Program</li>
|
||||
<li>Part</li>
|
||||
<li>User</li>
|
||||
<li>Assistant</li>
|
||||
<li>Experiment</li>
|
||||
<li>Semester Experiment</li>
|
||||
</ul>
|
||||
|
||||
<h4>Optional values</h4>
|
||||
|
@ -71,9 +53,7 @@
|
|||
None of the mentioned ids in the import file is meant as a database id. The ids here only refer to the imported instances. The id in the database is assigned automatically.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Here is the format of a table in the "Tables" section:
|
||||
</p>
|
||||
<p>Here is the format of a table in the "Tables" section:</p>
|
||||
|
||||
<h5>Table</h5>
|
||||
<ul>
|
||||
|
@ -81,41 +61,29 @@
|
|||
id → 0 / 1 / 2 / ... (starts with 0 and has step
|
||||
1)
|
||||
</li>
|
||||
<li>
|
||||
attribute → example1 / example2 / ... (explanation)
|
||||
</li>
|
||||
<li>
|
||||
...
|
||||
</li>
|
||||
<li>attribute → example1 / example2 / ... (explanation)</li>
|
||||
<li>...</li>
|
||||
</ul>
|
||||
<p>
|
||||
The type of attributes can be seen in the drawio file
|
||||
<a
|
||||
href="{{ url_for('static', filename='DB.drawio') }}"
|
||||
>
|
||||
DB.drawio
|
||||
</a> which can be opened using
|
||||
<a
|
||||
href="https://www.diagrams.net/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
diagrams.net
|
||||
</a>. Some attributes have constraints marked also in the drawio file.
|
||||
<a href="{{ url_for('static', filename='DB.drawio') }}">DB.drawio</a> which can be opened using
|
||||
<a href="https://www.diagrams.net/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">diagrams.net</a>. Some attributes have constraints marked also in the drawio file.
|
||||
</p>
|
||||
|
||||
<h4>Tables</h4>
|
||||
<h5>Semester (only one!)</h5>
|
||||
<ul>
|
||||
<li>
|
||||
label → WS / SS
|
||||
</li>
|
||||
<li>label → WS / SS</li>
|
||||
<li>
|
||||
year → 22 / 23 / ...
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>Part</h5>
|
||||
<h5>
|
||||
Part
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
id
|
||||
|
@ -128,7 +96,9 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>Student</h5>
|
||||
<h5>
|
||||
Student
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>student_number</code>
|
||||
|
@ -171,7 +141,9 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
<h5>Group</h5>
|
||||
<h5>
|
||||
Group
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>id</code>
|
||||
|
@ -184,7 +156,9 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>PartStudent</h5>
|
||||
<h5>
|
||||
PartStudent
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>student_number</code>
|
||||
|
@ -197,7 +171,9 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>Experiment</h5>
|
||||
<h5>
|
||||
Experiment
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>id</code>
|
||||
|
@ -210,7 +186,9 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>GroupExperiment</h5>
|
||||
<h5>
|
||||
GroupExperiment
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>id</code>
|
||||
|
@ -223,7 +201,9 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h5>Appointment</h5>
|
||||
<h5>
|
||||
Appointment
|
||||
</h5>
|
||||
<ul>
|
||||
<li>
|
||||
<code>date</code> → 12.09.2022
|
||||
|
|
|
@ -17,65 +17,52 @@
|
|||
</style>
|
||||
|
||||
<font color="white">
|
||||
<div style="
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 95vh;
|
||||
">
|
||||
<div style="
|
||||
text-align: center;
|
||||
">
|
||||
<div style="display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 95vh">
|
||||
<div style=" text-align: center; ">
|
||||
<h1>AdvLabDB</h1>
|
||||
<p>Database for labs</p>
|
||||
|
||||
<h2>Login</h2>
|
||||
|
||||
{% if message %}
|
||||
<div style="background-color: rgba(255,200,0,0.2); padding: 10px;">{{ message | safe }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% include "security/_messages.html" %}
|
||||
|
||||
<br>
|
||||
|
||||
<form action="{{ url_for_security('login') }}" method="POST" name="login_user_form">
|
||||
<form action="{{ url_for_security('login') }}"
|
||||
method="POST"
|
||||
name="login_user_form">
|
||||
{{ login_user_form.hidden_tag() }}
|
||||
{{ render_form_errors(login_user_form) }}
|
||||
|
||||
<div style="
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
">
|
||||
<div style=" display: flex; justify-content: center; ">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
Email
|
||||
</td>
|
||||
<td>
|
||||
{{ login_user_form.email() }}
|
||||
</td>
|
||||
<td>Email</td>
|
||||
<td>{{ login_user_form.email() }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Password
|
||||
</td>
|
||||
<td>
|
||||
{{ login_user_form.password() }}
|
||||
</td>
|
||||
<td>Password</td>
|
||||
<td>{{ login_user_form.password() }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if login_user_form.email.errors %}
|
||||
<ul>
|
||||
{% for error in login_user_form.email.errors %}
|
||||
<li class="fs-error-msg">{{ error }}</li>
|
||||
{% endfor %}
|
||||
{% for error in login_user_form.email.errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if login_user_form.password.errors %}
|
||||
<ul>
|
||||
{% for error in login_user_form.password.errors %}
|
||||
<li class="fs-error-msg">{{ error }}</li>
|
||||
{% endfor %}
|
||||
{% for error in login_user_form.password.errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
|
@ -85,9 +72,7 @@
|
|||
|
||||
{% if login_user_form.remember.errors %}
|
||||
<ul>
|
||||
{% for error in login_user_form.remember.errors %}
|
||||
<li class="fs-error-msg">{{ error }}</li>
|
||||
{% endfor %}
|
||||
{% for error in login_user_form.remember.errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue