From 38c6b76ddb69318b20f719776beb8fbcccfc1027 Mon Sep 17 00:00:00 2001 From: xieshen <1397910458@qq.com> Date: Thu, 7 Jan 2021 18:53:00 +0800 Subject: [PATCH] #add message --- .../backstage-organization-update.html | 59 +++++++++++++++++++ backstage/urls.py | 1 + backstage/views.py | 43 ++++++++++++++ dashboard/templates/dashboard/base/left.html | 29 ++++++++- 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 backstage/templates/backstage/backstage-organization-update.html diff --git a/backstage/templates/backstage/backstage-organization-update.html b/backstage/templates/backstage/backstage-organization-update.html new file mode 100644 index 0000000..0e5b008 --- /dev/null +++ b/backstage/templates/backstage/backstage-organization-update.html @@ -0,0 +1,59 @@ +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block content %} + + + + +
+ +
+ {% include 'dashboard/base/left.html' %} +
+
+
+ {% if messages %} + + {% endif %} + +
+
+
+
+
+
单位数据更新
+
+ +
{% csrf_token %} +{#
#} +{# #} +{# #} +{#
#} +
+ + +
+ +
+
+ +
+
+ +
+ +
+
+ +{% endblock %} + diff --git a/backstage/urls.py b/backstage/urls.py index 3a36f79..23c85a8 100644 --- a/backstage/urls.py +++ b/backstage/urls.py @@ -8,4 +8,5 @@ urlpatterns = [ path('backstage/error/',views.backstage_error,name='backstage-error'), path('backstage/comment/',views.backstage_comment,name='backstage-comment'), path('backstage/user/',views.backstage_user,name='backstage-user'), + path('backstage/organization/update/',views.backstage_organization_update,name='backstage-organization_update'), ] diff --git a/backstage/views.py b/backstage/views.py index e7d5398..6028fa4 100644 --- a/backstage/views.py +++ b/backstage/views.py @@ -129,3 +129,46 @@ def backstage_comment(request): def backstage_user(request): return render(request, '') + +def backstage_organization_update(request): + if request.method == 'POST': + filename = request.FILES.get('file') + date = request.POST.get("date") + date_length = request.POST.get("date_length") + if not os.path.exists(settings.MEDIA_ROOT): + os.makedirs(settings.MEDIA_ROOT) + if filename is None: + messages.error(request, '请选择要上传的文件!!!') + return HttpResponseRedirect('/backstage/backstage/organization/update/') + + data = xlrd.open_workbook(filename=None, file_contents=filename.read()) + table = data.sheets()[0] + for row in range(table.nrows): + v = table.row_values(row)[1] + if v != '单位全称': + try: + identificationcode = table.row_values(row)[3] + n_type = table.row_values(row)[7] + results = table.row_values(row)[21] + update = table.row_values(row)[22] + silent = table.row_values(row)[23] + start_data = table.row_values(row)[24] + d = datetime(*xldate_as_tuple(start_data, 0)) + cell_start = d.strftime('%Y-%m-%d') + end_data = table.row_values(row)[25] + e = datetime(*xldate_as_tuple(end_data, 0)) + cell_end = e.strftime('%Y-%m-%d') + city = table.row_values(row)[10] + cell_city = Area_code_2020.objects.get(name=city).code + district = table.row_values(row)[11] + cell_district = Area_code_2020.objects.get(name=district).code + timelinessmonitoring = TimelinessMonitoring(identificationcode=identificationcode, n_type=n_type, + results=results, update=update, silent=silent, + start_data=cell_start, end_data=cell_end, date=date, + date_length=date_length,city=cell_city,district=cell_district) + timelinessmonitoring.save() + except: + pass + messages.success(request,"上传成功") + return render(request, 'backstage/backstage-organization-update.html') + diff --git a/dashboard/templates/dashboard/base/left.html b/dashboard/templates/dashboard/base/left.html index c9345e7..60e67de 100644 --- a/dashboard/templates/dashboard/base/left.html +++ b/dashboard/templates/dashboard/base/left.html @@ -33,7 +33,7 @@ -