diff --git a/data/showcase_link.py b/data/showcase_link.py new file mode 100644 index 0000000..bcc4f1c --- /dev/null +++ b/data/showcase_link.py @@ -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) diff --git a/forms/link_showcase.py b/forms/link_showcase.py new file mode 100644 index 0000000..3d1bcf6 --- /dev/null +++ b/forms/link_showcase.py @@ -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('Сохранить') diff --git a/main.py b/main.py index af8b507..b8ddef1 100644 --- a/main.py +++ b/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//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') diff --git a/static/css/projects.css b/static/css/projects.css index 684ed5d..ee9d18e 100644 --- a/static/css/projects.css +++ b/static/css/projects.css @@ -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 { diff --git a/static/css/showcase.css b/static/css/showcase.css index c4cb230..defb75d 100644 --- a/static/css/showcase.css +++ b/static/css/showcase.css @@ -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; } \ No newline at end of file diff --git a/templates/showcase.html b/templates/showcase.html index 114e25d..b4760ce 100644 --- a/templates/showcase.html +++ b/templates/showcase.html @@ -25,8 +25,50 @@ {% endfor %} -
- +
+ {% endblock %} \ No newline at end of file