def start(message): classroom_slug = message.text[12:] if message.text[7:] else None if classroom_slug: teacher = Teacher.get(message.chat.id) if teacher: ru_text = "Вы учитель и не можете добавляться в классы как ученик" en_text = "You are a teacher and can't be added to classrooms as a student" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.send_message( message.chat.id, "Классные комнаты", reply_markup=get_classroom_list_inline_markup(teacher)) else: student = Student.get(message.chat.id) or \ Student(message.chat.id, language_code='en', registered_utc=datetime.now(timezone.utc)).save() classroom = Classroom.get_by_slug(classroom_slug) teacher = Teacher.get(classroom.teacher_id) if not student.check_classroom_student(classroom.id): ClassroomStudent(classroom.id, student.id, joined_utc=datetime.now(timezone.utc)).save() if not student.fullname: student_fullname_request(message) else: ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, parse_mode='Markdown') bot.send_message( message.chat.id, 'Классные комнаты', reply_markup=get_classroom_list_inline_markup(student)) else: user = Student.get(message.chat.id) or Teacher.get(message.chat.id) if user: ru_text = "Вы уже зарегистрированы" en_text = "You are already registered" text = ru_text if user.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) classroom_list_view(user) else: # teacher = Teacher(message.chat.id, language_code=message.from_user.language_code) Teacher(message.chat.id, language_code='en', registered_utc=datetime.now(timezone.utc)).save() teacher_fullname_request(message)
def handle_classroom_assessments_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) student = Student.get(call.message.chat.id) classroom = Classroom.get(data['classroom_id']) classroom_assessments_view(student, classroom) classroom_detail_view(student, classroom)
def submission_message_list_view(user, submission, task): student = Student.get(submission.student_id) text = f"Выполненное задание: *{task.name}*. Ученик: _{student.fullname}_" if \ user.language_code == 'ru' else f"Submission: *{task.name}*. Student: _{student.fullname}_" bot.send_message(user.id, text, parse_mode='Markdown') ru_text = "Нажмите, чтобы исправить ошибки 👇🏻" en_text = "Tap to review 👇🏻" text = ru_text if user.language_code == 'ru' else en_text for submission_message in submission.messages: message = bot.forward_message(user.id, submission_message.student_id, submission_message.message_id) if type(user) is Teacher and message.photo: bot.delete_message(message.chat.id, message.message_id) message_with_button = bot.send_photo( user.id, message.photo[-1].file_id, ) bot.send_message(user.id, text, reply_markup=get_drawer_markup( message.photo[-1].file_id, user, message_with_button.message_id, submission.id))
def handle_task_messages_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) task = Task.get(data['task_id']) task_message_list_view(user, task) task_detail_view(user, task)
def handle_submission_message_list_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) submission = Submission.get(data['submission_id']) task = Task.get(submission.task_id) submission_message_list_view(user, submission, task) task_detail_view(user, task)
def student_fullname_request(message): student = Student.get(message.chat.id) ru_text = "Введите свою фамилию и имя. Их будут видеть ваши учителя." en_text = "Send your full name. Your teachers will see it." text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text) bot.register_next_step_handler(message, student_fullname_receive)
def handle_submission_review_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) submission = Submission.get(data['submission_id']) task = Task.get(submission.task_id) submission_message_list_view(user, submission, task) review_submission_scenario.submission_comment_request( call.message, data['submission_id'])
def new_submission_review_result_notification(submission): task = Task.get(submission.task_id) classroom = Classroom.get(task.classroom_id) student = Student.get(submission.student_id) teacher = Teacher.get(classroom.teacher_id) ru_text = f"🔔 Ваше задание проверено\n\n*{classroom.name}*\n_{teacher.fullname}_" en_text = f"🔔 New submission review\n\n*{classroom.name}*\n_{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(student.id, text, parse_mode='MarkDown') submission_review_result_view(student, submission, task) task_detail_view(student, task)
def student_fullname_receive(message): student = Student.get(message.chat.id) student.fullname = message.text student.save() classroom = student.get_classrooms()[-1] teacher = Teacher.get(classroom.teacher_id) ru_text = f"Вы добавлены в классную комнату *{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"You have been added to the classroom *{classroom.name}*. Teacher: _{teacher.fullname}_" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, parse_mode='Markdown') classroom_list_view(student)
def get_submissions_for_review_inline_markup(teacher, task): inline_markup = types.InlineKeyboardMarkup(row_width=1) for submission in task.submissions_for_review: student = Student.get(submission.student_id) inline_markup.add( types.InlineKeyboardButton( text=f"{student.fullname} ({submission.created_utc.strftime('%d.%m.%Y')})", callback_data='@@SUBMISSION_REVIEW/{"submission_id": ' + str(submission.id) + '}' ) ) inline_markup.add( types.InlineKeyboardButton( text="🔙 Назад" if teacher.language_code == 'ru' else '🔙 Back', callback_data='@@TASK/{"task_id": ' + str(task.id) + '}' ) ) return inline_markup
def handle_new_submission_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) student = Student.get(call.message.chat.id) submission = Submission(data['task_id'], student.id, status=SubmissionStatus.DRAFT.value, created_utc=datetime.now(timezone.utc)).save() ru_text = "Отправьте мне выполненное задание в любом формате: " \ "текст, фото, видео, файлы или аудиосообщения; одним или несколькими сообщениями." en_text = "Send me the submission in any format: " \ "text, photo, video, files or audio messages; one or more messages." text = ru_text if student.language_code == 'ru' else en_text bot.send_message(call.message.chat.id, text, parse_mode='Markdown') bot.register_next_step_handler( call.message, create_submission_scenario.compose_submission, submission)
def compose_submission(message, submission): student = Student.get(message.chat.id) if message.text in ['Отправить на проверку', 'Submit for review']: submission.status = SubmissionStatus.REVIEW.value submission.save() ru_text = "Ваше задание отправлено, ждите результата" en_text = "Your submission is sent, wait for the review result" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) task = Task.get(submission.task_id) task_detail_view(student, task) elif message.text in ['❌ Отмена', '❌ Cancel']: ru_text = "Отмена" en_text = "Cancel" text = ru_text if student.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) task = Task.get(submission.task_id) task_detail_view(student, task) submission.delete() else: submission.add(message) ru_text = "Отправьте ещё что-то или нажмите *Отправить на проверку*" en_text = "Send something else or tap *Submit for review*" text = ru_text if student.language_code == 'ru' else en_text bot.send_message( message.chat.id, text, reply_markup=markups.get_compose_submission_markup(student), parse_mode='Markdown', ) bot.register_next_step_handler(message, compose_submission, submission)
def handle_classroom_query(call): data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) classroom = Classroom.get(data['classroom_id']) classroom_detail_view(user, classroom, message_to_edit=call.message)
def handle_classrooms_query(call): user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) classroom_list_view(user, message_to_edit=call.message)
def handle_classrooms_command(message): user = Teacher.get(message.chat.id) or Student.get(message.chat.id) classroom_list_view(user)
def handle_task_query(call): data = get_call_data(call) user = Teacher.get(call.message.chat.id) or Student.get( call.message.chat.id) task = Task.get(data['task_id']) task_detail_view(user, task, message_to_edit=call.message)