51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
from django.shortcuts import render
|
||
from django.contrib.auth.decorators import login_required, permission_required
|
||
|
||
from common.utils.page_helper import paginate_query_and_assign_numbers
|
||
from .models import DepartmentExpenseData
|
||
|
||
|
||
@login_required
|
||
@permission_required('ops_tbl.view_departmentexpensedata', raise_exception=True)
|
||
def department_expense_data_list_view(request):
|
||
# 声明查询集
|
||
query_set = DepartmentExpenseData.objects.all().order_by('-year_month')
|
||
|
||
# 获取查询参数
|
||
year_month = request.GET.get('year_month', '')
|
||
primary_department = request.GET.get('primary_department', '')
|
||
|
||
# 根据提供的参数进行筛选
|
||
if year_month:
|
||
query_set = query_set.filter(year_month__icontains=year_month)
|
||
if primary_department:
|
||
query_set = query_set.filter(primary_department__icontains=primary_department)
|
||
|
||
# 对查询结果进行分页,每页10条记录
|
||
items = paginate_query_and_assign_numbers(
|
||
request=request,
|
||
queryset=query_set,
|
||
per_page=10
|
||
)
|
||
|
||
# 构建上下文查询参数字符串
|
||
query_params = '&year_month={}&primary_department={}'.format(year_month, primary_department)
|
||
|
||
# 准备上下文
|
||
context = {
|
||
'items': items,
|
||
'query_params': query_params,
|
||
'model_config': 'ops_tbl.DepartmentExpenseData',
|
||
'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "费用管理", "name": "index"},
|
||
{"title": "各部门费用情况", "name": "department_expense_data_list"}],
|
||
'filters': [
|
||
{"type": "text", "id": "year_month", "name": "year_month", "label": "年月", "placeholder": "请输入年月"},
|
||
{"type": "text", "id": "primary_department", "name": "primary_department", "label": "一级部门",
|
||
"placeholder": "请输入一级部门"}
|
||
],
|
||
"table_exclude_field_name": ['id'],
|
||
'form_action_url': 'department_expense_data_list'
|
||
}
|
||
|
||
return render(request, 'view_list.html', context)
|