Exemplo n.º 1
0
def index():
    user: db.User = g.user

    if user.is_authenticated:
        if user.status == Status.ready:
            return redirect(url_for('profile.bind_phone'))

        week_num, weekday = SyncCurrent.to_week_index(
        ), SyncCurrent.to_weekday()

        user: db.User = g.user

        current_day_courses: Dict[
            SectionId,
            List[db.Course]] = course_helper.Controller.course_schedule(
                [each.course for each in user.ref_courses],
                week_index=week_num,
                weekday=weekday)
        current_time_activities: 'List[Tuple[GroupId, db.Activity]]' = tuple(
            (each.group_id, each.activity) for each in flatten(
                each.group.ref_activitys for each in user.ref_groups)
            if each.is_active)
    else:
        flash('学生使用学号登录,老师使用工号后5位登录。初始密码与账号相同。')
        current_day_courses = {}
        current_time_activities = ()

    today = SyncCurrent.get_date()
    return render_template('index.html',
                           preview=make_index_preview(
                               current_time_activities,
                               current_day_courses).set_indent(1).__str__(),
                           user=user,
                           title='首页',
                           side_info=load_side_info(user),
                           side_options=load_side_options(),
                           toweek=DateHelper.to_week_index(today),
                           today=DateHelper.to_weekday(today),
                           funclist_ess=load_function_list())
Exemplo n.º 2
0
def stop(sign_name, qrcode, status):
    """开始签到跳转, 停止签到"""

    sign = RxTable(db.Sign).where(name=sign_name).first()

    if not sign:
        flash("实例不存在!")
        Config.app.logger.warning('{}'.format(sign_name))
        return redirect(url_for('attendance.center'))

    if not status:
        need_sign_num, actual_sign_num, sign_users, not_sign_users = sign_helper.Controller.statistics(sign)
        # 将签到信息记录置于redis中缓存
        if sign.cls == db.SignClass.course:
            cls = 'c'

            @curry
            def make_student_info(user: db.User, is_sign: int):
                stu = user.ref_students.first().student
                return dict(name=stu.name,
                            number=stu.number,
                            is_sign=is_sign)

            inst_id = sign.inst_id

            cache_storage.set(
                name_pattern(cls, inst_id, None, "week"),
                SyncCurrent.to_week_index()
            )

            cache_storage.hset(
                name_pattern(cls, inst_id, None, "values"),
                SyncCurrent.to_week_index(),
                json.dumps(dict(
                    应到=need_sign_num,
                    实到=actual_sign_num,
                    人员=[*RxList(sign_users)
                        .map(make_student_info(is_sign=1)),
                        *RxList(not_sign_users)
                        .map(make_student_info(is_sign=0))]
                ))
            )

        return render_template('attendance/stop.html',
                               sign_name=sign_name,
                               sign_code=sign.sign_code,
                               status=status,
                               need_sign_num=need_sign_num,  # 应到人数, int
                               actual_sign_num=actual_sign_num,  # 实到人数,int
                               sign_users=map(get_name_id, sign_users),  # 签到的用户, List[User]
                               not_sign_users=map(get_name_id, not_sign_users))  # 未签到的用户, List[User]

    if qrcode:
        return render_template('attendance/qrcode.html',
                               title="签到管理",
                               sign_name=sign_name,
                               status=status)

    return render_template('attendance/stop.html',
                           title="签到管理",
                           sign_name=sign_name,
                           sign_code=sign.sign_code,
                           status=status)
Exemplo n.º 3
0
def toweek_course_():
    return redirect(
        url_for('schedule.toweek_course',
                week_num=SyncCurrent.to_week_index()))