#add message

This commit is contained in:
xieshen 2021-02-03 16:15:45 +08:00
parent 957fdd1bdb
commit 1eff922cd4
4 changed files with 145 additions and 7 deletions

View File

@ -0,0 +1,61 @@
{% extends 'dashboard/base/base.html' %}
{% load static %}
{% block content %}
<body class=" ">
<!-- START TOPBAR -->
<!-- START CONTAINER -->
<div class="page-container row-fluid">
<div class="page-sidebar ">
{% include 'dashboard/base/left.html' %}
</div>
<section id="main-content" class=" ">
<section class="wrapper" style='margin-top:60px;display:inline-block;width:100%;padding:15px 0 0 15px;'>
{% if messages %}
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<span aria-hidden="true">&times;</span>
<span class="sr-only">Close</span>
</button>
{% for message in messages %}
{{ message }}.<br/>
{% endfor %}
</div>
{% endif %}
</section>
<div class="chatapi-windows "></div>
<div class="panel panel-default">
<div class="panel-body">
<div class="panel panel-default">
<div class="panel-heading">添加不合格记录</div>
<div class="panel panel-default">
<!-- Default panel contents -->
<form action="{% url 'backstage-add-unqualified-media' %}" method="post"
enctype="multipart/form-data">{% csrf_token %}
<div class="form-group col-md-12">
<label for="version">批次</label>
<input type="text" class="form-control" id="source"
name="version">
</div>
<div class="form-group col-md-12" style="margin-left: 10%">
<label for="exampleInputFile">点击上传文件</label>
<input type="file" id="exampleInputFile" name="file">
{# <p class="help-block">请上传csv文件(文件表头依次为:新媒体类型,新媒体名称,主体类型,代表主体名称,市,县/区,备注,结果,更新次数,最大连续静默日数,开始时间,结束时间。时间格式为2020/11/17.更新次数和最大连续静默日必须是数字)</p>#}
</div>
<button type="submit" class="btn btn-success" style="margin-left: 40%">点击上传</button>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
</body>
{% endblock %}

View File

@ -14,7 +14,8 @@ from xlrd import xldate_as_tuple, xldate_as_datetime
from NewMediaMonitoring import settings
from dashboard.models import TimelinessMonitoring, Wrongly, Comment, Area_code_2020, Organization, Weixin, Douyin, \
Weibo, Toutiao, Qita
Weibo, Toutiao, Qita, NewMedia
from polls.models import UnqualifiedMedia
def backstage_new_media_public_opinion(request):
@ -377,4 +378,69 @@ def backstage_qita_update(request):
return render(request, 'backstage/backstage-toutiao-update.html', {'data_results': data_results})
def add_unqualified_media(request):
return render(request)
if request.method == 'POST':
filename = request.FILES.get('file')
version = request.POST.get('version')
if not os.path.exists(settings.MEDIA_ROOT):
os.makedirs(settings.MEDIA_ROOT)
if filename is None:
messages.error(request, '请选择要上传的文件!!!')
return HttpResponseRedirect('/backstage/add/unqualified/media/')
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 != '单位全称':
media_type = table.row_values(row)[7]
media_code = table.row_values(row)[3]
name = table.row_values(row)[4]
unit = table.row_values(row)[1]
media_id = None
type = None
print(media_code)
try:
if "微信" in str(media_type):
media_id = Weixin.objects.get(code=name).id
type = 0
elif "微博" in str(media_type):
media_id = Weibo.objects.get(code=name).id
type = 1
elif "抖音" in str(media_type):
media_id = Douyin.objects.get(code=name).id
type = 2
elif "头条" in str(media_type):
media_id = Toutiao.objects.get(code=name).id
type = 3
else:
media_id = Qita.objects.get(code=name).id
type = 4
if Area_code_2020.objects.filter(name=table.row_values(row)[9]).count() > 0:
province = Area_code_2020.objects.get(name=table.row_values(row)[9]).code
else:
province = table.row_values(row)[9]
if Area_code_2020.objects.filter(name=table.row_values(row)[10]).count() > 0:
cities = Area_code_2020.objects.get(name=table.row_values(row)[10]).code
else:
cities = table.row_values(row)[10]
if Area_code_2020.objects.filter(name=table.row_values(row)[11]).count() > 0:
district = Area_code_2020.objects.get(name=table.row_values(row)[11]).code
else:
district = table.row_values(row)[11]
result = table.row_values(row)[20]
cou = table.row_values(row)[21]
dos = table.row_values(row)[22]
sdos = time.strftime('%Y-%m-%d', time.localtime(table.row_values(row)[23]))
edos = time.strftime('%Y-%m-%d', time.localtime(table.row_values(row)[24]))
unqualifiedmedia = UnqualifiedMedia(media_id=media_id, name=name, unit=unit, type=type,
province=province, cities=cities, district=district,
result=result, cou=cou, dos=dos, sdos=sdos, edos=edos,
version=version)
unqualifiedmedia.save()
except:
pass
print(media_id)
messages.success(request,"上传成功")
return render(request,'backstage/backstage_add_unqualified_media.html')

View File

@ -33,7 +33,6 @@ def new_media_public_opinion_weixin(request):
o['id'] = str(w.id)
o['code'] = w.weixin.code
o['title'] = w.title
o['comment'] = w.comment
o['reply'] = w.reply
o['year'] = w.year
o['month'] = w.month

View File

@ -80,8 +80,11 @@ class Notice(models.Model):
return Notice.objects.create(type=2, user_id=user_id, content=content, news_id=news_id)
@classmethod
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value):
return Notice.objects.create(type=1, user_id=user_id, content=content, app=app, model=model, field=field, record_id=record_id, record_pass_value=record_pass_value, record_reject_value=record_reject_value)
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value,
record_reject_value):
return Notice.objects.create(type=1, user_id=user_id, content=content, app=app, model=model, field=field,
record_id=record_id, record_pass_value=record_pass_value,
record_reject_value=record_reject_value)
def __str__(self):
return self.content + ':' + self.user.username
@ -119,7 +122,8 @@ class Task(models.Model):
def add_url_message(self, user_id, title, description, url, image):
for group in self.groups.all():
Message.objects.create(
type=1, send_from_id=user_id, send_to_id=group.id, task=self, page_title=title, page_description=description, page_image=image, url=url)
type=1, send_from_id=user_id, send_to_id=group.id, task=self, page_title=title,
page_description=description, page_image=image, url=url)
class Meta:
ordering = ["-added"]
@ -252,6 +256,14 @@ UNQUALIFIED_MEDIA_TYPE_CHOICES = (
class UnqualifiedMedia(models.Model):
'''
type:
weixin = 0
weibo = 1
douyin = 2
toutiao = 3
qita = 4
'''
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
media_id = models.UUIDField('media_id', null=True, blank=True)
name = models.CharField('name', max_length=256, null=True, blank=True)