修改了员工基本信息的查看、新增、修改视图方法
This commit is contained in:
parent
a803e1c37c
commit
5510d567ba
|
@ -49,17 +49,13 @@ def emp_list_view(request):
|
||||||
|
|
||||||
# 构建上下文
|
# 构建上下文
|
||||||
context = {
|
context = {
|
||||||
# 模型设置
|
|
||||||
"model_config": "hrm_mgnt.EmployeeInformation",
|
"model_config": "hrm_mgnt.EmployeeInformation",
|
||||||
# 分页数据
|
|
||||||
"items": items,
|
"items": items,
|
||||||
# 面包屑
|
|
||||||
"breadcrumb_list": [
|
"breadcrumb_list": [
|
||||||
{"title": "首页", "name": "index"},
|
{"title": "首页", "name": "index"},
|
||||||
{"title": "人力资源管理", "name": "index"},
|
{"title": "人力资源管理", "name": "index"},
|
||||||
{"title": "人员基本信息表", "name": "emt_list"}
|
{"title": "人员基本信息表", "name": "emt_list"}
|
||||||
],
|
],
|
||||||
# 筛选表单选项
|
|
||||||
"filters": [
|
"filters": [
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -82,24 +78,17 @@ def emp_list_view(request):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
# Excel上传解析
|
|
||||||
"excel_upload_config": {
|
"excel_upload_config": {
|
||||||
"template_name": template_name,
|
"template_name": template_name,
|
||||||
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
|
"template_url": reverse("dl_excel_tpl", kwargs={'template_name': template_name}),
|
||||||
"parse_url": reverse("ep_common_parse"),
|
"parse_url": reverse("ep_common_parse"),
|
||||||
"save_url": reverse("save_excel_table_data")
|
"save_url": reverse("save_excel_table_data")
|
||||||
},
|
},
|
||||||
# 上下文查询参数
|
|
||||||
"query_params": query_params,
|
"query_params": query_params,
|
||||||
# 表格显示排除配置
|
|
||||||
"table_exclude_field_name": ['employee_id'],
|
"table_exclude_field_name": ['employee_id'],
|
||||||
# 筛选表单提交链接
|
"form_action_url": reverse("emp_list"),
|
||||||
"form_action_url": "emp_list",
|
|
||||||
# 修改对象提交链接
|
|
||||||
"modify_url": reverse("emp_list_modify"),
|
"modify_url": reverse("emp_list_modify"),
|
||||||
# 新增对象提交链接
|
|
||||||
"add_url": reverse("emp_list_add"),
|
"add_url": reverse("emp_list_add"),
|
||||||
# 删除对象提交链接
|
|
||||||
"delete_url": reverse("emp_list_delete"),
|
"delete_url": reverse("emp_list_delete"),
|
||||||
"add_button": True,
|
"add_button": True,
|
||||||
}
|
}
|
||||||
|
@ -113,7 +102,7 @@ def emp_list_add(request):
|
||||||
基础数据-人力资源管理-人员基本信息表-新增视图
|
基础数据-人力资源管理-人员基本信息表-新增视图
|
||||||
"""
|
"""
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = EmployeeInformationAddForm(request.POST)
|
form = EmployeeInformationForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
return JsonResponse({"message": "添加成功"})
|
return JsonResponse({"message": "添加成功"})
|
||||||
|
@ -121,7 +110,7 @@ def emp_list_add(request):
|
||||||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||||||
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
||||||
elif request.method == 'GET':
|
elif request.method == 'GET':
|
||||||
form = EmployeeInformationAddForm()
|
form = EmployeeInformationForm()
|
||||||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||||||
return JsonResponse({"form_html": form_html})
|
return JsonResponse({"form_html": form_html})
|
||||||
else:
|
else:
|
||||||
|
@ -139,9 +128,9 @@ def emp_list_modify(request):
|
||||||
if 'id' in request.POST:
|
if 'id' in request.POST:
|
||||||
instance = EmployeeInformation.objects.get(employee_id=request.POST['id'])
|
instance = EmployeeInformation.objects.get(employee_id=request.POST['id'])
|
||||||
current_base_salary = instance.base_salary # 获取当前基本工资
|
current_base_salary = instance.base_salary # 获取当前基本工资
|
||||||
form = EmployeeInformationEditForm(request.POST, instance=instance)
|
form = EmployeeInformationForm(request.POST, instance=instance)
|
||||||
else:
|
else:
|
||||||
form = EmployeeInformationEditForm(request.POST)
|
form = EmployeeInformationForm(request.POST)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
employee = form.save()
|
employee = form.save()
|
||||||
|
@ -170,12 +159,12 @@ def emp_list_modify(request):
|
||||||
if 'id' in request.GET:
|
if 'id' in request.GET:
|
||||||
try:
|
try:
|
||||||
instance = EmployeeInformation.objects.get(employee_id=request.GET['id'])
|
instance = EmployeeInformation.objects.get(employee_id=request.GET['id'])
|
||||||
form = EmployeeInformationEditForm(instance=instance)
|
form = EmployeeInformationForm(instance=instance)
|
||||||
form.fields['secondary_department'].queryset = SecondaryDepartment.objects.filter(primary_department=instance.primary_department).order_by('secondary_department_name')
|
form.fields['secondary_department'].choices = [(dept.secondary_department_name, dept.secondary_department_name) for dept in SecondaryDepartment.objects.filter(primary_department__department_name=instance.primary_department)]
|
||||||
except EmployeeInformation.DoesNotExist:
|
except EmployeeInformation.DoesNotExist:
|
||||||
raise Http404("对象不存在")
|
raise Http404("对象不存在")
|
||||||
else:
|
else:
|
||||||
form = EmployeeInformationEditForm()
|
form = EmployeeInformationForm()
|
||||||
|
|
||||||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||||||
return JsonResponse({"form_html": form_html})
|
return JsonResponse({"form_html": form_html})
|
||||||
|
|
Loading…
Reference in New Issue