def get_event_info(call): event_id = call.data.split('_')[1] event = Event.get_event(event_id) message = f'<b> {event.name} </b>\n' \ f'Місце проведення: {event.place}\n' \ f'Дата: {event.date}\n' \ f'Час: {event.time}' if EventVisitor.check_visitor(event_id=event_id, student_id=call.from_user.id) is False: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text= f'{emojize(":pencil2:", use_aliases=True)} Зареєструватися', callback_data=f'regon_{event.id}')) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message, reply_markup=keyboard, parse_mode='html') else: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text=f'{emojize(":x:", use_aliases=True)} Відмінити реєстрацію', callback_data=f'cancelregevent_{event.id}')) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message, reply_markup=keyboard, parse_mode='html')
def send_event_visitors_file(call): event_id = call.data.split('_')[1] event_name = Event.get_event(event_id).name file_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/tmp/' stud_dict, otherfac_list = prepare_event_visitors_table(event_id) make_event_visitors_table(visitors_dict=stud_dict, otherfac_list=otherfac_list, event_name=event_name, file_path=file_path) doc = open(f'{file_path}{event_name}.xlsx', 'rb') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Документ з учасниками:') bot.send_document(chat_id=call.from_user.id, data=doc)
def prepare_student_events_table(): group_dict = {} for group in Group.get_groups(): students = EventVisitor.get_visitor_students(group.id) if not students: continue else: stud_dict = {} for student in students: try: s_name = get_fio(Student.get_student_by_id(student[1].student_id).name) s_event = Event.get_event(student[1].event_id).name stud_dict.setdefault(s_name, []).append(s_event) except AttributeError: continue group_dict[group.name] = stud_dict return group_dict