Исправил баг отображения названия проекта, а также добавил раздел ссылок в витрину
This commit is contained in:
parent
213f793942
commit
c979eccaf7
16
data/showcase_link.py
Normal file
16
data/showcase_link.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sqlalchemy
|
||||
from flask_login import UserMixin
|
||||
|
||||
from .db_session import SqlAlchemyBase
|
||||
|
||||
|
||||
class ShowCaseLink(SqlAlchemyBase, UserMixin):
|
||||
__tablename__ = 'showcase_link'
|
||||
|
||||
id = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
primary_key=True, autoincrement=True)
|
||||
link = sqlalchemy.Column(sqlalchemy.Text, nullable=True, default=None)
|
||||
name = sqlalchemy.Column(sqlalchemy.Text, nullable=True, default=None)
|
||||
user = sqlalchemy.Column(sqlalchemy.Integer,
|
||||
sqlalchemy.ForeignKey("users.id"), nullable=True, default=None)
|
||||
up_date = sqlalchemy.Column(sqlalchemy.DateTime, nullable=False)
|
||||
9
forms/link_showcase.py
Normal file
9
forms/link_showcase.py
Normal file
@ -0,0 +1,9 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
class AddLink(FlaskForm):
|
||||
link = StringField('Ссылка', validators=[DataRequired()])
|
||||
name = StringField('Название', validators=[DataRequired()])
|
||||
submit = SubmitField('Сохранить')
|
||||
38
main.py
38
main.py
@ -18,6 +18,7 @@ from functions import check_password, mail, init_db_default, get_projects_data,
|
||||
copy_template, save_admin_data
|
||||
|
||||
from forms.edit_profile import EditProfileForm
|
||||
from forms.link_showcase import AddLink
|
||||
from forms.login import LoginForm
|
||||
from forms.find_project import FindProjectForm
|
||||
from forms.register import RegisterForm
|
||||
@ -35,6 +36,7 @@ from data.files import Files
|
||||
from data.projects import Projects
|
||||
from data.staff_projects import StaffProjects
|
||||
from data.roles import Roles
|
||||
from data.showcase_link import ShowCaseLink
|
||||
from data import db_session
|
||||
|
||||
app = Flask(__name__)
|
||||
@ -82,6 +84,9 @@ def admin():
|
||||
if int(user.role) != 1:
|
||||
user.activated = 0 if user.id not in activ_id else 1
|
||||
user.banned = 0 if user.id not in banned_id else 1
|
||||
else:
|
||||
user.banned = 0
|
||||
user.activated = 1
|
||||
data_session.commit()
|
||||
return render_template('admin.html', title='Панель админа', roles=roles, users=users, form=form)
|
||||
abort(404)
|
||||
@ -129,13 +134,44 @@ def template_project(id_template):
|
||||
return redirect('/login')
|
||||
|
||||
|
||||
@app.route('/showcase/link/<int:id_link>/delete')
|
||||
def delete_link(id_link):
|
||||
if current_user.is_authenticated:
|
||||
if current_user.role in [1, 4]:
|
||||
data_session = db_session.create_session()
|
||||
link = data_session.query(ShowCaseLink).filter(ShowCaseLink.id == id_link).first()
|
||||
if link:
|
||||
data_session.delete(link)
|
||||
data_session.commit()
|
||||
return redirect('/showcase')
|
||||
else:
|
||||
abort(404)
|
||||
else:
|
||||
abort(403)
|
||||
return redirect('/login')
|
||||
|
||||
|
||||
@app.route('/showcase', methods=['GET', 'POST'])
|
||||
def showcase():
|
||||
if current_user.is_authenticated:
|
||||
form = AddLink() if current_user.role in [1, 4] else None
|
||||
data_session = db_session.create_session()
|
||||
if request.method == 'POST' and current_user.role in [1, 4]:
|
||||
if form.validate_on_submit():
|
||||
link = ShowCaseLink(
|
||||
link=form.link.data,
|
||||
name=form.name.data,
|
||||
user=current_user.id,
|
||||
up_date=datetime.datetime.now()
|
||||
)
|
||||
data_session.add(link)
|
||||
data_session.commit()
|
||||
return redirect('/showcase')
|
||||
list_template = list(map(lambda curr_project: get_projects_data(curr_project),
|
||||
data_session.query(Projects).filter(Projects.is_template == 1).all()))
|
||||
return render_template('showcase.html', title='Витрина', list_template=list_template)
|
||||
list_links = data_session.query(ShowCaseLink).all()
|
||||
return render_template('showcase.html', title='Витрина', list_template=list_template, list_links=list_links,
|
||||
form=form, type=type)
|
||||
else:
|
||||
return redirect('/login')
|
||||
|
||||
|
||||
@ -111,8 +111,9 @@
|
||||
border-radius: 5vw;
|
||||
}
|
||||
.project_title_block {
|
||||
width: 70%;
|
||||
width: 100%;
|
||||
height: 4vw;
|
||||
margin-left: 1vw;
|
||||
}
|
||||
.project_title {
|
||||
font-size: 3.5vw;
|
||||
@ -129,9 +130,9 @@
|
||||
border: 0.25vw solid #ffffff;
|
||||
}
|
||||
.project_button_block_one {
|
||||
width: 50%;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.project_description {
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
width: 95%;
|
||||
margin-top: 5vw;
|
||||
}
|
||||
.templates_title {
|
||||
.templates_title, .links_title {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
font-size: 3.5vw;
|
||||
@ -64,6 +64,17 @@
|
||||
color: #ffffff;
|
||||
font-size: 2vw;
|
||||
font-weight: 500;
|
||||
overflow-y: hidden;
|
||||
overflow-x: auto;
|
||||
white-space: nowrap
|
||||
}
|
||||
.template_title::-webkit-scrollbar {
|
||||
height: 0.8vw; /* ширина scrollbar */
|
||||
}
|
||||
.template_title::-webkit-scrollbar-thumb {
|
||||
background-color: #d49d51; /* цвет плашки */
|
||||
border-radius: 5vw; /* закругления плашки */
|
||||
border: 0.25vw solid #ffffff;
|
||||
}
|
||||
.description {
|
||||
background-color: #EDCBB0;
|
||||
@ -127,4 +138,80 @@
|
||||
.open_button_link:hover {
|
||||
text-decoration: none;
|
||||
color: #000000;
|
||||
}
|
||||
.links_block {
|
||||
margin-top: 4vw;
|
||||
height: 17vw;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
.link_list {
|
||||
width: 95%;
|
||||
background-color: #EDCBB0;
|
||||
height: 16vw;
|
||||
border-radius: 1.5vw;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.link_block {
|
||||
margin: 1vw;
|
||||
width: 15vw;
|
||||
height: 6vw;
|
||||
background-color: #9E795A;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 1vw;
|
||||
}
|
||||
.link {
|
||||
width: auto;
|
||||
min-width: 15vw;
|
||||
max-width: 20vw;
|
||||
height: 6vw;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.link:hover {
|
||||
text-decoration: none;
|
||||
color: #ffffff;
|
||||
}
|
||||
.link_text {
|
||||
height: 1.8vw;
|
||||
color: #ffffff;
|
||||
font-size: 2vw;
|
||||
}
|
||||
.add_button, .link_delete, .repeal_button, .submit_button {
|
||||
border-radius: 1vw !important;
|
||||
margin: 1vw;
|
||||
width: 8vw;
|
||||
height: 3vw;
|
||||
}
|
||||
.link_delete, .repeal_button {
|
||||
background-color: hsla(0, 100%, 62%, 0.785) !important;
|
||||
border-color: hsla(0, 100%, 62%, 0.785) !important;
|
||||
}
|
||||
.delete_text {
|
||||
font-size: 1.3vw;
|
||||
}
|
||||
.header_link {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.form_link, .file_form {
|
||||
width: 90%;
|
||||
}
|
||||
.link_form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
}
|
||||
.form_data {
|
||||
margin: 0.5vw;
|
||||
}
|
||||
@ -25,8 +25,50 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="open_projects_block">
|
||||
|
||||
<div class="links_block">
|
||||
<div class="header_link">
|
||||
<h2 class="links_title">Полезные ссылки</h2>
|
||||
<button type="button" class="add_button btn btn-primary" id="add_link_button"
|
||||
onclick="add_link()">Добавить
|
||||
</button>
|
||||
<button type="button" class="repeal_button btn btn-primary" id="repeal_link_button"
|
||||
onclick="repeal_link()" style="display: none">Отмена
|
||||
</button>
|
||||
</div>
|
||||
<div class="link_list">
|
||||
{% for link in list_links %}
|
||||
<div class="link_block" {% if current_user.role in [1, 4] %}style="width:25vw !important;"{% endif %}>
|
||||
<a class="link" href="{{ link.link }}">
|
||||
<p class="link_text">{{ link.name }}</p>
|
||||
</a>
|
||||
{% if current_user.role in [1, 4] %}
|
||||
<a href="/showcase/link/{{ link.id }}/delete"
|
||||
class="btn btn-primary link_delete"><p class="delete_text">Удалить</p></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if current_user.role in [1, 4] %}
|
||||
<div class="form_link" id="form_link" style="display: none;">
|
||||
<form action="" method="post" class="link_form" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="form_data">
|
||||
{{ form.link(class="link_input form-control", type="text", placeholder="Ссылка") }}
|
||||
{% for error in form.link.errors %}
|
||||
<div class="alert alert-danger" role="alert">{{ error }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="form_data">
|
||||
{{ form.name(class="link_input form-control", type="text", placeholder="Название") }}
|
||||
{% for error in form.name.errors %}
|
||||
<div class="alert alert-danger" role="alert">{{ error }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{{ form.submit(type="submit", class="btn btn-primary submit_button") }}
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="../static/js/showcase.js"></script>
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user