Добавил в БД новые таблицы: projects, staff_projects. Сделал функцию init_db_default() которая заполняет БД начальными данными при первом запуске. Создал страницу ошибки 404, начал работать над страницей проектов.

This commit is contained in:
Andrei 2022-12-27 15:10:26 +05:00
parent f05d705219
commit afca8cf50c
12 changed files with 270 additions and 12 deletions

View File

@ -1 +1 @@
from . import users, roles, files
from . import users, roles, files, projects, staff_projects

19
data/projects.py Normal file
View File

@ -0,0 +1,19 @@
import sqlalchemy
from flask_login import UserMixin
from datetime import date
from .db_session import SqlAlchemyBase
class Projects(SqlAlchemyBase, UserMixin):
__tablename__ = 'projects'
id = sqlalchemy.Column(sqlalchemy.Integer,
primary_key=True, autoincrement=True)
name = sqlalchemy.Column(sqlalchemy.String, nullable=False)
about = sqlalchemy.Column(sqlalchemy.String, nullable=True)
photo = sqlalchemy.Column(sqlalchemy.Text)
date_create = sqlalchemy.Column(sqlalchemy.Date,
default=date.today())
creator = sqlalchemy.Column(sqlalchemy.Integer,
sqlalchemy.ForeignKey("users.id"), nullable=True, default=None)

16
data/staff_projects.py Normal file
View File

@ -0,0 +1,16 @@
import sqlalchemy
from flask_login import UserMixin
from .db_session import SqlAlchemyBase
class StaffProjects(SqlAlchemyBase, UserMixin):
__tablename__ = 'staff_projects'
id = sqlalchemy.Column(sqlalchemy.Integer,
primary_key=True, autoincrement=True)
user = sqlalchemy.Column(sqlalchemy.Integer,
sqlalchemy.ForeignKey("users.id"), nullable=True, default=None)
role = sqlalchemy.Column(sqlalchemy.Text)
permission = sqlalchemy.Column(sqlalchemy.Integer,
sqlalchemy.ForeignKey("roles.id"), nullable=True, default=None)

View File

@ -1,5 +1,7 @@
import smtplib
from email.message import EmailMessage
from data.roles import Roles
from data import db_session
def check_password(password=''):
@ -35,3 +37,16 @@ def mail(msg, to, topic='Подтверждение почты'):
mailServer.ehlo()
mailServer.send_message(em)
mailServer.quit()
def init_db_default():
data_session = db_session.create_session()
roles = [['admin', 2], ['moderator', 1], ['user', 0]]
for i in roles:
role = Roles(
name=i[0],
rights=i[1]
)
data_session.add(role)
data_session.commit()
data_session.close()

17
main.py
View File

@ -7,7 +7,7 @@ from werkzeug.datastructures import CombinedMultiDict
from werkzeug.utils import redirect
from itsdangerous import URLSafeTimedSerializer, SignatureExpired
from functions import check_password, mail
from functions import check_password, mail, init_db_default
from forms.edit_profile import EditProfileForm
from forms.login import LoginForm
from forms.register import RegisterForm
@ -32,9 +32,11 @@ def base():
return redirect('/projects')
@app.route('/projects')
@app.route('/projects', methods=['GET', 'POST'])
def project():
if current_user.is_authenticated:
if request.method == 'POST':
print(request.form.to_dict())
return render_template('projects.html', title='Проекты')
else:
return redirect('/login')
@ -190,8 +192,17 @@ def confirmation(token):
return redirect('/login?message=Срок действия ссылки истек, данные удалены&danger=True')
@app.errorhandler(404)
def page_not_found(error):
return render_template('page404.html', title='Страница не найдена')
def main():
db_session.global_init("db/incepted.db")
db_path = 'db/incepted.db'
db = os.path.exists(db_path)
db_session.global_init(db_path)
if not db:
init_db_default()
serve(app, host='0.0.0.0', port=5000)

72
static/css/page404.css Normal file
View File

@ -0,0 +1,72 @@
.navbar {
display: none !important;
}
.page_404 {
height: 55vw;
background-color: #dcb495;
display: flex;
flex-direction: column;
}
.header_block {
display: flex;
flex-direction: column;
width: 80%;
height: 15vw;
margin-left: 10%;
margin-top: 80px;
justify-content: space-around;
}
.header {
display: flex;
align-items: center;
justify-content: center;
}
.line_top {
height: 0.03vw;
background: #000000;
width: 32vw;
}
.header_rect {
width: 15vw;
height: 3.3vw;
background-color: #000000;
display: flex;
justify-content: center;
align-items: center;
}
.header_rect_text {
color: #ffffff;
font-size: 1.6vw;
}
.header_title {
color: #000000;
font-size: 3vw;
}
.line_bottom {
height: 0.03vw;
background: #000000;
width: 100%;
}
.link_block {
width: 100%;
margin-top: 50px;
display: flex;
justify-content: center;
}
.block_to_home {
width: 20vw;
height: 20vw;
background-color: #000000;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10vw;
}
.link_to_home {
height: 12.3vw;
width: 15vw;
}
.link_image {
height: 12.3vw;
width: 15vw;
}

View File

@ -6,7 +6,7 @@
background: linear-gradient( rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.8) ), url(../images/back_profile_one.jpg);background-repeat: repeat; background-position: center;
}
.profile_block {
height: 65vw;
height: 57vw;
width: 85%;
margin-left: 7.5%;
margin-bottom: 6%;

View File

@ -1,3 +1,67 @@
.projects_page {
height: 65vw;
height: 120vw;
background-color: #dcb495;
}
.header_block {
width: 100%;
height: 50vw;
background-position: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient( rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85) ), url(../images/back_project_one.jpg);background-repeat: repeat; background-position: center;
}
.header_title {
color: #ffffff;
font-size: 7vw;
}
.header_title_2 {
color: #ffffff;
text-align: center;
margin-top: 50px;
font-size: 1.5vw;
width: 50vw;
}
.find_block {
width: 100%;
height: 15vw;
background-color: #dcb495;
display: flex;
align-items: center;
flex-direction: row;
justify-content: center;
}
.find_input_text {
margin-right: 12px;
background-color: #EDCBB0;
border: #EDCBB0;
width: 45vw;
height: 5vw;
color: #776658;
border-radius: 30px;
vertical-align: middle;
}
.find_input_button {
margin-left: 12px;
background-color: #9E795A;
border: #9E795A;
width: 10vw;
height: 5vw;
color: #ffffff;
border-radius: 30px;
vertical-align: middle;
}
.list_project_block {
margin-left: 3%;
border: 2px solid #694a2d;
border-radius: 25px;
width: 94%;
height: 45vw;
}
.list_project {
width: 95%;
margin-left: 2.5%;
height: 95%;
margin-top: 2.5%;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

27
templates/page404.html Normal file
View File

@ -0,0 +1,27 @@
<link rel="stylesheet" href="../static/css/page404.css"/>
{% extends "base.html" %} {% block content %}
<div class="page_404">
<div class="header_block">
<div class="header">
<hr class="line_top">
<div class="header_rect">
<strong class="header_rect_text">Ошибка 404</strong>
</div>
<hr class="line_top">
</div>
<div class="header">
<h2 class="header_title">Страница не найдена</h2>
</div>
<div class="header">
<hr class="line_bottom">
</div>
</div>
<div class="link_block">
<div class="block_to_home">
<a class="link_to_home" href="/#header_block">
<img class="link_image" src="../static/images/logo_w.png">
</a>
</div>
</div>
</div>
{% endblock %}

View File

@ -10,6 +10,11 @@
Редикторовать
</div>
</a>
<a class="profile_button" id="logout_button" href="/logout">
<div class="profile_button_text">
<p>Выйти</p>
</div>
</a>
</div>
</div>
<div class="profile_block collapse" id="collapseExample">
@ -88,11 +93,6 @@
</div>
<div class="form_data_button">
{{ form.submit(type="submit", class="profile_button") }}
<a class="profile_button" id="logout_button" href="/logout">
<div class="profile_button_text">
<p>Выйти</p>
</div>
</a>
</div>
</form>
</div>

View File

@ -1,6 +1,40 @@
<link rel="stylesheet" href="../static/css/projects.css"/>
{% extends "base.html" %} {% block content %}
<div class="projects_page">
<div class="header_block">
<h2 class="header_title">КНИЖКИ</h2>
<strong class="header_title_2">Здесь вы можете создавать свои проекты, изменять их, ставить дату дедлайна и
добавлять участников в своей проект.</strong>
</div>
<div class="find_block">
<form action="" method="post">
<input class="find_input_text" type="text" placeholder="Имя проекта" name="find_text">
<button class="find_input_button">Поиск</button>
</form>
</div>
<div class="list_project_block">
<div class="accordion list_project" id="accordionPanelsStayOpenExample">
<div class="accordion-item project">
<h2 class="accordion-header project_header" id="panelsStayOpen-headingOne">
<button class="accordion-button priject_header_button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Project 1
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the
collapse plugin adds the appropriate classes that we use to style each element. These classes
control the overall appearance, as well as the showing and hiding via CSS transitions. You can
modify any of this with custom CSS or overriding our default variables. It's also worth noting
that just about any HTML can go within the <code>.accordion-body</code>, though the transition
does limit overflow.
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}