XH_Digital_Management/application/opa_mgnt/views.py

440 lines
18 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.http import JsonResponse
from django.shortcuts import render
from django.urls import reverse
from application.opa_mgnt.models import *
from common.utils.page_helper import paginate_query_and_assign_numbers
def sma_reg_list_view(request):
# 声明查询集
query_set = SocialMediaAccountRegistration.objects.filter().order_by('-record_id')
# 获取查询参数
platform = request.GET.get('platform', '')
# 根据提供的参数进行筛选
if platform:
query_set = query_set.filter(platform__icontains=platform)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&platform={}'.format(platform)
# Excel上传模板
template_name = "运营管理-新媒体账号登记-Excel上传模板.xlsx"
# 构建上下文
context = {
"model_config": 'opa_mgnt.SocialMediaAccountRegistration',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "运营管理", "name": "index"},
{"title": "新媒体账号登记", "name": "sma_reg_list"}
],
"filters": [
{"type": "text", "id": "platform", "name": "platform", "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"},
"platform": {"type": "text", "width": "180px"},
"account_name": {"type": "text", "width": "180px"},
"primary_department": {"type": "text", "width": "180px"},
"secondary_department": {"type": "text", "width": "180px"},
"operation_account": {"type": "text", "width": "180px"},
"password": {"type": "text", "width": "180px"},
"operator": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
"form_action_url": 'sma_reg_list',
"modify_url": reverse("sma_reg_list_modify"),
"add_url": reverse("sma_reg_list_add"),
"delete_url": reverse("sma_reg_list_delete"),
}
return render(request, '../templates/list.html', context)
def sma_reg_list_add(request):
if request.method == 'POST':
data = {
'platform': request.POST.get('platform'),
'account_name': request.POST.get('account_name'),
'primary_department': request.POST.get('primary_department'),
'secondary_department': request.POST.get('secondary_department'),
'operation_account': request.POST.get('operation_account'),
'password': request.POST.get('password'),
'operator': request.POST.get('operator'),
}
SocialMediaAccountRegistration.objects.create(**data)
return JsonResponse({"message": "添加成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def sma_reg_list_modify(request):
if request.method == 'POST':
record_id = request.POST.get('record_id')
data = {
'platform': request.POST.get('platform'),
'account_name': request.POST.get('account_name'),
'primary_department': request.POST.get('primary_department'),
'secondary_department': request.POST.get('secondary_department'),
'operation_account': request.POST.get('operation_account'),
'password': request.POST.get('password'),
'operator': request.POST.get('operator'),
}
SocialMediaAccountRegistration.objects.filter(record_id=record_id).update(**data)
return JsonResponse({"message": "修改成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def sma_reg_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
SocialMediaAccountRegistration.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def acc_op_mgmt_list_view(request):
# 声明查询集
query_set = AccountOperationManagement.objects.filter().order_by('-record_id')
# 获取查询参数
platform = request.GET.get('platform', '')
# 根据提供的参数进行筛选
if platform:
query_set = query_set.filter(platform__icontains=platform)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&platform={}'.format(platform)
# Excel上传模板
template_name = "运营管理-账号运营管理记录-Excel上传模板.xlsx"
# 构建上下文
context = {
"model_config": 'opa_mgnt.AccountOperationManagement',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "运营管理", "name": "index"},
{"title": "账号运营管理记录", "name": "acc_op_mgmt_list"}
],
"filters": [
{"type": "text", "id": "platform", "name": "platform", "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"},
"platform": {"type": "text", "width": "180px"},
"account_name": {"type": "text", "width": "180px"},
"content_title": {"type": "text", "width": "180px"},
"publication_time": {"type": "datetime", "width": "180px"},
"views": {"type": "number", "width": "180px"},
"favorites": {"type": "number", "width": "180px"},
"comments": {"type": "number", "width": "180px"},
"shares": {"type": "number", "width": "180px"},
"likes": {"type": "number", "width": "180px"},
"followers": {"type": "number", "width": "180px"},
"update_time": {"type": "datetime", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
"form_action_url": 'acc_op_mgmt_list',
"modify_url": reverse("acc_op_mgmt_list_modify"),
"add_url": reverse("acc_op_mgmt_list_add"),
"delete_url": reverse("acc_op_mgmt_list_delete"),
}
return render(request, '../templates/list.html', context)
def acc_op_mgmt_list_add(request):
if request.method == 'POST':
data = {
'platform': request.POST.get('platform'),
'account_name': request.POST.get('account_name'),
'content_title': request.POST.get('content_title'),
'publication_time': request.POST.get('publication_time'),
'views': request.POST.get('views'),
'favorites': request.POST.get('favorites'),
'comments': request.POST.get('comments'),
'shares': request.POST.get('shares'),
'likes': request.POST.get('likes'),
'followers': request.POST.get('followers'),
'update_time': request.POST.get('update_time'),
}
AccountOperationManagement.objects.create(**data)
return JsonResponse({"message": "添加成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def acc_op_mgmt_list_modify(request):
if request.method == 'POST':
record_id = request.POST.get('record_id')
data = {
'platform': request.POST.get('platform'),
'account_name': request.POST.get('account_name'),
'content_title': request.POST.get('content_title'),
'publication_time': request.POST.get('publication_time'),
'views': request.POST.get('views'),
'favorites': request.POST.get('favorites'),
'comments': request.POST.get('comments'),
'shares': request.POST.get('shares'),
'likes': request.POST.get('likes'),
'followers': request.POST.get('followers'),
'update_time': request.POST.get('update_time'),
}
AccountOperationManagement.objects.filter(record_id=record_id).update(**data)
return JsonResponse({"message": "修改成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def acc_op_mgmt_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
AccountOperationManagement.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_reg_list_view(request):
# 声明查询集
query_set = WebsiteRegistration.objects.filter().order_by('-record_id')
# 获取查询参数
website_name = request.GET.get('website_name', '')
# 根据提供的参数进行筛选
if website_name:
query_set = query_set.filter(website_name__icontains=website_name)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&website_name={}'.format(website_name)
# Excel上传模板
template_name = "运营管理-网站登记-Excel上传模板.xlsx"
# 构建上下文
context = {
"model_config": 'opa_mgnt.WebsiteRegistration',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "运营管理", "name": "index"},
{"title": "网站登记", "name": "web_reg_list"}
],
"filters": [
{"type": "text", "id": "website_name", "name": "website_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"},
"website_name": {"type": "text", "width": "180px"},
"primary_department": {"type": "text", "width": "180px"},
"secondary_department": {"type": "text", "width": "180px"},
"account": {"type": "text", "width": "180px"},
"password": {"type": "text", "width": "180px"},
"login_url": {"type": "text", "width": "180px"},
"tech_support": {"type": "text", "width": "180px"},
"domain": {"type": "text", "width": "180px"},
"expiration_date": {"type": "date", "width": "180px"},
"operator": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
"form_action_url": 'web_reg_list',
"modify_url": reverse("web_reg_list_modify"),
"add_url": reverse("web_reg_list_add"),
"delete_url": reverse("web_reg_list_delete"),
}
return render(request, '../templates/list.html', context)
def web_reg_list_add(request):
if request.method == 'POST':
data = {
'website_name': request.POST.get('website_name'),
'primary_department': request.POST.get('primary_department'),
'secondary_department': request.POST.get('secondary_department'),
'account': request.POST.get('account'),
'password': request.POST.get('password'),
'login_url': request.POST.get('login_url'),
'tech_support': request.POST.get('tech_support'),
'domain': request.POST.get('domain'),
'expiration_date': request.POST.get('expiration_date'),
'operator': request.POST.get('operator'),
}
WebsiteRegistration.objects.create(**data)
return JsonResponse({"message": "添加成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_reg_list_modify(request):
if request.method == 'POST':
record_id = request.POST.get('record_id')
data = {
'website_name': request.POST.get('website_name'),
'primary_department': request.POST.get('primary_department'),
'secondary_department': request.POST.get('secondary_department'),
'account': request.POST.get('account'),
'password': request.POST.get('password'),
'login_url': request.POST.get('login_url'),
'tech_support': request.POST.get('tech_support'),
'domain': request.POST.get('domain'),
'expiration_date': request.POST.get('expiration_date'),
'operator': request.POST.get('operator'),
}
WebsiteRegistration.objects.filter(record_id=record_id).update(**data)
return JsonResponse({"message": "修改成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_reg_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
WebsiteRegistration.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_maint_rec_list_view(request):
# 声明查询集
query_set = WebsiteMaintenanceRecord.objects.filter().order_by('-record_id')
# 获取查询参数
website_name = request.GET.get('website_name', '')
# 根据提供的参数进行筛选
if website_name:
query_set = query_set.filter(website_name__icontains=website_name)
# 对查询结果进行分页每页10条记录
items = paginate_query_and_assign_numbers(
request=request,
queryset=query_set,
per_page=10
)
# 构建上下文查询参数字符串
query_params = '&website_name={}'.format(website_name)
# Excel上传模板
template_name = "运营管理-网站运维记录-Excel上传模板.xlsx"
# 构建上下文
context = {
"model_config": 'opa_mgnt.WebsiteMaintenanceRecord',
"items": items,
"breadcrumb_list": [
{"title": "首页", "name": "index"},
{"title": "运营管理", "name": "index"},
{"title": "网站运维记录", "name": "web_maint_rec_list"}
],
"filters": [
{"type": "text", "id": "website_name", "name": "website_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"},
"website_name": {"type": "text", "width": "180px"},
"maintenance_content": {"type": "text", "width": "180px"},
"maintenance_details": {"type": "text", "width": "180px"},
"maintenance_time": {"type": "datetime", "width": "180px"},
"maintainer": {"type": "text", "width": "180px"},
"actions": {"type": "actions", "width": "100px"}
}
},
"query_params": query_params,
"form_action_url": 'web_maint_rec_list',
"modify_url": reverse("web_maint_rec_list_modify"),
"add_url": reverse("web_maint_rec_list_add"),
"delete_url": reverse("web_maint_rec_list_delete"),
}
return render(request, '../templates/list.html', context)
def web_maint_rec_list_add(request):
if request.method == 'POST':
data = {
'website_name': request.POST.get('website_name'),
'maintenance_content': request.POST.get('maintenance_content'),
'maintenance_details': request.POST.get('maintenance_details'),
'maintenance_time': request.POST.get('maintenance_time'),
'maintainer': request.POST.get('maintainer'),
}
WebsiteMaintenanceRecord.objects.create(**data)
return JsonResponse({"message": "添加成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_maint_rec_list_modify(request):
if request.method == 'POST':
record_id = request.POST.get('record_id')
data = {
'website_name': request.POST.get('website_name'),
'maintenance_content': request.POST.get('maintenance_content'),
'maintenance_details': request.POST.get('maintenance_details'),
'maintenance_time': request.POST.get('maintenance_time'),
'maintainer': request.POST.get('maintainer'),
}
WebsiteMaintenanceRecord.objects.filter(record_id=record_id).update(**data)
return JsonResponse({"message": "修改成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)
def web_maint_rec_list_delete(request):
if request.method == 'GET':
target_id = request.GET.get('target_id')
WebsiteMaintenanceRecord.objects.filter(record_id=target_id).delete()
return JsonResponse({"message": "删除成功"})
return JsonResponse({"message": "无效的请求方法"}, status=405)