1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| @api.route('/gitCommit/find', methods=['GET', 'POST']) @login_required @cost_count def gitcommit_find(): data = request.json projectName = data.get('project_name') branchName = data.get('branch_name') commitMessage = data.get('title')
period = data.get('period')
time_start = period[0] if period else None time_end = period[1] if period else None page = data.get('page') if data.get('page') else 1 per_page = data.get('sizePage') if data.get('sizePage') else 20
''' 筛选的时候会遇到多个筛选条件,但都是非必填的 把存在的筛选条件添加到数组中,然后进行解包 最后把解包后的数据添加到筛选条件中 '''
filterList = [] if projectName is not None: filterList.append(GitCommits.project_name) if branchName is not None: filterList.append(GitCommits.branch_name) if commitMessage is not None: filterList.append(GitCommits.title.like('%' + commitMessage + '%')) if time_start is not None: filterList.append(time_start < GitCommits.create_at < time_end)
_data = GitCommits.query.filter(*filterList)
pagination = _data.order_by(GitCommits.create_at.desc()).paginate(page, per_page=per_page, error_out=False) _data = pagination.items total = pagination.total
end_data = [{'id':c.id, 'project_id': c.project_id, 'project_name': c.project_name, 'branch_name': c.branch_name, 'commit_message': c.title, 'author_name': c.author_name, 'create_at': c.create_at} for c in _data]
print(end_data) return jsonify({'data': end_data, 'total': total, 'status': 1})
|