diff --git a/backstage/views.py b/backstage/views.py index f85f2c5..b3503cb 100644 --- a/backstage/views.py +++ b/backstage/views.py @@ -1,11 +1,14 @@ import os +import re import xlrd +from django.contrib import messages from django.http import HttpResponse from django.shortcuts import render # Create your views here. from NewMediaMonitoring import settings +from dashboard.models import TimelinessMonitoring def backstage_new_media_public_opinion(request): @@ -18,7 +21,39 @@ def backstage_new_media_public_opinion(request): # ncols = sheet.ncols table = workbook.sheets()[0] for row in range(table.nrows): - v = table.row_values(row)[0] - if v != '账号名称': - print(table.row_values(row)[0]) - return render(request,'backstage/backstage_new_media_public_opinion.html') \ No newline at end of file + v = table.row_values(row) + if v[0] != '新媒体类型' or v[1] != '新媒体名称' or v[2] != '主体类型' or v[3] != '代表主体名称' or v[4] != '市' or v[ + 6] != '备注' or v[7] != '结果' or v[8] != '更新次数' or v[9] != '最大连续静默日数' or v[10] != '开始时间' or v[ + 11] != '结束时间': + messages.error(request, '请上传正确的文件格式!!!') + return render(request, 'backstage/backstage_new_media_public_opinion.html') + mat1 = re.search(r"(\d{4}-\d{1,2}-\d{1,2})", v[10]) + mat2 = re.search(r"(\d{4}-\d{1,2}-\d{1,2})", v[11]) + if mat1 is None or mat2 is None: + messages.error(request, '请上传正确的时间格式!!!') + return render(request, 'backstage/backstage_new_media_public_opinion.html') + if v[8].isdigit() and v[9].isdigit(): + if v != '账号名称': + n_type = v[0] + n_name = v[1] + o_type = v[2] + o_name = v[3] + city = v[4] + counties = v[5] + remark = v[6] + results = v[7] + update = v[8] + silet = v[9] + start_data = v[10] + end_data = v[11] + timelinessmonitoring = TimelinessMonitoring(n_type=n_type, n_name=n_name, o_type=o_type, o_name=o_name, + city=city, counties=counties, remark=remark, + results=results, update=update, silet=silet, + start_data=start_data, end_data=end_data,) + print(timelinessmonitoring) + + else: + messages.error(request, '更新次数和最大连续静默日数只能为数字!!!') + return render(request, 'backstage/backstage_new_media_public_opinion.html') + + return render(request, 'backstage/backstage_new_media_public_opinion.html') diff --git a/dashboard/views.py b/dashboard/views.py index 05ea3f4..d05fbca 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -471,6 +471,7 @@ def user_search_by_keyword(request): for u in userpaginator[:30]: o = dict() o['id'] = str(u.id) + o['user_id'] = str(u.user_id) if u.image: o['image'] = u.image o['name'] = u.name diff --git a/management/templates/management/newmedia-management-edit-douyin.html b/management/templates/management/newmedia-management-edit-douyin.html index 20bc385..c681fee 100644 --- a/management/templates/management/newmedia-management-edit-douyin.html +++ b/management/templates/management/newmedia-management-edit-douyin.html @@ -28,7 +28,7 @@