예제 #1
0
    def get_debtors_by_subject_group(subject_id, group_id):
        debtors = session.query(SubjectDebtor, Student).filter(SubjectDebtor.subject_id == subject_id)\
            .filter(Student.group_id == group_id).filter(SubjectDebtor.student_id == Student.id).all()

        return [
            Student.get_student_by_id(debtor[0].student_id)
            for debtor in debtors
        ]
예제 #2
0
 def get_debtors_by_group(group_id):
     debtors = session.query(
         ProfcomDebtor,
         Student).filter(Student.group_id == group_id).filter(
             ProfcomDebtor.student_id == Student.id).all()
     return [
         Student.get_student_by_id(debtor[0].student_id)
         for debtor in debtors
     ]
예제 #3
0
def save_profcomdebtor(message, debtor_id, group):
    debt = message.text

    ProfcomDebtor.add_debtor(debtor_id, debt)

    username = Student.get_student_by_id(debtor_id).username
    name = Student.get_student_by_id(debtor_id).name

    bot.send_message(chat_id=message.from_user.id,
                     text=f'Студент <a href="t.me/{username}">{name}</a> '
                          f'групи {group} занесений до боржників '
                          f'{emojize(":heavy_exclamation_mark:", use_aliases=True)}',
                     parse_mode='html',
                     disable_web_page_preview=True)

    bot.send_message(chat_id=message.from_user.id,
                     text='Вибери пункт меню:',
                     reply_markup=make_role_replykeyboard(studdekan_buttons))
예제 #4
0
def change_headman(call):
    group = call.data.split('_')[1]
    new_headman_id = call.data.split('_')[2]

    Headman.change_headman(new_headman_id)

    username = Student.get_student_by_id(new_headman_id).username
    name = Student.get_student_by_id(new_headman_id).name

    bot.edit_message_text(chat_id=call.from_user.id,
                          message_id=call.message.message_id,
                          text=f'<a href="t.me/{username}">{name}</a> '
                          f'призначений старостою групи {group} '
                          f'{emojize(":white_check_mark:", use_aliases=True)}',
                          parse_mode='html')
    bot.send_message(chat_id=call.from_user.id,
                     text='Вибери пункт меню:',
                     reply_markup=make_role_replykeyboard(studdekan_buttons))
예제 #5
0
def show_headman_info(message):
    group = message.text
    group_id = Group.get_id_by_group(group)

    if group_id is False:
        bot.clear_step_handler_by_chat_id(message.from_user.id)
        bot.send_message(
            chat_id=message.from_user.id,
            text='Вибери пункт меню:',
            reply_markup=make_role_replykeyboard(studdekan_buttons))
    else:
        headman = Headman.get_headman_by_group(group_id)

        if not headman:
            keyboard = InlineKeyboardMarkup()
            keyboard.add(
                InlineKeyboardButton(
                    text=f'Призначити старосту '
                    f'{emojize(":white_check_mark:", use_aliases=True)}',
                    callback_data='assign_headman'))

            bot.send_message(chat_id=message.from_user.id,
                             text=f'Групі {group} непризначено старосту.\n'
                             'Для призначення старости скористайся командою '
                             f'{emojize(":point_down:", use_aliases=True)}',
                             reply_markup=keyboard)
        else:
            username = Student.get_student_by_id(headman.student_id).username
            name = Student.get_student_by_id(headman.student_id).name
            phone = Student.get_student_by_id(headman.student_id).phone

            bot.send_message(
                chat_id=message.from_user.id,
                text=
                f'Староста групи {group}: <a href="t.me/{username}">{name}</a>\n'
                f'Номер телефону: {phone}',
                parse_mode='html',
                disable_web_page_preview=True)
            bot.send_message(
                chat_id=message.from_user.id,
                text='Вибери пункт меню:',
                reply_markup=make_role_replykeyboard(studdekan_buttons))
예제 #6
0
def get_profcomdebtor_for_del(call):
    debtor_id = call.data.split('_')[1]

    group = Group.get_group_by_id(Student.get_student_by_id(debtor_id).group_id)
    username = Student.get_student_by_id(debtor_id).username
    name = Student.get_student_by_id(debtor_id).name

    bot.edit_message_text(chat_id=call.from_user.id,
                          message_id=call.message.message_id,
                          text=f'Студент <a href="t.me/{username}">{name}</a> '
                               f'групи {group} видалений з боржників '
                               f'{emojize(":heavy_exclamation_mark:", use_aliases=True)}',
                          parse_mode='html',
                          disable_web_page_preview=True)

    ProfcomDebtor.delete_debtor(debtor_id)

    bot.send_message(chat_id=call.from_user.id,
                     text='Вибери пункт меню:',
                     reply_markup=make_role_replykeyboard(studdekan_buttons))
예제 #7
0
def cancel_reg_on_event(call):
    event_id = call.data.split('_')[1]

    EventVisitor.delete_visitor(event_id, call.from_user.id)

    bot.edit_message_text(
        chat_id=call.from_user.id,
        message_id=call.message.message_id,
        text=
        f'Реєстрація скасована {emojize(":white_check_mark:", use_aliases=True)}'
    )

    user = Student.get_student_by_id(call.from_user.id)
예제 #8
0
def save_extragrade(message, student_id):
    ExtraGrade.add_extragrade(extra_grade=int(message.text), student_id=student_id)

    student = Student.get_student_by_id(student_id)

    bot.send_message(chat_id=message.from_user.id,
                     text=f'Додатковий бал студенту '
                          f'<a href="t.me/{student.username}">{student.name}</a>'
                          f' було поставлено {emojize(":white_check_mark:", use_aliases=True)}',
                     parse_mode='html')

    bot.send_message(chat_id=message.from_user.id,
                     text='Вибери пункт меню:',
                     reply_markup=make_role_replykeyboard(studdekan_buttons))
예제 #9
0
def register_on_event(call):
    event_id = call.data.split('_')[1]
    chat_id = call.from_user.id

    if Group.get_group_by_id(
            Student.get_student_by_id(chat_id).group_id) == 'other':
        message = bot.send_message(
            chat_id=chat_id,
            text="Введіть прізвище ім'я факультет групу\n"
            "<b>Наприклад:</b> <i>Петров Петро ФЕУ 123</i>",
            parse_mode='html')
        bot.register_next_step_handler(message, reg_on_event_other, event_id)
    else:
        EventVisitor.add_visitor(event_id, chat_id)

        bot.edit_message_text(
            chat_id=chat_id,
            message_id=call.message.message_id,
            text=
            f'Реєстрація пройшла успішно {emojize(":white_check_mark:", use_aliases=True)}'
        )

        user = Student.get_student_by_id(chat_id)
예제 #10
0
def register_for_admins(message):
    if Student.get_student_by_id(message.from_user.id) is None:
        group_keyboard = make_keyboard(keyboard_type='group',
                                       elem_list=Group.get_groups(),
                                       marker='group_')

        bot.send_message(chat_id=message.from_user.id,
                         text='Вибери свою групу:',
                         reply_markup=group_keyboard)
        bot.register_next_step_handler_by_chat_id(message.from_user.id,
                                                  get_group)
    else:
        bot.send_message(chat_id=message.from_user.id,
                         text='Ти вже зареєстрований')
        bot.clear_step_handler_by_chat_id(chat_id=message.from_user.id)
예제 #11
0
def prepare_event_visitors_table(event_id):
    visitor_ids = EventVisitor.get_visitors(event_id)
    stud_dict = {}
    otherfac_list = []

    for visitor_id in visitor_ids:
        student = Student.get_student_by_id(visitor_id)

        if Group.get_group_by_id(student.group_id) == 'other':
            otherfac_list.append(EventVisitor.get_visitor_by_id(visitor_id).note)
        else:
            try:
                s_name = get_fio(student.name)
                s_group = f'КНТ-{Group.get_group_by_id(student.group_id)}'

                stud_dict.setdefault(s_group, []).append(s_name)
            except AttributeError:
                continue

    return stud_dict, otherfac_list
예제 #12
0
def list_headman(call):
    headmans_list = Headman.get_all_headmans()
    message_text = f'<b>Старости {len(headmans_list)}/52:</b>\n\n'

    for group in Group.get_groups():
        headman = Headman.get_headman_by_group(group_id=group.id)
        if headman:
            student = Student.get_student_by_id(headman.student_id)

            link = f'<a href="t.me/{student.username}">{get_fio(student.name)}</a> ({headman.rating})\n'
        else:
            link = '-\n'

        message_text += ''.join(f'КНТ-{group.name}: {link}')

    bot.edit_message_text(chat_id=call.from_user.id,
                          message_id=call.message.message_id,
                          text=message_text,
                          parse_mode='html',
                          disable_web_page_preview=True)
예제 #13
0
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
예제 #14
0
 def get_all_debtors():
     return [
         Student.get_student_by_id(debtor.student_id)
         for debtor in session.query(ProfcomDebtor).all()
     ]
예제 #15
0
 def change_headman(new_headman_id):
     new_headman = Student.get_student_by_id(new_headman_id)
     old_headman = Headman.get_headman_by_group(new_headman.group_id)
     old_headman.student_id = new_headman.id
     session.commit()