XH_Digital_Management/application/fin_tbl/views.py

52 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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