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 handle_classroom_link_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) teacher = Teacher.get(call.message.chat.id) classroom = Classroom.get(data['classroom_id']) classroom_link_view(teacher, classroom) classroom_detail_view(teacher, classroom)
def handle_classroom_query(call): bot.clear_step_handler_by_chat_id(call.message.chat.id) data = get_call_data(call) classroom = Classroom.get(data['classroom_id']) teacher = Teacher.get(call.message.chat.id) delete_classroom_scenario.are_you_sure_request(call.message, teacher, classroom)
def new_task_notification(task): classroom = Classroom.get(task.classroom_id) teacher = Teacher.get(classroom.teacher_id) students = Student.get_classroom_students(classroom.id) ru_text = f"🔔 Новое задание: *{task.name}*\n\n*{classroom.name}*. Учитель: _{teacher.fullname}_" en_text = f"🔔 New task: *{task.name}*\n\n*{classroom.name}*. Teacher: _{teacher.fullname}_" for student in students: text = ru_text if student.language_code == 'ru' else en_text bot.send_message(student.id, text, parse_mode='MarkDown') task_detail_view(student, task)
def get_classrooms(self): try: classrooms = execute_database_command( '''SELECT cl.teacher_id, cl.name, cl.slug, cl.created_utc, cl.id FROM teachers t JOIN classrooms cl ON t.id = cl.teacher_id WHERE t.id=%s''', (self.id, ))[0] return [ Classroom(cl[0], cl[1], cl[2], cl[3], cl[4]) for cl in classrooms ] except IndexError: return None
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 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 compose_task(message, task): teacher = Teacher.get(message.chat.id) if message.text in ['Выдать задание', 'Assign task']: ru_text = "Задание выдано вашим ученикам" en_text = "The task has been sent to your students" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) classroom = Classroom.get(task.classroom_id) classroom_detail_view(teacher, classroom) new_task_notification(task) elif message.text in ['❌ Отмена', '❌ Cancel']: ru_text = "Отмена" en_text = "Cancel" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message(message.chat.id, text, reply_markup=remove_markup()) classroom = Classroom.get(task.classroom_id) classroom_detail_view(teacher, classroom) task.delete() else: task.add(message) ru_text = "Отправьте ещё что-то или нажмите *Выдать задание*" en_text = "Send something else or tap *Assign task*" text = ru_text if teacher.language_code == 'ru' else en_text bot.send_message( message.chat.id, text, reply_markup=markups.get_compose_task_markup(teacher), parse_mode='Markdown', ) bot.register_next_step_handler(message, compose_task, task)
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 classroom_name_receive(message): teacher = Teacher.get(message.chat.id) classroom = Classroom(teacher.id, message.text, created_utc=datetime.now(timezone.utc)).save() classroom_link_view(teacher, classroom) classroom_list_view(teacher)