Skip to content

Commit

Permalink
feature: Ability to rename groups
Browse files Browse the repository at this point in the history
  • Loading branch information
worldbeater committed Sep 21, 2024
1 parent 2b7063b commit 6acd221
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 9 additions & 1 deletion webapp/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def get_by_id(self, group_id: int) -> Group:
group = session.query(Group).get(group_id)
return group

def rename(self, group_id: int, title: str):
with self.db.create_session() as session:
session.query(Group) \
.filter_by(id=group_id) \
.update(dict(title=title))

def create_by_names(self, names: list[str]):
for name in names:
self.create(name)
Expand Down Expand Up @@ -519,7 +525,9 @@ def create_external(self, email: str, provider: str) -> Student:

def update_group(self, student: Student, group: str | None):
with self.db.create_session() as session:
session.query(Student).filter_by(id=student.id).update(dict(group=group))
session.query(Student) \
.filter_by(id=student.id) \
.update(dict(group=group))


class MailerRepository:
Expand Down
16 changes: 15 additions & 1 deletion webapp/templates/teacher/exam.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
</label>
<button class="btn btn-outline-primary w-100 mb-2 d-block" type="submit">Начать</button>
</form>
<form action="/teacher/group/{{ group.id }}/rename" method="GET" class="w-100">
<label class="mx-auto fw-bold mt-2 mb-2 d-block">
Видимое название группы {{ group.external }}
</label>
<input
name="title"
type="text"
class="form-control mb-2"
placeholder="Видимое название группы"
value="{{ group.title }}">
<button class="btn btn-outline-primary w-100 mb-2 d-block" type="submit">
Переименовать группу
</button>
</form>
{% elif seed.active == false %}
<h6 class="d-block fw-bold">Зачёт завершён</h6>
<div class="mx-auto mb-2 breadcrumb-item active d-block">
Expand Down Expand Up @@ -53,7 +67,7 @@
</label>
<button class="btn btn-outline-primary w-100 mb-2 d-block" type="submit">Завершить</button>
</form>
<h6 class="d-block mt-3">Выгрузка промежуточных результатов</h6>
<h6 class="d-block fw-bold mt-3">Выгрузка промежуточных результатов</h6>
<form action="/teacher/group/{{ group.id }}/exam/csv" method="GET" class="w-100">
<label class="mx-auto mb-2 breadcrumb-item active d-block">Разделитель CSV</label>
<select class="form-select mb-2" name="delimiter">
Expand Down
9 changes: 9 additions & 0 deletions webapp/views/teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def select_group(teacher: Student):
return redirect(f'/teacher/group/{group}')


@blueprint.route("/teacher/group/<group_id>/rename", methods=["GET"])
@teacher_jwt_required(db.students)
def rename(teacher: Student, group_id: int):
group = db.groups.get_by_id(group_id)
title = request.args.get('title')
db.groups.rename(group_id, title if title else group.external)
return redirect(f'/teacher/group/{group_id}/exam')


@blueprint.route("/teacher/group/<group_id>/exam", methods=["GET"])
@teacher_jwt_required(db.students)
def exam(teacher: Student, group_id: int):
Expand Down

0 comments on commit 6acd221

Please sign in to comment.