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