Exemplo n.º 1
0
 def payment_to_dump(payment):
     return {
         'id': payment.id,
         'month': get_month_name(payment.month),
         'value': payment.value,
         'cash': payment.cash,
         'confirmed': payment.confirmed,
         'comment': payment.comment,
     }
Exemplo n.º 2
0
def format_monthly_stats_to_list(historical_stats):
    return sorted(
        (dict(
            date=key,
            future=yyyy_mm_to_datetime(key) > datetime.utcnow(),
            name=get_month_name(key),
            **aggregate_status_types(value),
        ) for key, value in historical_stats.items()),
        key=lambda x: x["date"],
        reverse=True,
    )
Exemplo n.º 3
0
def months_list(group_id):
    group = Group.query.get_or_404(group_id)
    dates_of_lessons = dates_of_lessons_dict(group_id)
    months = [{
        'month_number': month_number,
        'month_name': get_month_name(month_number),
        'lessons_dates': dates_of_lessons.get(month_number)
    } for month_number in range(group.start_month, group.end_month + 1)]
    return render_template('lessons/months_list.html',
                           group=group,
                           months=months)
Exemplo n.º 4
0
def group_stat(group_id):
    group = Group.query.get_or_404(group_id)
    students_by_month = group_students_count_by_month_dict(group_id)
    pays_by_month = group_payments_count_by_month_dict(group_id)
    pays_confirmed_by_month = group_payments_confirmed_count_by_month_dict(group_id)
    attendings_percent_by_month = group_attendings_percent_by_month_dict(group_id)
    months = [{'month_number': month_number, 'month_name': get_month_name(month_number),
               'students_count': students_by_month.get(month_number),
               'lessons_count': Lesson.lessons_in_group_in_month(group_id, month_number).count(),
               'attendings_percent': attendings_percent_by_month.get(month_number, 0),
               'payments': pays_by_month.get(month_number, 0),
               'payments_confirmed': pays_confirmed_by_month.get(month_number, 0)}
              for month_number in range(group.start_month, group.end_month + 1)]
    return render_template('stat/group.html', group=group, months=months)
Exemplo n.º 5
0
def check_db_integrity():
    problems = list()

    for master in Master.query.all():
        if master.system_user.system_role.name != role_master_name:
            problems.append(
                'у мастера id={} ({}) неверная системная роль'.format(
                    master.id, master.fio))
    for teacher in Teacher.query.all():
        if teacher.system_user.system_role.name != role_teacher_name:
            problems.append(
                'у учителя id={} ({}) неверная системная роль'.format(
                    teacher.id, teacher.fio))
    for student in Student.query.all():
        if student.system_user.system_role.name != role_student_name:
            problems.append(
                'у ученика id={} ({}) неверная системная роль'.format(
                    student.id, student.fio))
    for bot in Bot.query.all():
        if bot.system_user.system_role.name != role_bot_name:
            problems.append('у бота id={} ({}) неверная системная роль'.format(
                bot.id, bot.fio))
    for developer in Developer.query.all():
        if developer.system_user.system_role.name != role_developer_name:
            problems.append(
                'у разработчика id={} ({}) неверная системная роль'.format(
                    developer.id, developer.fio))

    system_role_id_master = SystemRole.query.filter(
        SystemRole.name == role_master_name).first().id
    system_role_id_teacher = SystemRole.query.filter(
        SystemRole.name == role_teacher_name).first().id
    system_role_id_student = SystemRole.query.filter(
        SystemRole.name == role_student_name).first().id
    system_role_id_bot = SystemRole.query.filter(
        SystemRole.name == role_bot_name).first().id
    system_role_id_developer = SystemRole.query.filter(
        SystemRole.name == role_developer_name).first().id

    if SystemUser.query.filter(
            SystemUser.system_role_id ==
            system_role_id_master).count() != Master.query.count():
        problems.append('неверное кол-во мастеров')
    if SystemUser.query.filter(
            SystemUser.system_role_id ==
            system_role_id_teacher).count() != Teacher.query.count():
        problems.append('неверное кол-во учителей')
    if SystemUser.query.filter(
            SystemUser.system_role_id ==
            system_role_id_student).count() != Student.query.count():
        problems.append('неверное кол-во учеников')
    if SystemUser.query.filter(SystemUser.system_role_id == system_role_id_bot
                               ).count() != Bot.query.count():
        problems.append('неверное кол-во ботов')
    if SystemUser.query \
            .filter(SystemUser.system_role_id == system_role_id_developer).count() != Developer.query.count():
        problems.append('неверное кол-во разработчиков')

    if SystemUser.query.count() != Master.query.count() + Teacher.query.count() + Student.query.count() \
            + Bot.query.count() + Developer.query.count():
        problems.append(
            'кол-во системных пользователей не равно кол-ву пользователей')

    for group in Group.query.all():
        if group.start_month > group.end_month:
            problems.append('группа id={} ({}) - конец раньше начала'.format(
                group.id, group.name))
        if group.end_month - group.start_month >= 12:
            problems.append(
                'группа id={} ({}) функционирует больше 12 месяцев'.format(
                    group.id, group.name))
        start_date = start_date_of_month(group.start_month)
        end_date = end_date_of_month(group.end_month)
        for lesson in group.lessons.all():
            if lesson.date < start_date or lesson.date > end_date:
                problems.append(
                    'занятие id={} ({} / {}) выходит за рамки функционирования группы'
                    .format(lesson.id, group.name, lesson.date))
            for attending in lesson.attendings.all():
                if attending.state not in attending_states:
                    problems.append(
                        'неизвестный статус посещения id={} ({} / {} / {})'.
                        format(attending.id, attending.student.fio,
                               attending.lesson.date, group.name))
        for student_in_group in group.students_in_group.all():
            if student_in_group.enter_month < group.start_month or student_in_group.exit_month > group.end_month \
                    or student_in_group.enter_month > student_in_group.exit_month:
                problems.append(
                    'ученик в группе id={} ({} / {}) выходит за рамки функционирования группы'
                    .format(student_in_group.id, student_in_group.student.fio,
                            group.name))
            for payment in student_in_group.payments.all():
                if payment.month < student_in_group.enter_month or payment.month > student_in_group.exit_month:
                    problems.append(
                        'платеж id={} ({} / {} / {}) выходит за рамки нахождения ученика в группе'
                        .format(payment.id, group.name,
                                student_in_group.student.fio,
                                get_month_name(payment.month)))
                if payment.value < 0 or payment.value > payment.max_value:
                    problems.append(
                        'неверная сумма платежа id={} ({} / {} / {})'.format(
                            payment.id, group.name,
                            student_in_group.student.fio,
                            get_month_name(payment.month)))
    notification_types_overflow = 1
    for i in range(0, len(notification_types_list)):
        notification_types_overflow <<= 1
    for parent in Parent.query.all():
        if parent.notification_types < 0 or parent.notification_types >= notification_types_overflow:
            problems.append(
                'у родителя id={} неверные типы уведомлений: {}'.format(
                    parent.id, parent.notification_types))

    return render_template('check_db_integrity.html', problems=problems)
Exemplo n.º 6
0
def lessons_in_month(group_id, month_number):
    group = Group.query.get_or_404(group_id)
    if month_number < group.start_month or month_number > group.end_month:
        abort(404)
    month_name = get_month_name(month_number)
    students_in_group = group.students_in_group_in_month(month_number) \
        .join(Student, Student.id == StudentInGroup.student_id) \
        .order_by(Student.fio) \
        .all()
    if 'submit' in request.form:
        if not can_user_write_group(current_user, group): abort(403)
        ls = Lesson.lessons_in_group_in_month(group_id, month_number).all()
        ps = Payment.query \
            .join(StudentInGroup, StudentInGroup.id == Payment.student_in_group_id) \
            .filter(StudentInGroup.group_id == group_id, Payment.month == month_number)
        payments = dict()
        for p in ps:
            payments[p.student_in_group_id] = p
        for student_in_group in students_in_group:
            new_value = request.form.get('p_{}'.format(student_in_group.id),
                                         0,
                                         type=int)
            if new_value < 0: new_value = 0
            max_value = group.section.price - student_in_group.discount
            if new_value > max_value: new_value = max_value
            payment = payments.get(student_in_group.id)
            is_cash = 'c_{}'.format(student_in_group.id) in request.form
            comment = request.form.get(
                'comment_{}'.format(student_in_group.id), '')
            if payment is not None:
                if not payment.confirmed:
                    payment.value = new_value
                    payment.cash = is_cash
                    payment.comment = comment
            else:
                db.session.add(
                    Payment(student_in_group=student_in_group,
                            month=month_number,
                            value=new_value,
                            cash=is_cash,
                            comment=comment))
            attendings = dict()
            for l in ls:
                attendings[l.id] = dict()
                for a in l.attendings:
                    attendings[l.id][a.student_id] = a
            for l in ls:
                attending = attendings[l.id].get(student_in_group.student_id)
                a_key = 'a_{}_{}'.format(l.id, student_in_group.student_id)
                new_state = request.form.get(a_key,
                                             attending_was_not,
                                             type=int)
                if attending is not None:
                    attending.state = new_state
                else:
                    db.session.add(
                        Attending(lesson=l,
                                  student=student_in_group.student,
                                  state=new_state))
        flash('посещения и оплата в группе {} за {} сохранены.'.format(
            group.name, month_name))
        return redirect(
            url_for('lessons.lessons_in_month',
                    group_id=group_id,
                    month_number=month_number))
    pd = payments_in_month_info(group_id, month_number)
    ll = lessons_lists(group_id, month_number)
    return render_template('lessons/lessons_in_month.html',
                           group=group,
                           month_number=month_number,
                           month_name=month_name,
                           students_in_group=students_in_group,
                           payments=pd.values,
                           confirmed=pd.confirmed,
                           cash=pd.cash,
                           comments=pd.comments,
                           lessons=ll[0],
                           attendings_states=ll[1],
                           write_mode=can_user_write_group(
                               current_user, group))