Ejemplo n.º 1
0
def task(call, lang):
    course_ = Course.Course(call.data['c_id'])
    task_ = course_.task(call.data['t_id'])

    p = UI.Paging(course_.participants, sort_key='name')

    text = msgs[lang]['teacher']['management']['task'].format(name=task_.name, hmark=int(task_.highest_mark)) \
        + p.msg(call.data['page'], lang)

    c_text = msgs[lang]['confirm']['delete_task'].format(task_.name)

    markup = mkp.create_listed(
        lang,
        tbt.user_tasks_list(p.list(call.data['page']), call.data['c_id'],
                            call.data['t_id']), tbt.task, call.data['c_id'],
        call.data['t_id'], lang, call.data['page'])
    mkp.add_before_back(
        markup,
        cbt.confirm_action('del_task',
                           msgs[lang]['buttons']['confirm']['del_task'],
                           c_text,
                           call.message.chat.id,
                           call.message.message_id,
                           c_id=call.data['c_id'],
                           t_id=call.data['t_id']))

    botHelper.edit_mes(text, call, markup=markup)
Ejemplo n.º 2
0
def course_owner(call, lang):
    course_ = Course.Course(call.data['c_id'])

    text = msgs[lang]['teacher']['course_owner_full'].format(
        name=course_.name,
        num=len(course_.participants),
        lock=UI.to_dtime(course_.entry_restriction),
        desc=course_.description)
    c_text = msgs[lang]['confirm']['delete_course'].format(course_.name)
    markup = mkp.create(
        lang, [tbt.user_list(call.data['c_id'], lang)],
        [tbt.task_list(call.data['c_id'], lang)],
        [tbt.classwork_list(call.data['c_id'], lang)],
        [tbt.announce(call.data['c_id'], lang)], [
            tbt.switch_lock(call.data['c_id'],
                            True if course_.is_open else False, lang)
        ], [
            cbt.confirm_action(
                'delete_course',
                msgs[lang]['buttons']['confirm']['delete_course'],
                c_text,
                call.message.chat.id,
                call.message.message_id,
                c_id=course_.id)
        ])

    botHelper.edit_mes(text, call, markup=markup)
Ejemplo n.º 3
0
def cw(call, lang):
    course_ = Course.Course(call.data['c_id'])
    classwork = course_.classwork(call.data['cw_id'])

    p = UI.Paging(course_.participants, sort_key='name')

    text = msgs[lang]['teacher']['management']['classwork'].format(
        date=classwork.date) + p.msg(call.data['page'], lang)

    c_text = msgs[lang]['confirm']['delete_class'].format(classwork.name)

    markup = mkp.create_listed(
        lang,
        tbt.user_attendance_list(p.list(call.data['page']), call.data['c_id'],
                                 call.data['cw_id']), tbt.classwork,
        call.data['c_id'], call.data['cw_id'], lang, call.data['page'])
    mkp.add_before_back(
        markup,
        tbt.invert_attendance(call.data['c_id'], call.data['cw_id'], lang))
    mkp.add_before_back(
        markup, tbt.change_cw_date(call.data['c_id'], call.data['cw_id'],
                                   lang))
    mkp.add_before_back(
        markup,
        cbt.confirm_action('del_class',
                           msgs[lang]['buttons']['confirm']['del_class'],
                           c_text,
                           call.message.chat.id,
                           call.message.message_id,
                           c_id=call.data['c_id'],
                           cw_id=call.data['cw_id']))

    botHelper.edit_mes(text, call, markup=markup)
Ejemplo n.º 4
0
def usr_mng(call, lang):
    course_ = Course.Course(call.data['c_id'])
    tasks = course_.tasks
    user = User.User(call.data['u_id'])
    cws = course_.classworks

    if tasks:
        total_mark = sum(
            filter(None, map(lambda x: x.mark(call.data['u_id']).value,
                             tasks)))
        mean_mark = total_mark / len(tasks)
    else:
        total_mark = None
        mean_mark = None

    if cws:
        overall = len(cws)
        att = sum(map(lambda cw_: cw_.attendance(call.data['u_id']).value,
                      cws))
    else:
        overall = None
        att = None

    text = msgs[lang]['teacher']['management']['user'].format(
        course=course_.name,
        name=user.name,
        email='',
        mean=mean_mark,
        total=total_mark,
        attend=att,
        attend_tot=overall)

    c_text = msgs[lang]['confirm']['kick'].format(user.name)

    markup = mkp.create(lang, [
        cbt.confirm_action('kick',
                           msgs[lang]['buttons']['confirm']['kick'],
                           c_text,
                           call.message.chat.id,
                           call.message.message_id,
                           c_id=call.data['c_id'],
                           u_id=call.data['u_id'])
    ])

    botHelper.edit_mes(text, call, markup=markup)
Ejemplo n.º 5
0
def course(call, lang):
    course_ = Course.Course(call.data['c_id'])
    num_par = len(course_.participants)
    owner = course_.owner

    if owner.id == call.message.chat.id:  # owner
        if course_.is_open:
            lock = msgs[lang]['teacher']['lock_open']
        else:
            lock = msgs[lang]['teacher']['lock_close']
        desc = course_.description
        if len(desc) > UI.constants.COURSE_INFO_DESC_LENGTH:
            desc = botHelper.remove_danger(
                desc[:UI.constants.COURSE_INFO_DESC_LENGTH]) + '...'

        botHelper.edit_mes(
            msgs[lang]['teacher']['course_owner_min'].format(name=course_.name,
                                                             num=num_par,
                                                             lock=lock,
                                                             desc=desc),
            call,
            markup=mkp.create(lang, [tbt.manage(call.data['c_id'], lang)]))
    elif course_.id in (c.id
                        for c in User.User(call.message.chat.id).participation
                        ):  # enrolled
        cws = course_.classworks
        attend_text = ''
        overall = len(cws)
        if overall:
            att = sum(
                map(lambda cw_: cw_.attendance(call.message.chat.id).value,
                    cws))
            attend_text = msgs[lang]['student']['attendance'].format(
                count=att, overall=overall, ratio=int(att / overall * 100))

        tasks = course_.tasks
        if tasks:
            total_mark = sum(
                map(lambda task_: task_.mark(call.message.chat.id).value,
                    tasks))
            mean_mark = total_mark / len(tasks)
            mark_text = msgs[lang]['student']['marks'].format(
                total_mark, round(mean_mark, 2))
        else:
            mark_text = ''

        text = msgs[lang]['student']['course'].format(name=course_.name,
                                                      fio=owner.name,
                                                      num=num_par,
                                                      mail='',
                                                      marks=mark_text,
                                                      attend=attend_text)

        c_text = msgs[lang]['confirm']['leave_course'].format(course_.name)
        if not course_.is_open:
            c_text += msgs[lang]['confirm']['leave_course_append']

        markup = mkp.create(lang, [cbt.task_list(call.data['c_id'], lang)], [
            cbt.confirm_action('leave',
                               msgs[lang]['buttons']['confirm']['leave'],
                               c_text,
                               call.message.chat.id,
                               call.message.message_id,
                               c_id=course_.id)
        ])

        botHelper.edit_mes(text, call, markup=markup)
    else:  # not enrolled
        locked = '' if course_.is_open else msgs[lang]['student'][
            'course_closed']
        end_entry = course_.entry_restriction
        lock = UI.to_dtime(
            end_entry) if end_entry else msgs[lang]['student']['lock_absent']

        text = msgs[lang]['student']['course_not_enroll'].format(
            name=course_.name,
            fio=owner.name,
            desc=course_.description,
            num=num_par,
            lock=lock,
            mail='',
            locked=locked)  # TODO mail

        c_text = msgs[lang]['confirm']['enroll_course'].format(course_.name)

        if locked:
            markup = mkp.create(lang)
        else:
            markup = mkp.create(lang, [
                cbt.confirm_action('enroll',
                                   msgs[lang]['buttons']['confirm']['enroll'],
                                   c_text,
                                   call.message.chat.id,
                                   call.message.message_id,
                                   c_id=course_.id)
            ])

        botHelper.edit_mes(text, call, markup=markup)