XH_Digital_Management/application/rsc_mgnt/views.py

654 lines
29 KiB
Python
Raw Normal View History

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-06-07 03:47:15 +08:00
from application.rsc_mgnt.forms import *
2024-05-31 20:17:40 +08:00
from application.rsc_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 cg_cat_list_view(request):
query_set = ConsumableGoodsCategory.objects.filter().order_by('-category_id')
category_name = request.GET.get('category_name', '')
2024-05-29 09:27:39 +08:00
2024-06-06 15:08:38 +08:00
if category_name:
query_set = query_set.filter(category_name__icontains=category_name)
2024-05-29 09:27:39 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&category_name={}'.format(category_name)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-消耗品类别管理-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.ConsumableGoodsCategory',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "消耗品类别管理", "name": "cg_cat_list"}
],
"filters": [
2024-06-06 15:08:38 +08:00
{"type": "text", "id": "category_name", "name": "category_name", "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": {
"category_id": {"type": "text", "width": "180px"},
"category_name": {"type": "text", "width": "180px"},
"description": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['category_id'],
2024-06-06 20:56:06 +08:00
"form_action_url": 'cg_cat_list',
"modify_url": reverse("cg_cat_list_modify"),
"add_url": reverse("cg_cat_list_add"),
"delete_url": reverse("cg_cat_list_delete"),
2024-05-31 20:17:40 +08:00
}
2024-05-29 09:27:39 +08:00
2024-06-07 03:47:15 +08:00
return render(request, 'items_list.html', context)
2024-05-29 09:27:39 +08:00
2024-06-06 15:08:38 +08:00
def cg_cat_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = ConsumableGoodsCategoryForm(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 = ConsumableGoodsCategoryForm()
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 cg_cat_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = ConsumableGoodsCategory.objects.get(category_id=request.POST['id'])
form = ConsumableGoodsCategoryForm(request.POST, instance=instance)
else:
form = ConsumableGoodsCategoryForm(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 'id' in request.GET:
try:
instance = ConsumableGoodsCategory.objects.get(category_id=request.GET['id'])
form = ConsumableGoodsCategoryForm(instance=instance)
except ConsumableGoodsCategory.DoesNotExist:
raise Http404("对象不存在")
else:
form = ConsumableGoodsCategoryForm()
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 cg_cat_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
ConsumableGoodsCategory.objects.filter(category_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-05-31 20:17:40 +08:00
def cg_inv_list_view(request):
query_set = ConsumableGoodsInventory.objects.filter().order_by('-inventory_id')
inventory_id = request.GET.get('inventory_id', '')
2024-05-29 09:27:39 +08:00
2024-06-06 15:08:38 +08:00
if inventory_id:
query_set = query_set.filter(inventory_id__icontains=inventory_id)
2024-05-31 20:17:40 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&inventory_id={}'.format(inventory_id)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-消耗品库存-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.ConsumableGoodsInventory',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "消耗品库存", "name": "cg_inv_list"}
],
"filters": [
2024-06-06 15:08:38 +08:00
{"type": "text", "id": "inventory_id", "name": "inventory_id", "label": "库存ID",
"placeholder": "请输入库存ID"}
],
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": {
"inventory_id": {"type": "text", "width": "180px"},
"item": {"type": "text", "width": "180px"},
"category": {"type": "text", "width": "180px"},
"specification": {"type": "text", "width": "180px"},
"unit": {"type": "text", "width": "180px"},
"current_inventory": {"type": "number", "width": "180px"},
"safety_stock": {"type": "number", "width": "180px"},
"replenishment_alert": {"type": "boolean", "width": "180px"},
"storage_location": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['inventory_id'],
2024-06-06 20:56:06 +08:00
"form_action_url": 'cg_inv_list',
"modify_url": reverse("cg_inv_list_modify"),
"add_url": reverse("cg_inv_list_add"),
"delete_url": reverse("cg_inv_list_delete"),
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 cg_inv_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = ConsumableGoodsInventoryForm(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 = ConsumableGoodsInventoryForm()
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 cg_inv_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = ConsumableGoodsInventory.objects.get(inventory_id=request.POST['id'])
form = ConsumableGoodsInventoryForm(request.POST, instance=instance)
else:
form = ConsumableGoodsInventoryForm(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 'id' in request.GET:
try:
instance = ConsumableGoodsInventory.objects.get(inventory_id=request.GET['id'])
form = ConsumableGoodsInventoryForm(instance=instance)
except ConsumableGoodsInventory.DoesNotExist:
raise Http404("对象不存在")
else:
form = ConsumableGoodsInventoryForm()
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 cg_inv_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
ConsumableGoodsInventory.objects.filter(inventory_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-05-31 20:17:40 +08:00
def cmp_phone_reg_list_view(request):
query_set = CompanyMobilePhoneUsageRegistry.objects.filter().order_by('-record_id')
mobile_number = request.GET.get('mobile_number', '')
current_user = request.GET.get('current_user', '')
owner = request.GET.get('owner', '')
2024-06-06 15:08:38 +08:00
if mobile_number:
query_set = query_set.filter(mobile_number__icontains=mobile_number)
if current_user:
query_set = query_set.filter(current_user__icontains=current_user)
if owner:
query_set = query_set.filter(owner__icontains=owner)
2024-05-31 20:17:40 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&mobile_number={}&current_user={}&owner={}'.format(mobile_number, current_user, owner)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-公司手机号使用登记-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.CompanyMobilePhoneUsageRegistry',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "公司手机号使用登记", "name": "cmp_phone_reg_list"}
],
"filters": [
2024-06-06 15:08:38 +08:00
{"type": "text", "id": "mobile_number", "name": "mobile_number", "label": "手机号",
"placeholder": "请输入手机号"},
{"type": "text", "id": "current_user", "name": "current_user", "label": "现使用人",
"placeholder": "请输入现使用人"},
{"type": "text", "id": "owner", "name": "owner", "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": {
"record_id": {"type": "text", "width": "180px"},
"mobile_number": {"type": "text", "width": "180px"},
"owner": {"type": "text", "width": "180px"},
"current_user": {"type": "text", "width": "180px"},
"purpose": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['record_id'],
2024-06-06 20:56:06 +08:00
"form_action_url": 'cmp_phone_reg_list',
"modify_url": reverse("cmp_phone_reg_list_modify"),
"add_url": reverse("cmp_phone_reg_list_add"),
"delete_url": reverse("cmp_phone_reg_list_delete"),
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 cmp_phone_reg_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = CompanyMobilePhoneUsageRegistryForm(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 = CompanyMobilePhoneUsageRegistryForm()
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 cmp_phone_reg_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = CompanyMobilePhoneUsageRegistry.objects.get(record_id=request.POST['id'])
form = CompanyMobilePhoneUsageRegistryForm(request.POST, instance=instance)
else:
form = CompanyMobilePhoneUsageRegistryForm(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 'id' in request.GET:
try:
instance = CompanyMobilePhoneUsageRegistry.objects.get(record_id=request.GET['id'])
form = CompanyMobilePhoneUsageRegistryForm(instance=instance)
except CompanyMobilePhoneUsageRegistry.DoesNotExist:
raise Http404("对象不存在")
else:
form = CompanyMobilePhoneUsageRegistryForm()
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 cmp_phone_reg_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
CompanyMobilePhoneUsageRegistry.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-05-31 20:17:40 +08:00
def bv_usage_list_view(request):
query_set = BusinessVehicleUsageRegistry.objects.filter().order_by('-record_id')
license_plate = request.GET.get('license_plate', '')
checkout_time = request.GET.get('checkout_time', '')
2024-06-06 15:08:38 +08:00
if license_plate:
query_set = query_set.filter(license_plate__icontains=license_plate)
if checkout_time:
query_set = query_set.filter(checkout_time__icontains=checkout_time)
2024-05-31 20:17:40 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&license_plate={}&checkout_time={}'.format(license_plate, checkout_time)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-商务车使用登记-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.BusinessVehicleUsageRegistry',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "商务车使用登记", "name": "bv_usage_list"}
],
"filters": [
2024-06-07 03:47:15 +08:00
{"type": "text", "id": "license_plate", "name": "license_plate", "label": "车牌",
"placeholder": "请输入车牌"},
2024-06-06 15:08:38 +08:00
{"type": "date", "id": "checkout_time", "name": "checkout_time", "label": "借用时间"}
],
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": {
"record_id": {"type": "text", "width": "180px"},
"license_plate": {"type": "text", "width": "180px"},
"checkout_time": {"type": "datetime", "width": "180px"},
"borrower": {"type": "text", "width": "180px"},
"accompanying_personnel": {"type": "text", "width": "180px"},
"reason": {"type": "text", "width": "180px"},
"destination": {"type": "text", "width": "180px"},
"days_of_use": {"type": "number", "width": "180px"},
"return_time": {"type": "datetime", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['record_id'],
2024-06-06 20:56:06 +08:00
"form_action_url": 'bv_usage_list',
"modify_url": reverse("bv_usage_list_modify"),
"add_url": reverse("bv_usage_list_add"),
"delete_url": reverse("bv_usage_list_delete"),
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 bv_usage_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = BusinessVehicleUsageRegistryForm(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 = BusinessVehicleUsageRegistryForm()
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 bv_usage_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = BusinessVehicleUsageRegistry.objects.get(record_id=request.POST['id'])
form = BusinessVehicleUsageRegistryForm(request.POST, instance=instance)
else:
form = BusinessVehicleUsageRegistryForm(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 'id' in request.GET:
try:
instance = BusinessVehicleUsageRegistry.objects.get(record_id=request.GET['id'])
form = BusinessVehicleUsageRegistryForm(instance=instance)
except BusinessVehicleUsageRegistry.DoesNotExist:
raise Http404("对象不存在")
else:
form = BusinessVehicleUsageRegistryForm()
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 bv_usage_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
BusinessVehicleUsageRegistry.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-05-31 20:17:40 +08:00
def mem_acc_list_view(request):
query_set = MembershipAccountsRegistry.objects.filter().order_by('-record_id')
platform_name = request.GET.get('platform_name', '')
status = request.GET.get('status', '')
2024-06-06 15:08:38 +08:00
if platform_name:
query_set = query_set.filter(platform_name__icontains=platform_name)
if status:
query_set = query_set.filter(status__icontains=status)
2024-05-31 20:17:40 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&platform_name={}&status={}'.format(platform_name, status)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-会员账号登记-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.MembershipAccountsRegistry',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "会员账号登记", "name": "mem_acc_list"}
],
"filters": [
2024-06-07 03:47:15 +08:00
{"type": "text", "id": "platform_name", "name": "platform_name", "label": "平台名称",
"placeholder": "请输入平台名称"},
2024-06-06 15:08:38 +08:00
{"type": "select", "id": "status", "name": "status", "label": "状态", "options": [
{"value": "有效", "display": "有效"}, {"value": "过期", "display": "过期"}
]}
],
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": {
"record_id": {"type": "text", "width": "180px"},
"platform_name": {"type": "text", "width": "180px"},
"purpose": {"type": "text", "width": "180px"},
"price": {"type": "number", "width": "180px"},
"manager": {"type": "text", "width": "180px"},
"account": {"type": "text", "width": "180px"},
"password": {"type": "password", "width": "180px"},
"effective_date": {"type": "date", "width": "180px"},
"expiration_date": {"type": "date", "width": "180px"},
"status": {"type": "select", "width": "180px", "options": [
{"value": "有效", "display": "有效"}, {"value": "过期", "display": "过期"}
]},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['record_id'],
2024-06-06 20:56:06 +08:00
"form_action_url": 'mem_acc_list',
"modify_url": reverse("mem_acc_list_modify"),
"add_url": reverse("mem_acc_list_add"),
"delete_url": reverse("mem_acc_list_delete"),
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 mem_acc_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = MembershipAccountsRegistryForm(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 = MembershipAccountsRegistryForm()
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 mem_acc_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = MembershipAccountsRegistry.objects.get(record_id=request.POST['id'])
form = MembershipAccountsRegistryForm(request.POST, instance=instance)
else:
form = MembershipAccountsRegistryForm(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 'id' in request.GET:
try:
instance = MembershipAccountsRegistry.objects.get(record_id=request.GET['id'])
form = MembershipAccountsRegistryForm(instance=instance)
except MembershipAccountsRegistry.DoesNotExist:
raise Http404("对象不存在")
else:
form = MembershipAccountsRegistryForm()
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 mem_acc_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
MembershipAccountsRegistry.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
2024-05-31 20:17:40 +08:00
def svc_reg_list_view(request):
query_set = StoredValueCardRegistration.objects.filter().order_by('-record_id')
merchant_name = request.GET.get('merchant_name', '')
2024-06-06 15:08:38 +08:00
if merchant_name:
query_set = query_set.filter(merchant_name__icontains=merchant_name)
2024-05-31 20:17:40 +08:00
2024-06-07 03:47:15 +08:00
items = paginate_query_and_assign_numbers(request=request, queryset=query_set, per_page=10)
2024-06-06 15:08:38 +08:00
query_params = '&merchant_name={}'.format(merchant_name)
2024-06-06 20:56:06 +08:00
template_name = "资源管理-储值卡登记表-Excel上传模板.xlsx"
2024-05-31 20:17:40 +08:00
context = {
2024-06-06 20:56:06 +08:00
"model_config": 'rsc_mgnt.StoredValueCardRegistration',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "资源管理", "name": "index"},
{"title": "储值卡登记表", "name": "svc_reg_list"}
2024-06-06 15:08:38 +08:00
],
2024-06-06 20:56:06 +08:00
"filters": [
2024-06-07 03:47:15 +08:00
{"type": "text", "id": "merchant_name", "name": "merchant_name", "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": {
"record_id": {"type": "text", "width": "180px"},
"merchant_name": {"type": "text", "width": "180px"},
"merchant_type": {"type": "text", "width": "180px"},
"balance": {"type": "number", "width": "180px"},
"usage_records": {"type": "textarea", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
2024-06-07 03:47:15 +08:00
2024-06-06 20:56:06 +08:00
"form_action_url": 'svc_reg_list',
2024-06-07 03:47:15 +08:00
"table_exclude_field_name": ['record_id'],
2024-06-06 20:56:06 +08:00
"modify_url": reverse("svc_reg_list_modify"),
"add_url": reverse("svc_reg_list_add"),
"delete_url": reverse("svc_reg_list_delete"),
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 svc_reg_list_add(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
form = StoredValueCardRegistrationForm(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 = StoredValueCardRegistrationForm()
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 svc_reg_list_modify(request):
if request.method == 'POST':
2024-06-07 03:47:15 +08:00
if 'id' in request.POST:
instance = StoredValueCardRegistration.objects.get(record_id=request.POST['id'])
form = StoredValueCardRegistrationForm(request.POST, instance=instance)
else:
form = StoredValueCardRegistrationForm(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 'id' in request.GET:
try:
instance = StoredValueCardRegistration.objects.get(record_id=request.GET['id'])
form = StoredValueCardRegistrationForm(instance=instance)
except StoredValueCardRegistration.DoesNotExist:
raise Http404("对象不存在")
else:
form = StoredValueCardRegistrationForm()
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 svc_reg_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
StoredValueCardRegistration.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)