from django.http import JsonResponse, Http404 from django.shortcuts import render, get_object_or_404, redirect from django.template.loader import render_to_string from django.urls import reverse from common.utils.page_helper import paginate_query_and_assign_numbers from .forms import * from .models import * def seal_reg_list_view(request): query_set = SealUsageRegistry.objects.filter().order_by('-record_id') applicant = request.GET.get('applicant', '') if applicant: query_set = query_set.filter(applicant__icontains=applicant) items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10) query_params = '&applicant={}'.format(applicant) template_name = "合规管理-用印登记表-Excel上传模板.xlsx" context = { "model_config": 'cpc_mgnt.SealUsageRegistry', "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "合规管理", "name": "index"}, {"title": "用印登记表", "name": "seal_reg_list"} ], "filters": [ {"type": "text", "id": "applicant", "name": "applicant", "label": "申请人", "placeholder": "请输入申请人"} ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "record_id": {"type": "text", "width": "180px"}, "applicant": {"type": "text", "width": "180px"}, "seal_date": {"type": "date", "width": "110px"}, "seal_entity": {"type": "text", "width": "180px"}, "seal_type": {"type": "text", "width": "180px"}, "document_name": {"type": "text", "width": "180px"}, "number_of_copies": {"type": "number", "width": "100px"}, "handler": {"type": "text", "width": "180px"}, "actions": {"type": "actions", "width": "100px"} } }, "query_params": query_params, "form_action_url": 'seal_reg_list', "modify_url": reverse("seal_reg_list_modify"), "add_url": reverse("seal_reg_list_add"), "delete_url": reverse("seal_reg_list_delete"), "table_exclude_field_name": [], # Add any fields you want to exclude } return render(request, 'items_list.html', context) def seal_reg_list_add(request): if request.method == 'POST': form = SealUsageRegistryForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "添加成功"}) else: 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 = SealUsageRegistryForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def seal_reg_list_modify(request): if request.method == 'POST': if 'record_id' in request.POST: instance = SealUsageRegistry.objects.get(record_id=request.POST['record_id']) form = SealUsageRegistryForm(request.POST, instance=instance) else: form = SealUsageRegistryForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "保存成功"}) else: 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': if 'record_id' in request.GET: try: instance = SealUsageRegistry.objects.get(record_id=request.GET['record_id']) form = SealUsageRegistryForm(instance=instance) except SealUsageRegistry.DoesNotExist: raise Http404("对象不存在") else: form = SealUsageRegistryForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def seal_reg_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') SealUsageRegistry.objects.filter(record_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def seal_doc_borrow_list_view(request): query_set = SealAndDocumentBorrowingRegistry.objects.filter().order_by('-record_id') entity_name = request.GET.get('entity_name', '') if entity_name: query_set = query_set.filter(entity_name__icontains=entity_name) items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10) query_params = '&entity_name={}'.format(entity_name) template_name = "合规管理-印章证件借用登记表-Excel上传模板.xlsx" context = { "model_config": 'cpc_mgnt.SealAndDocumentBorrowingRegistry', "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "合规管理", "name": "index"}, {"title": "印章证件借用登记表", "name": "seal_doc_borrow_list"} ], "filters": [ {"type": "text", "id": "entity_name", "name": "entity_name", "label": "主体名称", "placeholder": "请输入主体名称"} ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "record_id": {"type": "text", "width": "180px"}, "entity_name": {"type": "text", "width": "180px"}, "item_type": {"type": "text", "width": "180px"}, "purpose": {"type": "text", "width": "180px"}, "borrower": {"type": "text", "width": "180px"}, "borrowing_time": {"type": "datetime", "width": "180px"}, "expected_return_date": {"type": "date", "width": "110px"}, "lender": {"type": "text", "width": "180px"}, "returnee": {"type": "text", "width": "180px"}, "return_date": {"type": "date", "width": "110px"}, "verifier": {"type": "text", "width": "180px"}, "actions": {"type": "actions", "width": "100px"} } }, "query_params": query_params, "form_action_url": 'seal_doc_borrow_list', "modify_url": reverse("seal_doc_borrow_list_modify"), "add_url": reverse("seal_doc_borrow_list_add"), "delete_url": reverse("seal_doc_borrow_list_delete"), "table_exclude_field_name": [], # Add any fields you want to exclude } return render(request, 'items_list.html', context) def seal_doc_borrow_list_add(request): if request.method == 'POST': form = SealAndDocumentBorrowingRegistryForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "添加成功"}) else: 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 = SealAndDocumentBorrowingRegistryForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def seal_doc_borrow_list_modify(request): if request.method == 'POST': if 'record_id' in request.POST: instance = SealAndDocumentBorrowingRegistry.objects.get(record_id=request.POST['record_id']) form = SealAndDocumentBorrowingRegistryForm(request.POST, instance=instance) else: form = SealAndDocumentBorrowingRegistryForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "保存成功"}) else: 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': if 'record_id' in request.GET: try: instance = SealAndDocumentBorrowingRegistry.objects.get(record_id=request.GET['record_id']) form = SealAndDocumentBorrowingRegistryForm(instance=instance) except SealAndDocumentBorrowingRegistry.DoesNotExist: raise Http404("对象不存在") else: form = SealAndDocumentBorrowingRegistryForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def seal_doc_borrow_list_delete(request): if request.method == 'GET': target_id = request.GET.get('target_id') SealAndDocumentBorrowingRegistry.objects.filter(record_id=target_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def contract_mgmt_list_view(request): # 声明查询集 query_set = ContractManagementLedger.objects.filter().order_by('-contract_number') # 获取查询参数 project_name = request.GET.get('project_name', '') # 根据提供的参数进行筛选 if project_name: query_set = query_set.filter(project_name__icontains=project_name) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&project_name={}'.format(project_name) # Excel上传模板 template_name = "合规管理-合同管理台账-Excel上传模板.xlsx" # 构建上下文 context = { "model_config": 'cpc_mgnt.ContractManagementLedger', "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "合规管理", "name": "index"}, {"title": "合同管理台账", "name": "contract_mgmt_list"} ], "filters": [ {"type": "text", "id": "project_name", "name": "project_name", "label": "项目名称", "placeholder": "请输入项目名称"} ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "project_name": {"type": "text", "width": "180px"}, "contract_number": {"type": "text", "width": "180px"}, "contract_name": {"type": "text", "width": "180px"}, "primary_department": {"type": "text", "width": "180px"}, "project_leader": {"type": "text", "width": "180px"}, "project_progress": {"type": "text", "width": "180px"}, "contract_status": {"type": "select", "width": "180px"}, "contract_type": {"type": "select", "width": "180px"}, "business_type": {"type": "text", "width": "180px"}, "number_of_copies": {"type": "number", "width": "100px"}, "cost_agreement": {"type": "text", "width": "180px"}, "review_date": {"type": "date", "width": "110px"}, "signing_date": {"type": "date", "width": "110px"}, "effective_date": {"type": "date", "width": "110px"}, "expiration_date": {"type": "date", "width": "110px"}, "our_side": {"type": "text", "width": "180px"}, "other_side": {"type": "text", "width": "180px"}, "submitter_for_review": {"type": "text", "width": "180px"}, "custodian_of_original": {"type": "text", "width": "180px"}, "payment_agreement_needed": {"type": "boolean", "width": "100px"}, "signed": {"type": "boolean", "width": "100px"}, "backup_location": {"type": "text", "width": "180px"}, "notes": {"type": "text", "width": "180px"}, "actions": {"type": "actions", "width": "100px"} } }, "query_params": query_params, "form_action_url": 'contract_mgmt_list', "modify_url": reverse("contract_mgmt_list_modify"), "add_url": reverse("contract_mgmt_list_add"), "delete_url": reverse("contract_mgmt_list_delete"), "table_exclude_field_name": ['contract_number'], # Exclude primary key } return render(request, 'items_list.html', context) def contract_mgmt_list_add(request): if request.method == 'POST': form = ContractManagementLedgerForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "添加成功"}) else: 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 = ContractManagementLedgerForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def contract_mgmt_list_modify(request): if request.method == 'POST': if 'contract_number' in request.POST: instance = ContractManagementLedger.objects.get(contract_number=request.POST['contract_number']) form = ContractManagementLedgerForm(request.POST, instance=instance) else: form = ContractManagementLedgerForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "保存成功"}) else: 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': if 'contract_number' in request.GET: try: instance = ContractManagementLedger.objects.get(contract_number=request.GET['contract_number']) form = ContractManagementLedgerForm(instance=instance) except ContractManagementLedger.DoesNotExist: raise Http404("对象不存在") else: form = ContractManagementLedgerForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def contract_mgmt_list_delete(request): if request.method == 'GET': contract_number = request.GET.get('contract_number') ContractManagementLedger.objects.filter(contract_number=contract_number).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def policies_list_view(request): # 声明查询集 query_set = CompanyPolicies.objects.filter().order_by('-policy_id') # 获取查询参数 policy_name = request.GET.get('policy_name', '') # 根据提供的参数进行筛选 if policy_name: query_set = query_set.filter(policy_name__icontains=policy_name) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&policy_name={}'.format(policy_name) # Excel上传模板 template_name = "合规管理-公司制度表-Excel上传模板.xlsx" # 构建上下文 context = { "model_config": 'cpc_mgnt.CompanyPolicies', "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "合规管理", "name": "index"}, {"title": "公司制度表", "name": "policies_list"} ], "filters": [ {"type": "text", "id": "policy_name", "name": "policy_name", "label": "制度名称", "placeholder": "请输入制度名称"} ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "policy_id": {"type": "text", "width": "180px"}, "issuing_unit": {"type": "text", "width": "180px"}, "policy_category": {"type": "select", "width": "180px"}, "policy_name": {"type": "text", "width": "180px"}, "version": {"type": "text", "width": "180px"}, "publication_date": {"type": "date", "width": "110px"}, "effective_date": {"type": "date", "width": "110px"}, "status": {"type": "select", "width": "180px"}, "actions": {"type": "actions", "width": "100px"} } }, "query_params": query_params, "form_action_url": 'policies_list', "modify_url": reverse("policies_list_modify"), "add_url": reverse("policies_list_add"), "delete_url": reverse("policies_list_delete"), "table_exclude_field_name": ['policy_id'], # Exclude primary key } return render(request, 'items_list.html', context) def policies_list_add(request): if request.method == 'POST': form = CompanyPoliciesForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "添加成功"}) else: 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 = CompanyPoliciesForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def policies_list_modify(request): if request.method == 'POST': if 'policy_id' in request.POST: instance = CompanyPolicies.objects.get(policy_id=request.POST['policy_id']) form = CompanyPoliciesForm(request.POST, instance=instance) else: form = CompanyPoliciesForm(request.POST) if form.is_valid(): form.save() return JsonResponse({"message": "保存成功"}) else: 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': if 'policy_id' in request.GET: try: instance = CompanyPolicies.objects.get(policy_id=request.GET['policy_id']) form = CompanyPoliciesForm(instance=instance) except CompanyPolicies.DoesNotExist: raise Http404("对象不存在") else: form = CompanyPoliciesForm() form_html = render_to_string('form_partial.html', {'form': form}, request) return JsonResponse({"form_html": form_html}) else: return JsonResponse({"message": "无效的请求方法"}, status=405) def policies_list_delete(request): if request.method == 'GET': policy_id = request.GET.get('policy_id') CompanyPolicies.objects.filter(policy_id=policy_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405)