Example #1
0
def lesson_member(update, context):
    user = update.message.from_user
    logger.info("Start of %s: %s", user.first_name, update.message.text)
    today = datetime.now().date()
    group = Group.objects.filter(Q(first_date__date=today)
                                 | Q(second_date__date=today),
                                 teacher=user_obj(update))
    keyboard = KeyBoards()
    StudentsMarks.objects.create(
        student=Users.objects.get(first_name=update.message.text),
        group=group[0],
        date=today)
    slist = [
        i.student.first_name
        for i in StudentsMarks.objects.filter(group=group[0], date=today)
    ]
    print(slist)
    s_all = Students.objects.filter(group=group[0])
    for i in s_all:
        if i.student.first_name in slist:
            continue
        keyboard.addButton(i.student.first_name, one_row=True)

    if len(slist) == s_all.count():
        update.message.reply_text(
            'Все ученики отмечены\n/end для завершения занятия',
            reply_markup=ReplyKeyboardRemove())
        return LESSON_MEMBER

    update.message.reply_text(
        'Ученик {0} был отмечен\n/end для завершения занятия'.format(
            update.message.text),
        reply_markup=keyboard.getKeyboard())

    return LESSON_MEMBER
Example #2
0
def group_start(update, context):
    keyboard = KeyBoards()
    Group.objects.create(teacher=user_obj(update))
    for i in Level.objects.all():
        keyboard.addButton(i.level)
    update.message.reply_text('Пожалуйста укажите уровень группы',
                              reply_markup=keyboard.getKeyboard())
    return GROUP_LEVEL
Example #3
0
def my_trials(update, context):
    t_obj = Trial.objects.filter(teacher=user_obj(update))
    keyboard = KeyBoards()
    for i in t_obj:
        keyboard.addButton("/ted {0}".format(i), one_row=True)
    update.message.reply_text(
        'Список ваших пробных занятий\nНажмите на одну из них для редактирования',
        reply_markup=keyboard.getKeyboard())
    return True
Example #4
0
def trial_start(update, context):
    if user_obj(update).role != 2:
        return None
    keyboard = KeyBoards()
    for i in Age.objects.all():
        keyboard.addButton(i.age)
    update.message.reply_text(
        'Пожалуйста укажите возрастную группу для пробного занятия',
        reply_markup=keyboard.getKeyboard())
    return TRIAL_AGE
Example #5
0
def age(update, context):
    user = update.message.from_user
    logger.info("Age of %s: %s", user.first_name, update.message.text)
    keyboard = KeyBoards()
    keyboard.addButton('Отправить номер телефона', request_contact=True)
    update.message.reply_text(
        'Замечательно! Сейчас, отправьте мне ваш контакт.',
        reply_markup=keyboard.getKeyboard())
    u = user_obj(update)
    u.age = Age.objects.get(age=update.message.text)
    u.save()
    return PHONE
Example #6
0
def name(update, context):
    keyboard = KeyBoards()
    for i in Age.objects.all():
        keyboard.addButton(i.age)
    user = update.message.from_user
    logger.info("Name of %s: %s", user.first_name, update.message.text)
    update.message.reply_text(
        'Отлично! Теперь нам необходимо знать возраст нашего нового ученика!',
        reply_markup=keyboard.getKeyboard())
    u = user_obj(update)
    u.first_name = update.message.text
    u.save()
    return AGE
Example #7
0
def group_name(update, context):
    user = update.message.from_user
    logger.info("Name of %s: %s", user.first_name, update.message.text)
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    t_obj.name = update.message.text
    t_obj.save()
    #GROUP_DATA['name'] = update.message.text
    keyboard = KeyBoards()
    for i in days:
        keyboard.addButton(i)
    update.message.reply_text('Отлично! Теперь выберите первый день занятия',
                              reply_markup=keyboard.getKeyboard())
    return GROUP_DAYS_ONE
Example #8
0
def phone(update, context):
    user = update.message.from_user
    logger.info("Phone of %s: %s", user.first_name, update.message.text)
    keyboard = KeyBoards()
    for i in Trial.objects.filter(status=True):
        keyboard.addButton('{0}'.format(i.date), one_row=True)

    update.message.reply_text(
        'Замечательно! Теперь осталось выбрать подходящее время для пробного занятия.',
        reply_markup=keyboard.getKeyboard())
    u = user_obj(update)
    u.phone = update.message.contact.phone_number
    u.save()
    return GROUP
Example #9
0
def group_days_one(update, context):
    user = update.message.from_user
    logger.info("Days of %s: %s", user.first_name, update.message.text)
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    t_obj.first_date = get_date(update.message.text)
    t_obj.save()
    #GROUP_DATA['date_one'] = update.message.text
    keyboard = KeyBoards()
    for i in days:
        if i == update.message.text:
            continue
        keyboard.addButton(i)
    update.message.reply_text('А теперь второй день занятия',
                              reply_markup=keyboard.getKeyboard())
    return GROUP_DAYS_TWO
Example #10
0
def trial_age(update, context):
    user = update.message.from_user
    if user_obj(update).role != 2:
        return None
    logger.info("Trial Age of %s: %s", user.first_name, update.message.text)
    keyboard = KeyBoards()
    for i in range(8):
        keyboard.addButton('{0}'.format(date.today() + timedelta(days=i)),
                           one_row=True)
    update.message.reply_text(
        'Замечательно! Теперь осталось выбрать дату для пробного занятия.',
        reply_markup=keyboard.getKeyboard())
    Trial.objects.create(teacher=user_obj(update),
                         age=Age.objects.get(age=update.message.text))
    return TRIAL_DATE
Example #11
0
def group_days_two(update, context):
    user = update.message.from_user
    logger.info("Days of %s: %s", user.first_name, update.message.text)
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    t_obj.second_date = get_date(update.message.text)
    t_obj.save()
    #GROUP_DATA['date_two'] = update.message.text
    keyboard = KeyBoards()
    for i in range(8, 20):
        '''
        if i < time.localtime().tm_hour:
            continue
        '''
        keyboard.addButton('{0}:00'.format(i), one_row=True)
    update.message.reply_text('Укажите время для первого',
                              reply_markup=keyboard.getKeyboard())
    return GROUP_TIMES_ONE
Example #12
0
def trial_date(update, context):
    user = update.message.from_user
    logger.info("Trial Date of %s: %s", user.first_name, update.message.text)
    t_obj = Trial.objects.filter(teacher=user_obj(update)).last()
    t_obj.date = update.message.text
    t_obj.save()
    keyboard = KeyBoards()
    for i in range(8, 20):
        '''
        if i < time.localtime().tm_hour:
            continue
        '''
        keyboard.addButton('{0}:00'.format(i), one_row=True)
    update.message.reply_text(
        'Замечательно! Теперь осталось выбрать время для пробного занятия.',
        reply_markup=keyboard.getKeyboard())
    return TRIAL_TIME
Example #13
0
def begin_lesson(update, context):
    user = update.message.from_user
    logger.info("Start of %s: %s", user.first_name, update.message.text)
    group = Group.objects.filter(Q(first_date__date=datetime.now().date())
                                 | Q(second_date__date=datetime.now().date()),
                                 teacher=user_obj(update))
    if group.count() < 1:
        update.message.reply_text('Сегодня у вас нет занятий',
                                  reply_markup=ReplyKeyboardRemove())
        table(update, context)
        return False
    keyboard = KeyBoards()
    for i in Students.objects.filter(group=group[0]):
        keyboard.addButton(i.student.first_name, one_row=True)
    update.message.reply_text(
        'Пожалуйста, отметьте учеников, присутствующих на занятии\n/end для завершения занятия',
        reply_markup=keyboard.getKeyboard())
    print(TEMP_DATA)
    return LESSON_MEMBER
Example #14
0
def group_times_one(update, context):
    user = update.message.from_user
    logger.info("Times of %s: %s", user.first_name, update.message.text)
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    t_obj.first_date = datetime(year=t_obj.first_date.year,
                                month=t_obj.first_date.month,
                                day=t_obj.first_date.day,
                                hour=int(update.message.text.split(':')[0]))
    t_obj.save()
    #GROUP_DATA['time_one'] = update.message.text
    keyboard = KeyBoards()
    for i in range(8, 20):
        '''
        if i < time.localtime().tm_hour:
            continue
        '''
        keyboard.addButton('{0}:00'.format(i), one_row=True)
    update.message.reply_text('Укажите время для второго',
                              reply_markup=keyboard.getKeyboard())
    return GROUP_TIMES_TWO
Example #15
0
def group_times_two(update, context):
    user = update.message.from_user
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    t_obj.second_date = datetime(year=t_obj.second_date.year,
                                 month=t_obj.second_date.month,
                                 day=t_obj.second_date.day,
                                 hour=int(update.message.text.split(':')[0]))
    t_obj.save()
    #GROUP_DATA['time_two'] = update.message.text
    #memlist.append(user.id)
    #GROUP_DATA['members'] = []

    logger.info("Times of %s: %s", user.first_name, update.message.text)
    keyboard = KeyBoards()
    for i in TrialGroups.objects.filter(trial__teacher=user_obj(update),
                                        status=False):
        keyboard.addButton(i.student.first_name, one_row=True)
    update.message.reply_text('Теперь осталось добавить учеников в группу',
                              reply_markup=keyboard.getKeyboard())

    return GROUP_MEMBERS
Example #16
0
def group_members(update, context):
    user = update.message.from_user
    logger.info("Times of %s: %s", user.first_name, update.message.text)
    #excluded.append(update.message.text)
    GROUP_DATA['members'].append(update.message.text)
    user = TrialGroups.objects.get(
        student=Users.objects.get(first_name=update.message.text),
        status=False,
        trial__teacher=user_obj(update))
    user.status = True
    user.save()
    t_obj = Group.objects.filter(teacher=user_obj(update)).last()
    student = Students.objects.create(student=user.student,
                                      group=t_obj,
                                      start_date=t_obj.first_date,
                                      end_date=t_obj.second_date)
    keyboard = KeyBoards()
    trial_count = TrialGroups.objects.filter(
        status=False, trial__teacher=user_obj(update)).count()
    if trial_count > 1:
        for i in TrialGroups.objects.filter(trial__teacher=user_obj(update),
                                            status=False):
            keyboard.addButton("{0} {1}".format(i.student.first_name,
                                                i.student.phone),
                               one_row=True)
        update.message.reply_text(
            'Добавьте еще одного или введите /stop для завершения',
            reply_markup=keyboard.getKeyboard())
    else:
        update.message.reply_text('Ученики закончились введите /stop',
                                  reply_markup=ReplyKeyboardRemove())

    if Students.objects.filter(group=t_obj).count() == 10:
        sendInfo(update, context)
        update.message.reply_text('Отлично! Группа сформирована {0}'.format(
            str(GROUP_DATA)),
                                  reply_markup=ReplyKeyboardRemove())
        return ConversationHandler.END
    return GROUP_MEMBERS