示例#1
0
def get():
    form, error = JsonParser(
        Argument('page', type=int, default=1, required=False),
        Argument('pagesize', type=int, default=10, required=False),
        Argument('name', type=str, required=False),
    ).parse(request.args)

    if error is None:
        user = User.query.filter_by(is_supper=False)
        if form.name:
            user = user.filter(User.nickname.like('%{}%'.format(form.name)))
        total = user.count()
        users = []
        now_time = datetime.now()
        for item in user.limit(form.pagesize).offset(
            (form.page - 1) * form.pagesize).all():
            data = item.to_json(excludes=('password_hash', 'access_token',
                                          'token_expired'))
            if item.token_expired:
                data['last_login'] = human_diff_time(
                    now_time,
                    datetime.fromtimestamp(item.token_expired -
                                           8 * 60 * 60)) + '前'
            else:
                data['last_login'] = '******'
            users.append(data)
        return json_response({'data': users, 'total': total})
    return json_response(message=error)
示例#2
0
文件: job.py 项目: hy070111/prod
def get():
    form, error = JsonParser(
        Argument('page', type=int, default=1, required=False),
        Argument('pagesize', type=int, default=10, required=False),
        Argument('job_group', type=str, required=False),).parse(request.args)

    if error is None:
        if form.job_group:
            job = Job.query.filter_by(group=form.job_group).order_by(Job.enabled.desc())
        else:
            job = Job.query.order_by(Job.enabled.desc())

        total = job.count()
        job_data = job.limit(form.pagesize).offset((form.page - 1) * form.pagesize).all()
        jobs = [x.to_json() for x in job_data]
        now = datetime.now()
        for job in jobs:
            if not job['enabled']:
                job['next_run_time'] = '未启用'
            elif str(job['id']) in scheduler.jobs:
                next_run_time = scheduler.jobs[str(job['id'])].next_run_time
                if next_run_time is None:
                    job['next_run_time'] = '已过期'
                else:
                    job['next_run_time'] = human_diff_time(next_run_time.replace(tzinfo=None), now)
            elif job['trigger'] == 'date' and now > datetime.strptime(job['trigger_args'], '%Y-%m-%d %H:%M:%S'):
                job['next_run_time'] = '已过期'
            else:
                job['next_run_time'] = '异常'
        return json_response({'data': jobs, 'total': total})
    return json_response(message=error)