#add message

This commit is contained in:
xieshen 2020-11-17 09:03:09 +08:00
parent 82e98070f3
commit f0b2c9fdcf
10 changed files with 90 additions and 76 deletions

View File

@ -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])
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')

View File

@ -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

View File

@ -62,7 +62,9 @@
{% for w in res %}
<tr>
<td style="vertical-align: middle;text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center"><img src="{{ w.image.url }}"
<td style="text-align: center"><img {% if w.image.url %}
src="{{ w.image.url }}"{% else %}
src="{% static 'dashboard/image/douyin.jpg' %}" {% endif %}
style="width: 60px;height: 60px;margin: auto"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ w.code }}</td>

View File

@ -64,7 +64,9 @@
{% for w in res %}
<tr>
<td style="vertical-align: middle;text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center"><img src="{{ w.image.url }}"
<td style="text-align: center"><img {% if w.image.url %}
src="{{ w.image.url }}"{% else %}
src="{% static 'dashboard/image/qita.png' %}" {% endif %}
style="width: 60px;height: 60px;margin: auto"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ w.type }}</td>

View File

@ -62,7 +62,9 @@
{% for w in res %}
<tr>
<td style="vertical-align: middle;text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center"><img src="{{ w.image.url }}"
<td style="text-align: center"><img {% if w.image.url %}
src="{{ w.image.url }}"{% else %}
src="{% static 'dashboard/image/toutiao.png' %}" {% endif %}
style="width: 60px;height: 60px;margin: auto"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ w.code }}</td>

View File

@ -63,7 +63,9 @@
{% for w in res %}
<tr>
<td style="vertical-align: middle;text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center"><img src="{{ w.image.url }}"
<td style="text-align: center"><img {% if w.image.url %}
src="{{ w.image.url }}"{% else %}
src="{% static 'dashboard/image/weibo.png' %}" {% endif %}
style="width: 60px;height: 60px;margin: auto"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ w.code }}</td>

View File

@ -62,7 +62,9 @@
{% for w in res %}
<tr>
<td style="vertical-align: middle;text-align: center">{{ forloop.counter }}</td>
<td style="text-align: center"><img src="{{ w.image.url }}"
<td style="text-align: center"><img {% if w.image.url %}
src="{{ w.image.url }}"{% else %}
src="{% static 'dashboard/image/weixin.png' %}" {% endif %}
style="width: 60px;height: 60px;margin: auto"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ w.code }}</td>

View File

@ -51,7 +51,7 @@
<th style="text-align: center">序号</th>
<th style="text-align: center">头像</th>
<th style="text-align: center">姓名</th>
<th style="text-align: center">电话<a href="{% url 'user-management-management-sort' %}">^</a></th>
<th style="text-align: center">电话<a href="{% url 'user-management-management-sort' %}"></a></th>
<th style="text-align: center">单位名称</th>
{# <th style="text-align: center">单位类型</th>#}
<th style="text-align: center">行政区划</th>
@ -71,7 +71,7 @@
{# <td style="vertical-align: middle;text-align: center">{{ u.type }}</td>#}
<td style="vertical-align: middle;text-align: center">{{ u.administrativedivision }}</td>
<td style="vertical-align: middle;text-align: center">
<a href="{% url 'user-management-delete' u.id %}"
<a href="{% url 'user-management-delete' u.user_id %}"
class="btn btn-danger btn-mini">删除</a>
</td>
</tr>

View File

@ -24,16 +24,16 @@ def user_management(request):
district = o.district
userpaginator = None
if level == 1:
userpaginator = User.objects.filter(userprofile__organization__province=province).order_by('-date_joined')
userpaginator = Userprofile.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
userpaginator = User.objects.filter(userprofile__organization__province=province,
userprofile__organization__cities=cities).order_by('-date_joined')
userpaginator = Userprofile.objects.filter(organization__province=province,
organization__cities=cities).order_by('-created')
elif level == 3:
userpaginator = User.objects.filter(userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district).order_by('-date_joined')
userpaginator = Userprofile.objects.filter(organization__province=province,
organization__cities=cities,
organization__district=district).order_by('-created')
elif level == 9:
userpaginator = User.objects.all().order_by('-date_joined')
userpaginator = Userprofile.objects.all().order_by('-created')
userallinfo = []
if userpaginator is not None:
paginator = Paginator(userpaginator, 6)
@ -48,12 +48,13 @@ def user_management(request):
for u in userpaginator:
o = dict()
o['id'] = str(u.id)
if u.userprofile_set.get(user_id=u.id).image:
o['image'] = u.userprofile_set.get(user_id=u.id).image
o['name'] = u.userprofile_set.get(user_id=u.id).name
o['phone'] = u.username
o['organization'] = u.userprofile_set.get(user_id=u.id).organization.name
organization_id = Userprofile.objects.get(user_id=u.id).organization_id
o['user_id'] = str(u.user_id)
if u.image:
o['image'] = u.image
o['name'] = u.name
o['phone'] = u.user.username
o['organization'] = u.organization.name
organization_id = u.organization.id
print(organization_id)
if Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get(
@ -100,8 +101,9 @@ def user_management(request):
@login_required
def user_delete(request, pk):
print(pk)
user = User.objects.get(id=pk)
user.delete()
# user.delete()
return HttpResponseRedirect('/management/user/management/')

40
test.py
View File

@ -1,38 +1,4 @@
# -*- coding: utf-8 -*-
import csv
import re
import uuid
import os
import psycopg2
from pip._vendor import chardet
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB1 user=newmedia password=newmedia2020!@#'
def insert_area(title,date, code,content):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
id = uuid.uuid4()
cursor.execute(
'insert into monitor_test(id, title,date, code,content) values (%s,%s, %s,%s,%s)'
, (str(id),title,date, code,content))
connection.commit()
return code
if __name__ == '__main__':
with open('D:/2020/舆论监测平台/新媒体监测数据/天水/天水20200822-20200922/天水20200822-20200922数据整理/天水微信正文.csv',encoding='utf8') as csvfile:
reader = csv.reader(csvfile)
try:
for r in reader:
print(r)
title = r[0]
date = r[1]
code = r[2]
content = r[5]
insert_area(title, date, code, content)
except:
pass
s = '2020-10-9'
mat = re.search(r"(\d{4}-\d{1,2}-\d{1,2})",s)
print(mat)