Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some bugs in service for practices and in other places #83

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ flask_se_practice_yandex_secret.conf
**/__pycache__/

# Do not track documents for thesises
src/static/practice/reviews/*.pdf
src/static/practice/slides/*.pdf
src/static/practice/texts/*.pdf
src/static/practice/*/*.pdf
src/static/thesis/*/*.pdf

# Do not track fulltext search files
src/msearch/*
4 changes: 2 additions & 2 deletions src/flask_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def frequently_asked_questions():
return render_template("frequently_asked_questions.html")


@app.route("/nooffer.html")
@app.route("/nooffer")
def nooffer():
return render_template("nooffer.html")

Expand All @@ -680,7 +680,7 @@ def sitemap():
"""Generate sitemap.xml. Makes a list of urls and date modified."""
pages = []
skip_pages = [
"/nooffer.html",
"/nooffer",
"/fetch_theses",
"/Sitemap.xml",
"/sitemap.xml",
Expand Down
67 changes: 55 additions & 12 deletions src/flask_se_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from flask import redirect, url_for
from flask_admin import AdminIndexView, expose
from flask_admin.contrib.sqla import ModelView
from flask_admin.contrib.sqla.fields import QuerySelectField
from flask_login import current_user

from wtforms import TextAreaField, SelectField

from flask_se_config import SECRET_KEY_THESIS
from se_models import db
from se_models import db, Users, Staff, Worktype, Courses, AreasOfStudy

ADMIN_ROLE_LEVEL = 5
REVIEW_ROLE_LEVEL = 3
Expand All @@ -17,6 +17,8 @@

# Base model view with access and inaccess methods
class SeAdminModelView(ModelView):
can_set_page_size = True

def is_accessible(self):
if current_user.is_authenticated:
if current_user.role >= ADMIN_ROLE_LEVEL:
Expand All @@ -29,8 +31,46 @@ def inaccessible_callback(self, name, **kwargs):


class SeAdminModelViewThesis(SeAdminModelView):
column_exclude_list = ["text"]
pass
column_list = (
"name_ru",
"name_en",
"author",
"supervisor",
"publish_year",
"recomended",
"temporary",
"review_status",
"download_thesis",
"download_presentation",
)
form_extra_fields = {
"supervisor": QuerySelectField(
"Научный руководитель",
query_factory=lambda: Staff.query.all(),
get_pk=lambda staff: staff.id,
),
"owner": QuerySelectField(
"Author user",
query_factory=lambda: Users.query.all(),
get_pk=lambda user: user.id,
),
"type": QuerySelectField(
"Тип работы",
query_factory=lambda: Worktype.query.all(),
get_pk=lambda t: t.id,
),
"course": QuerySelectField(
"Курс",
query_factory=lambda: Courses.query.all(),
get_label=lambda c: c.name,
get_pk=lambda c: c.id,
),
"area": QuerySelectField(
"Направление обучения",
query_factory=lambda: AreasOfStudy.query.all(),
get_pk=lambda c: c.id,
),
}


class SeAdminModelViewReviewer(ModelView):
Expand Down Expand Up @@ -129,7 +169,7 @@ class SeAdminModelViewStaff(SeAdminModelView):
"still_working",
)
form_columns = (
"user_id",
"user",
"official_email",
"position",
"science_degree",
Expand All @@ -144,8 +184,13 @@ class SeAdminModelViewStaff(SeAdminModelView):
("к.т.н.", "к.т.н."),
]
}

pass
form_extra_fields = {
"user": QuerySelectField(
"User",
query_factory=lambda: Users.query.all(),
get_pk=lambda user: user.id,
)
}


class SeAdminModelViewNews(SeAdminModelView):
Expand Down Expand Up @@ -230,10 +275,10 @@ class SeAdminModelViewReviewDiplomaThemes(SeAdminModelViewReviewer):
"rows": 10,
"style": "width: 100%;",
},
"requirements": {"rows": 3, "style": "width: 100%;", "readonly": True},
"title": {"readonly": True},
"requirements": {"rows": 3, "style": "width: 100%;"},
"title": {"readonly": False},
"level": {"disabled": True},
"company": {"disabled": True},
"company": {"disabled": False},
"author": {"readonly": True},
"comment": {
"rows": 5,
Expand Down Expand Up @@ -270,5 +315,3 @@ class SeAdminModelViewCurrentThesis(SeAdminModelView):
status="Статус",
)
column_choices = {"status": [(1, "Текущая работа"), (2, "Завершенная работа")]}

pass
45 changes: 29 additions & 16 deletions src/flask_se_practice.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def practice_index():

return render_template(
PracticeStudentTemplates.MAIN.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
notifications=notifications,
notifications_not_viewed=notifications_not_viewed,
type_notifications=type_notifications,
Expand All @@ -120,7 +120,7 @@ def practice_index():
@login_required
def practice_guide():
return render_template(
PracticeStudentTemplates.GUIDE.value, thesises=get_list_of_thesises()
PracticeStudentTemplates.GUIDE.value, thesises=get_list_of_theses()
)


Expand Down Expand Up @@ -153,7 +153,7 @@ def practice_new_thesis():

return render_template(
PracticeStudentTemplates.NEW_PRACTICE.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
user=current_user,
review_filter=form,
form=form,
Expand All @@ -177,8 +177,12 @@ def practice_choosing_topic(current_thesis):
current_thesis.title = topic
current_thesis.supervisor_id = supervisor_id
db.session.commit()

supervisor_user_id = (
Staff.query.filter_by(id=supervisor_id).first().user_id
)
add_mail_notification(
supervisor_id,
supervisor_user_id,
"Добавлена новая учебная практика/ВКР",
render_template(
NotificationTemplates.NEW_PRACTICE_TO_SUPERVISOR.value,
Expand Down Expand Up @@ -207,14 +211,15 @@ def practice_choosing_topic(current_thesis):
form.staff.choices.append((0, "Выберите научного руководителя"))
for supervisor in (
Staff.query.join(Users, Staff.user_id == Users.id)
.filter(Staff.still_working)
.order_by(asc(Users.last_name))
.all()
):
form.staff.choices.append((supervisor.id, supervisor.user.get_name()))

return render_template(
PracticeStudentTemplates.CHOOSING_TOPIC.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
form=form,
practice=current_thesis,
deadline=deadline,
Expand All @@ -241,8 +246,11 @@ def practice_edit_theme(current_thesis):
current_thesis.title = topic
current_thesis.consultant = consultant
if current_thesis.supervisor_id != supervisor_id:
supervisor_user_id = (
Staff.query.filter_by(id=supervisor_id).first().user_id
)
add_mail_notification(
supervisor_id,
supervisor_user_id,
"Добавлена новая учебная практика/ВКР",
render_template(
NotificationTemplates.NEW_PRACTICE_TO_SUPERVISOR.value,
Expand All @@ -263,14 +271,15 @@ def practice_edit_theme(current_thesis):
for supervisor in (
Staff.query.join(Users, Staff.user_id == Users.id)
.filter(Staff.id != current_thesis.supervisor_id)
.filter(Staff.still_working)
.order_by(asc(Users.last_name))
.all()
):
form.staff.choices.append((supervisor.id, supervisor.user.get_name()))

return render_template(
PracticeStudentTemplates.EDIT_TOPIC.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
form=form,
practice=current_thesis,
)
Expand Down Expand Up @@ -352,7 +361,7 @@ def practice_goals_tasks(current_thesis):

return render_template(
PracticeStudentTemplates.GOALS_TASKS.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
practice=current_thesis,
)

Expand All @@ -376,7 +385,7 @@ def practice_workflow(current_thesis):
)
return render_template(
PracticeStudentTemplates.WORKFLOW.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
practice=current_thesis,
reports=reports,
)
Expand Down Expand Up @@ -415,8 +424,12 @@ def practice_add_new_report(current_thesis):
)
db.session.add(new_report)
db.session.commit()

supervisor_user_id = (
Staff.query.filter_by(id=current_thesis.supervisor_id).first().user_id
)
add_mail_notification(
current_thesis.supervisor_id,
supervisor_user_id,
"Новый отчёт по учебной практике",
render_template(
NotificationTemplates.NEW_REPORT_TO_SUPERVISOR.value,
Expand All @@ -431,7 +444,7 @@ def practice_add_new_report(current_thesis):
add_thesis_report_form = UserAddReport()
return render_template(
PracticeStudentTemplates.NEW_REPORT.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
practice=current_thesis,
form=add_thesis_report_form,
user=current_user,
Expand Down Expand Up @@ -668,7 +681,7 @@ def practice_preparation(current_thesis):
elif "delete_reviewer_review_button" in request.form:
current_thesis.reviewer_review_uri = None
db.session.commit()
elif "delete_supevisor_review_button" in request.form:
elif "delete_supervisor_review_button" in request.form:
current_thesis.supervisor_review_uri = None
db.session.commit()
elif "delete_code_link_button" in request.form:
Expand All @@ -686,7 +699,7 @@ def practice_preparation(current_thesis):

return render_template(
PracticeStudentTemplates.PREPARATION.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
practice=current_thesis,
deadline=deadline,
remaining_time_submit=get_remaining_time(deadline, "submit_work_for_review"),
Expand All @@ -699,7 +712,7 @@ def practice_preparation(current_thesis):
def practice_thesis_defense(current_thesis):
return render_template(
PracticeStudentTemplates.DEFENSE.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
practice=current_thesis,
)

Expand Down Expand Up @@ -747,14 +760,14 @@ def practice_data_for_practice(current_thesis):

return render_template(
PracticeStudentTemplates.SETTINGS.value,
thesises=get_list_of_thesises(),
thesises=get_list_of_theses(),
user=current_user,
form=form,
practice=current_thesis,
)


def get_list_of_thesises() -> List[CurrentThesis]:
def get_list_of_theses() -> List[CurrentThesis]:
return [thesis for thesis in current_user.current_thesises if not thesis.deleted]


Expand Down
2 changes: 1 addition & 1 deletion src/flask_se_practice_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def archive_thesis():

add_mail_notification(
current_thesis.author_id,
"[SE site] Ваша работы перенесена в архив практик и ВКР",
"[SE site] Ваша работа перенесена в архив практик и ВКР",
render_template(
NotificationTemplates.THESIS_WAS_ARCHIVED_BY_ADMIN.value,
curator=current_user,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/nooffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Main content -->
<section xmlns="http://www.w3.org/1999/html">
<!-- Container -->
<div class="container d-flex align-items-center pt-5 pt-lg-6 pb-5 border-bottom">
<div class="container d-flex align-items-center mt-7 pt-lg-6 pb-5 border-bottom">
<div class="col px-0">
<div class="row">
<div class="col-lg-9">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/practice/student/preparation.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ <h5 class="modal-title" id="ModalLabelSupervisor">Подтверждение</h5
Вы точно хотите удалить отзыв научного руководителя?
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-secondary" name="delete_supevisor_review_button" value="Да, удалить!">
<input type="submit" class="btn btn-secondary" name="delete_supervisor_review_button" value="Да, удалить!">
<button type="button" class="btn btn-primary" data-dismiss="modal">Нет, оставить</button>
</div>
</div>
Expand Down