Skip to content

Commit

Permalink
some fixes in lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinRaikhert committed Oct 3, 2024
1 parent fba30b3 commit 4f13842
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/bot/bot_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
lesson_end_handler, schedule_handler, start_handler,
success_registration_webapp_handler,
unknown_command_handler)
from bot.handlers.conversation import help, schedule
from bot.handlers.conversation import help
from bot.handlers.feedback import body, subject
from bot.persistence import DjangoPersistence
from bot.states import UserStates
Expand Down Expand Up @@ -79,7 +79,7 @@ async def _build_app(self):
start_handler,
help_handler,
success_registration_webapp_handler,
unknown_command_handler, # Переименованный echo handler
unknown_command_handler,
feedback_handler,
schedule_handler,
lesson_end_handler,
Expand Down Expand Up @@ -195,10 +195,10 @@ async def build_main_handler():
persistent=True,
states={
UserStates.START: [
feedback_handler,
start_handler,
CallbackQueryHandler(help,
pattern=f'^{UserStates.HELP.value}$'),
CallbackQueryHandler(schedule,
CallbackQueryHandler(schedule_handler,
pattern=f'^{UserStates.SCHEDULE.value}$'),
],
UserStates.HELP: [
Expand Down
5 changes: 4 additions & 1 deletion src/bot/handlers/was_the_lesson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
)
from telegram.ext import CallbackContext, CallbackQueryHandler

from schooling.models import Lesson
from schooling.models import Lesson, Student
from bot.states import UserStates
from bot.messages_texts.constants import (
UNCOMPLETED_LESSON_FEEDBACK_MSG,
Expand Down Expand Up @@ -80,6 +80,9 @@ async def was_the_lesson_completed(update: Update, context: CallbackContext):
if lesson.is_passed_teacher and lesson.is_passed_student:
lesson.is_passed = True
await lesson.asave()
student = await Student.objects.aget(telegram_id=student_tg_id)
student.paid_lessons -= 1
await student.asave()
context.user_data['lesson_responses'].clear()

if teacher_answ == 'no' or student_answ == 'no':
Expand Down
8 changes: 0 additions & 8 deletions src/schooling/signals_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs):
lambda: instance.teacher_old.telegram_id,
)()
chat_ids = (student_telegram_id, teacher_old_telegram_id)
msg_teacher = await get_message_text(instance)
msg_text = (
f'Ваше занятие на тему "{instance.name}" '
f'проведёт преподаватель {instance.teacher_id}\n'
Expand All @@ -205,7 +204,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs):
await sync_to_async(lambda: instance.student_id.telegram_id)(),
await sync_to_async(lambda: instance.teacher_id.telegram_id)(),
)
chat_id = None

elif instance.teacher_old != instance.teacher_id:
message_text = msg_text
Expand All @@ -230,12 +228,6 @@ async def msg_change_lesson(sender, instance, created, **kwargs):
reply_markup=reply_markup,
)

if chat_id:
bot_token = settings.TELEGRAM_TOKEN
await send_message_to_user(
bot_token, chat_id, msg_teacher, reply_markup,
)


@receiver(pre_delete, sender=Lesson)
async def delete_lesson_and_send_msg(sender, instance, *args, **kwargs):
Expand Down

0 comments on commit 4f13842

Please sign in to comment.