diff --git a/functions.py b/functions.py index f565fd0..4f8630b 100644 --- a/functions.py +++ b/functions.py @@ -1,3 +1,4 @@ +import datetime import smtplib from json import loads from email.message import EmailMessage @@ -6,6 +7,7 @@ from data.users import User from data.staff_projects import StaffProjects from data import db_session import uuid +import pymorphy2 def check_password(password=''): @@ -90,3 +92,31 @@ def save_project_logo(photo): with open(filename, 'wb') as f: photo.save(f) return filename + + +def overdue_quest_project(quest): + if str(quest.deadline.date()) == str(datetime.datetime.now().date()): + quest.overdue = 'today' + elif quest.deadline < datetime.datetime.now(): + quest.overdue = 'yes' + quest.time_left = 'Просрочено на' + round_date(quest.deadline) + else: + quest.overdue = 'no' + quest.time_left = 'Еще есть: ' + round_date(quest.deadline) + return quest + + +def round_date(date_time): + morph = pymorphy2.MorphAnalyzer() + difference = abs(date_time - datetime.datetime.now()).days + resp = '' + if difference // 365: + resp += f'{difference // 365} {morph.parse("год")[0].make_agree_with_number(difference // 365).word}' + difference -= 365 * (difference // 365) + if difference // 30: + resp += ', ' if resp else ' ' + f'{difference // 30}' \ + f' {morph.parse("месяц")[0].make_agree_with_number(difference // 30).word}' + difference -= 30 * (difference // 30) + if difference: + resp += ', ' if resp else ' ' + f'{difference} {morph.parse("день")[0].make_agree_with_number(difference).word}' + return f'{resp}' diff --git a/main.py b/main.py index 8e7b561..575d75b 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,8 @@ from itsdangerous import URLSafeTimedSerializer, SignatureExpired from sqlalchemy import or_ from json import loads -from functions import check_password, mail, init_db_default, get_projects_data, get_user_data, save_project_logo +from functions import check_password, mail, init_db_default, get_projects_data, get_user_data, save_project_logo, \ + overdue_quest_project from forms.edit_profile import EditProfileForm from forms.login import LoginForm from forms.find_project import FindProjectForm @@ -115,7 +116,15 @@ def project(id_project): if current_user.id == current_project.creator or current_user.id in list(map(lambda x: x.user, staff)): staff = list(map(lambda x: get_user_data(x), data_session.query(User).filter( User.id.in_(list(map(lambda x: x.user, staff)))).all())) if staff else [] - return render_template('project.html', project=current_project, title=current_project.name, staff=staff) + quests = data_session.query(Quests).filter(Quests.project == current_project.id).all() + if quests: + quests.sort(key=lambda x: (x.realized, x.deadline)) + quests = list(map(lambda x: overdue_quest_project(x), quests)) + return render_template('project.html', + project=current_project, + title=current_project.name, + staff=staff, + quests=quests) else: abort(403) else: diff --git a/requirements.txt b/requirements.txt index be128f6..dcd1a72 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/static/css/project.css b/static/css/project.css index 7cf9d63..d86eefa 100644 --- a/static/css/project.css +++ b/static/css/project.css @@ -104,6 +104,9 @@ font-size: 3vw; margin-bottom: 15px; } +.header_title_2 { + width: 51vw !important; +} .header_title { width: 100%; } @@ -147,4 +150,126 @@ flex-direction: row; flex-wrap: nowrap; width: 60vw; + justify-content: center; + align-items: flex-start; +} +.list_quests { + width: 95%; + margin-left: 2.5%; + margin-top: 2vw; + overflow-y: hidden; + overflow-x: hidden; +} +.quest_header_button { + height: 4.5vw; + width: 100%; + text-align: left; + border-radius: 5vw; + background-color: #9E795A; + border-color: #9E795A; + border-bottom-color: #9E795A; + color: #ffffff; + display: flex; + align-items: center; +} +.quest_button_block_one { + width: 50%; + display: flex; + justify-content: space-between; + align-items: flex-start; +} +.quest_title_block { + width: 90%; + height: 4vw; + display: flex; + align-items: center; +} +.quest_title { + overflow-y: hidden; + overflow-x: hidden; + max-height: 1.5vw; + font-size: 1.5vw; + display: flex; + align-items: center; + margin-top: 0.7vw; + margin-left: 1.8vw; +} +.deadline_block { + border-radius: 5vw !important; + width: 15vw; + height: 70%; + margin-top: 2%; + font-size: 1vw; + display: flex; + color: #000000 !important; + align-items: center; + justify-content: center; + flex-direction: row; +} +.quest_body_block { + background-color: #9E795A; + width: 100%; + height: 20vw; + border-radius: 2vw; + display: flex; + align-items: center; + justify-content: center; +} +.quest_body { + width: 94%; + height: 94%; + display: flex; + align-items: center; + justify-content: space-around; +} +.quest_description_block { + width: 70%; + height: 90%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} +.quest_description { + width: 100%; + height: 100%; + background-color: #dcb495; + border-radius: 2vw; + overflow-y: auto; +} +.quest_description::-webkit-scrollbar, .task_block::-webkit-scrollbar-thumb { + width: 0.8vw !important; +} +.quest_description::-webkit-scrollbar-thumb, .task_block::-webkit-scrollbar-thumb { + background-color: #d49d51 !important; /* цвет плашки */ + border-radius: 5vw !important; /* закругления плашки */ + border: 0.25vw solid #ffffff !important; +} +.quest_description_text { + margin: 20px; +} +.quest_solve_button { + width: 13vw; + height: 5vw; + background-color: #000000; + border: 2px solid #ffffff; + border-radius: 3vw; + margin-left: 2vw; +} +.quest_solve_link:hover { + text-decoration: none; + color: #000000; +} +.quest_solve_text { + width: 13vw; + height: 5vw; + text-align: center; + font-size: 1.5vw; + color: #ffffff; + display: flex; + align-items: center; + justify-content: center; +} +#quest_solve_link_id { + display: none; } \ No newline at end of file diff --git a/static/js/project.js b/static/js/project.js index b75b539..67de248 100644 --- a/static/js/project.js +++ b/static/js/project.js @@ -1,2 +1,7 @@ -var edit_button = document.getElementById("edit_button"); -edit_button.href = String(window.location.href) + '/edit'; \ No newline at end of file +var edit_button = document.getElementById("edit_button"), +new_task_link = document.getElementById("new_task_link"), +quest_solve_link = document.getElementById("quest_solve_link"), +quest_solve_link_id = document.getElementById("quest_solve_link_id"); +edit_button.href = String(window.location.href) + '/edit'; +new_task_link.href = String(window.location.href) + '/task/new'; +quest_solve_link.href = String(window.location.href) + '/quest/' + quest_solve_link_id.className; \ No newline at end of file diff --git a/templates/project.html b/templates/project.html index a108cc4..a89c3f9 100644 --- a/templates/project.html +++ b/templates/project.html @@ -35,14 +35,72 @@
Описание
+{{ quest.description }}
+