2024-06-07 03:47:15 +08:00
|
|
|
|
from django.http import JsonResponse, Http404
|
|
|
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
|
|
|
|
from django.template.loader import render_to_string
|
2024-06-06 15:08:38 +08:00
|
|
|
|
from django.urls import reverse
|
2024-05-15 18:41:23 +08:00
|
|
|
|
|
2024-06-07 14:20:58 +08:00
|
|
|
|
from application.mkt_mgnt.forms import CustomerForm, ProjectResourcesForm
|
2024-05-31 20:17:40 +08:00
|
|
|
|
from application.mkt_mgnt.models import *
|
|
|
|
|
from common.utils.page_helper import paginate_query_and_assign_numbers
|
2024-05-29 09:27:39 +08:00
|
|
|
|
|
|
|
|
|
|
2024-05-31 20:17:40 +08:00
|
|
|
|
def proj_res_list_view(request):
|
|
|
|
|
# 声明查询集
|
|
|
|
|
query_set = ProjectResources.objects.filter().order_by('-resource_id')
|
2024-05-29 09:27:39 +08:00
|
|
|
|
|
2024-05-31 20:17:40 +08:00
|
|
|
|
# 获取查询参数
|
|
|
|
|
name = request.GET.get('name', '')
|
|
|
|
|
unit = request.GET.get('unit', '')
|
|
|
|
|
resource_manager = request.GET.get('resource_manager', '')
|
|
|
|
|
|
|
|
|
|
# 根据提供的参数进行筛选
|
2024-06-06 15:08:38 +08:00
|
|
|
|
if name:
|
|
|
|
|
query_set = query_set.filter(name__icontains=name)
|
|
|
|
|
if unit:
|
|
|
|
|
query_set = query_set.filter(unit__icontains=unit)
|
|
|
|
|
if resource_manager:
|
|
|
|
|
query_set = query_set.filter(resource_manager__name__icontains=resource_manager)
|
2024-05-31 20:17:40 +08:00
|
|
|
|
|
|
|
|
|
# 对查询结果进行分页,每页10条记录
|
|
|
|
|
items = paginate_query_and_assign_numbers(
|
|
|
|
|
request=request,
|
|
|
|
|
queryset=query_set,
|
|
|
|
|
per_page=10
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 构建上下文查询参数字符串
|
2024-06-06 15:08:38 +08:00
|
|
|
|
query_params = '&name={}&unit={}&resource_manager={}'.format(name, unit, resource_manager)
|
|
|
|
|
|
2024-06-06 20:56:06 +08:00
|
|
|
|
# Excel上传模板
|
|
|
|
|
template_name = "营销管理-项目资源表-Excel上传模板.xlsx"
|
|
|
|
|
|
|
|
|
|
# 构建上下文
|
2024-05-31 20:17:40 +08:00
|
|
|
|
context = {
|
2024-06-06 20:56:06 +08:00
|
|
|
|
"model_config": 'mkt_mgnt.ProjectResources',
|
|
|
|
|
"items": items,
|
|
|
|
|
"breadcrumb_list": [
|
|
|
|
|
{"title": "首页", "name": "index"},
|
|
|
|
|
{"title": "营销管理", "name": "index"},
|
|
|
|
|
{"title": "项目资源表", "name": "proj_res_list"}
|
|
|
|
|
],
|
|
|
|
|
"filters": [
|
|
|
|
|
{"type": "text", "id": "name", "name": "name", "label": "姓名", "placeholder": "请输入姓名"},
|
|
|
|
|
{"type": "text", "id": "unit", "name": "unit", "label": "单位", "placeholder": "请输入单位"},
|
2024-06-07 03:47:15 +08:00
|
|
|
|
{"type": "text", "id": "resource_manager", "name": "resource_manager", "label": "资源维护人",
|
|
|
|
|
"placeholder": "请输入资源维护人"}
|
2024-06-06 20:56:06 +08:00
|
|
|
|
],
|
|
|
|
|
"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": {
|
|
|
|
|
"resource_id": {"type": "text", "width": "180px"},
|
|
|
|
|
"name": {"type": "text", "width": "180px"},
|
|
|
|
|
"unit": {"type": "text", "width": "180px"},
|
|
|
|
|
"position": {"type": "text", "width": "180px"},
|
|
|
|
|
"contact_phone": {"type": "text", "width": "180px"},
|
|
|
|
|
"contact_address": {"type": "text", "width": "180px"},
|
|
|
|
|
"resource_manager": {"type": "text", "width": "180px"},
|
|
|
|
|
"actions": {"type": "actions", "width": "100px"}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"query_params": query_params,
|
|
|
|
|
"form_action_url": 'proj_res_list',
|
|
|
|
|
"modify_url": reverse("proj_res_list_modify"),
|
|
|
|
|
"add_url": reverse("proj_res_list_add"),
|
|
|
|
|
"delete_url": reverse("proj_res_list_delete"),
|
2024-06-07 03:47:15 +08:00
|
|
|
|
"table_exclude_field_name": ['resource_id'], # Exclude primary key
|
2024-05-31 20:17:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 03:47:15 +08:00
|
|
|
|
return render(request, 'items_list.html', context)
|
2024-05-31 20:17:40 +08:00
|
|
|
|
|
|
|
|
|
|
2024-06-06 15:08:38 +08:00
|
|
|
|
def proj_res_list_add(request):
|
|
|
|
|
if request.method == 'POST':
|
2024-06-07 03:47:15 +08:00
|
|
|
|
form = ProjectResourcesForm(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 = ProjectResourcesForm()
|
|
|
|
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
|
|
|
|
return JsonResponse({"form_html": form_html})
|
|
|
|
|
else:
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
2024-06-06 15:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def proj_res_list_modify(request):
|
|
|
|
|
if request.method == 'POST':
|
2024-06-07 03:47:15 +08:00
|
|
|
|
if 'resource_id' in request.POST:
|
|
|
|
|
instance = ProjectResources.objects.get(resource_id=request.POST['resource_id'])
|
|
|
|
|
form = ProjectResourcesForm(request.POST, instance=instance)
|
|
|
|
|
else:
|
|
|
|
|
form = ProjectResourcesForm(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 'resource_id' in request.GET:
|
|
|
|
|
try:
|
|
|
|
|
instance = ProjectResources.objects.get(resource_id=request.GET['resource_id'])
|
|
|
|
|
form = ProjectResourcesForm(instance=instance)
|
|
|
|
|
except ProjectResources.DoesNotExist:
|
|
|
|
|
raise Http404("对象不存在")
|
|
|
|
|
else:
|
|
|
|
|
form = ProjectResourcesForm()
|
|
|
|
|
|
|
|
|
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
|
|
|
|
return JsonResponse({"form_html": form_html})
|
|
|
|
|
else:
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
2024-06-06 15:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def proj_res_list_delete(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
resource_id = request.GET.get('resource_id')
|
|
|
|
|
ProjectResources.objects.filter(resource_id=resource_id).delete()
|
|
|
|
|
return JsonResponse({"message": "删除成功"})
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
|
|
|
|
|
|
|
|
|
|
2024-05-31 20:17:40 +08:00
|
|
|
|
def cust_list_view(request):
|
|
|
|
|
# 声明查询集
|
|
|
|
|
query_set = Customer.objects.filter().order_by('-customer_id')
|
|
|
|
|
|
|
|
|
|
# 获取查询参数
|
|
|
|
|
name = request.GET.get('name', '')
|
|
|
|
|
unit = request.GET.get('unit', '')
|
|
|
|
|
|
|
|
|
|
# 根据提供的参数进行筛选
|
2024-06-06 15:08:38 +08:00
|
|
|
|
if name:
|
|
|
|
|
query_set = query_set.filter(name__icontains=name)
|
|
|
|
|
if unit:
|
|
|
|
|
query_set = query_set.filter(unit__icontains=unit)
|
2024-05-31 20:17:40 +08:00
|
|
|
|
|
|
|
|
|
# 对查询结果进行分页,每页10条记录
|
|
|
|
|
items = paginate_query_and_assign_numbers(
|
|
|
|
|
request=request,
|
|
|
|
|
queryset=query_set,
|
|
|
|
|
per_page=10
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 构建上下文查询参数字符串
|
2024-06-06 15:08:38 +08:00
|
|
|
|
query_params = '&name={}&unit={}'.format(name, unit)
|
|
|
|
|
|
2024-06-06 20:56:06 +08:00
|
|
|
|
# Excel上传模板
|
|
|
|
|
template_name = "营销管理-客户-Excel上传模板.xlsx"
|
|
|
|
|
|
|
|
|
|
# 构建上下文
|
2024-05-31 20:17:40 +08:00
|
|
|
|
context = {
|
2024-06-06 20:56:06 +08:00
|
|
|
|
"model_config": 'mkt_mgnt.Customer',
|
|
|
|
|
"items": items,
|
|
|
|
|
"breadcrumb_list": [
|
|
|
|
|
{"title": "首页", "name": "index"},
|
|
|
|
|
{"title": "营销管理", "name": "index"},
|
|
|
|
|
{"title": "客户", "name": "cust_list"}
|
|
|
|
|
],
|
|
|
|
|
"filters": [
|
|
|
|
|
{"type": "text", "id": "name", "name": "name", "label": "姓名", "placeholder": "请输入姓名"},
|
|
|
|
|
{"type": "text", "id": "unit", "name": "unit", "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": {
|
|
|
|
|
"customer_id": {"type": "text", "width": "180px"},
|
|
|
|
|
"relationship_type": {"type": "text", "width": "180px"},
|
|
|
|
|
"detailed_description": {"type": "text", "width": "180px"},
|
|
|
|
|
"name": {"type": "text", "width": "180px"},
|
|
|
|
|
"unit": {"type": "text", "width": "180px"},
|
|
|
|
|
"position": {"type": "text", "width": "180px"},
|
|
|
|
|
"residence": {"type": "text", "width": "180px"},
|
|
|
|
|
"cooperation": {"type": "text", "width": "180px"},
|
|
|
|
|
"main_organizer": {"type": "text", "width": "180px"},
|
|
|
|
|
"assistant": {"type": "text", "width": "180px"},
|
|
|
|
|
"actions": {"type": "actions", "width": "100px"}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"query_params": query_params,
|
|
|
|
|
"form_action_url": 'cust_list',
|
|
|
|
|
"modify_url": reverse("cust_list_modify"),
|
|
|
|
|
"add_url": reverse("cust_list_add"),
|
|
|
|
|
"delete_url": reverse("cust_list_delete"),
|
2024-06-07 03:47:15 +08:00
|
|
|
|
"table_exclude_field_name": ['customer_id'], # Exclude primary key
|
2024-05-31 20:17:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 03:47:15 +08:00
|
|
|
|
return render(request, 'items_list.html', context)
|
2024-06-06 15:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cust_list_add(request):
|
|
|
|
|
if request.method == 'POST':
|
2024-06-07 03:47:15 +08:00
|
|
|
|
form = CustomerForm(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 = CustomerForm()
|
|
|
|
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
|
|
|
|
return JsonResponse({"form_html": form_html})
|
|
|
|
|
else:
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
2024-06-06 15:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cust_list_modify(request):
|
|
|
|
|
if request.method == 'POST':
|
2024-06-07 03:47:15 +08:00
|
|
|
|
if 'customer_id' in request.POST:
|
|
|
|
|
instance = Customer.objects.get(customer_id=request.POST['customer_id'])
|
|
|
|
|
form = CustomerForm(request.POST, instance=instance)
|
|
|
|
|
else:
|
|
|
|
|
form = CustomerForm(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 'customer_id' in request.GET:
|
|
|
|
|
try:
|
|
|
|
|
instance = Customer.objects.get(customer_id=request.GET['customer_id'])
|
|
|
|
|
form = CustomerForm(instance=instance)
|
|
|
|
|
except Customer.DoesNotExist:
|
|
|
|
|
raise Http404("对象不存在")
|
|
|
|
|
else:
|
|
|
|
|
form = CustomerForm()
|
|
|
|
|
|
|
|
|
|
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
|
|
|
|
return JsonResponse({"form_html": form_html})
|
|
|
|
|
else:
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
2024-06-06 15:08:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cust_list_delete(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
customer_id = request.GET.get('customer_id')
|
|
|
|
|
Customer.objects.filter(customer_id=customer_id).delete()
|
|
|
|
|
return JsonResponse({"message": "删除成功"})
|
|
|
|
|
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
2024-06-07 03:47:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|