#add message

This commit is contained in:
xieshen 2021-04-02 16:45:37 +08:00
parent 4c1065ff26
commit 289589b5fd
6 changed files with 123 additions and 52 deletions

View File

@ -9,6 +9,7 @@ urlpatterns = [
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'),
path('backstage/data/download/',views.backstage_data_download,name='backstage-data-download'),
path('backstage/weixin/update/',views.backstage_weixin_update,name='backstage-weixin_update'),
path('backstage/douyin/update/',views.backstage_douyin_update,name='backstage-douyin_update'),
path('backstage/weibo/update/',views.backstage_weibo_update,name='backstage-weibo_update'),

View File

@ -6,7 +6,7 @@ from datetime import datetime
import xlrd
from django.contrib import messages
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseRedirect, FileResponse
from django.shortcuts import render
# Create your views here.
@ -444,3 +444,95 @@ def add_unqualified_media(request):
print(media_id)
messages.success(request,"上传成功")
return render(request,'backstage/backstage_add_unqualified_media.html')
def backstage_data_download(request):
user = request.user
weixin = Weixin.objects.all()
weibo = Weibo.objects.all()
toutiao = Toutiao.objects.all()
douyin = Douyin.objects.all()
qita = Qita.objects.all()
results = []
for wx in weixin:
o_weixin = dict()
o_weixin['type'] = "微信"
o_weixin['code'] = wx.code
o_weixin['organization'] = wx.organization.name
o_weixin['alias'] = wx.alias
o_weixin['status'] = wx.status
o_weixin['id'] = wx.weixinid
o_weixin['attention'] = wx.attention
o_weixin['identificationcode'] = wx.identificationcode
o_weixin['function'] = wx.function
o_weixin['articleurl'] = wx.articleurl
results.append(o_weixin)
for wb in weibo:
o_weibo = dict()
o_weibo['type'] = "微博"
o_weibo['code'] = wb.code
o_weibo['organization'] = wb.organization.name
o_weibo['alias'] = wb.alias
o_weibo['status'] = wb.status
o_weibo['id'] = wb.weiboid
o_weibo['attention'] = wb.attention
o_weibo['identificationcode'] = wb.identificationcode
o_weibo['function'] = wb.function
o_weibo['articleurl'] = wb.articleurl
results.append(o_weibo)
for tt in toutiao:
o_toutiao = dict()
o_toutiao['type'] = "今日头条"
o_toutiao['code'] = tt.code
o_toutiao['organization'] = tt.organization.name
o_toutiao['alias'] = tt.alias
o_toutiao['status'] = tt.status
o_toutiao['id'] = tt.toutiaoid
o_toutiao['attention'] = tt.attention
o_toutiao['identificationcode'] = tt.identificationcode
o_toutiao['function'] = tt.function
o_toutiao['articleurl'] = tt.articleurl
results.append(o_toutiao)
for dy in douyin:
o_douyin = dict()
o_douyin['type'] = "抖音"
o_douyin['code'] = dy.code
o_douyin['organization'] = dy.organization.name
o_douyin['alias'] = dy.alias
o_douyin['status'] = dy.status
o_douyin['id'] = dy.douyinid
o_douyin['attention'] = dy.attention
o_douyin['identificationcode'] = dy.identificationcode
o_douyin['function'] = dy.function
o_douyin['articleurl'] = dy.articleurl
results.append(o_douyin)
for qt in qita:
o_qita = dict()
o_qita['type'] = qt.type
o_qita['code'] = qt.code
o_qita['organization'] = qt.organization.name
o_qita['alias'] = qt.alias
o_qita['status'] = qt.status
o_qita['id'] = qt.qitaid
o_qita['attention'] = qt.attention
o_qita['identificationcode'] = qt.identificationcode
o_qita['function'] = qt.function
o_qita['articleurl'] = qt.articleurl
results.append(o_qita)
# print(results)
t = int(time.time())
os.popen('mkdir /var/www/p3/newmediamonitoring/static/upload/%s' % (t))
f = '/var/www/p3/newmediamonitoring/static/upload/%s' % (t)
with open(f+'/'+user.username+'.csv','w', newline='',encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["类型","名称", "单位", "别名", "状态", "ID", "关注量","新媒体标识码","功能","文章URL"])
for r in results:
# print(r['type'])
writer.writerow([r['type'], r['code'], r['organization'],r['alias'], r['status'], r['id'], r['attention'],r['identificationcode'],r['function'], r['articleurl']])
file = open(f+'/'+user.username+'.csv','rb')
response = FileResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment'
return response

View File

@ -191,8 +191,8 @@
href="{% url 'backstage-comment' %}">评论</a>
</li>
<li>
<a {% if url_name == 'backstage-organization_update' %} class="active" {% endif %}
href="{% url 'backstage-organization_update' %}">单位更新</a>
<a {% if url_name == 'backstage-data-download' %} class="active" {% endif %}
href="{% url 'backstage-data-download' %}">数据下载</a>
</li>
<li>
<a {% if url_name == 'backstage-weixin_update' %} class="active" {% endif %}

View File

@ -44,7 +44,7 @@
action="{% url 'user-management-update' usee.id %}"
enctype="multipart/form-data">{% csrf_token %}
<div class="form-group">
<label class="form-label" for="organization">单位</label>
<label class="form-label" for="organization">单位(请选择主体单位。新建或编辑单位名称在“主体单位管理”栏)</label>
{# <div class="controls">#}
{# <select class="form-control" name="organization">#}
{# <option value="{{ userprofile.organization.id }}">{{ userprofile.organization.name }}</option>#}
@ -88,6 +88,16 @@
value="{{ usee.username }}">
</div>
</div>
<div class="form-group">
<label class="form-label" for="username">通知</label>
<div class="controls">
{% if userprofile.message_status %}
<span>短信通知</span>
{% else %}
<span>不做通知</span>
{% endif %}
</div>
</div>
<div class="form-group">
<label class="form-label" for="image">图标
@ -99,22 +109,7 @@
</div>
</label>
</div>
<div class="form-group">
<label for="passwordold">旧密码<br/>
<input type="password" name="passwordold" id="user_pass" class="input"
value="" size="20"/></label>
</div>
<div class="form-group">
<label for="passwordnew">新密码<br/>
<input type="password" name="passwordnew" id="user_pass" class="input"
value="" size="20"/></label>
</div>
<div class="form-group">
<label for="confirm_password">确认密码<br/>
<input type="password" name="confirm_password" id="user_pass1"
class="input" value=""
size="20"/></label>
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 50px">提交修改
</button>
</form>

View File

@ -74,10 +74,11 @@
{# <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-update' u.user_id %}"
class="btn btn-success btn-mini">修改</a>
<a href="{% url 'user-management-delete' u.user_id %}"
class="btn btn-danger btn-mini">删除</a>
{# <a href="{% url 'user-management-update' u.user_id %}"#}
{# class="btn btn-success btn-mini">修改</a>#}
</td>
</tr>
{% endfor %}

View File

@ -120,26 +120,8 @@ def user_update(request, pk):
email = request.POST.get('email')
username = request.POST.get('username')
image = request.FILES.get('image')
passwordold = request.POST.get('passwordold')
passwordnew = request.POST.get('passwordnew')
confirm_password = request.POST.get('confirm_password')
if len(passwordold) != 0 and len(passwordnew) != 0 and len(confirm_password) != 0:
if passwordnew == confirm_password:
user.email = email
user.username = username
user.password = make_password(passwordnew)
userprofile.organization_id = o_id
userprofile.name = name
if image is not None:
userprofile.image = image
user.save()
userprofile.save()
messages.success(request, "修改成功")
return HttpResponseRedirect("/")
else:
messages.error(request, '两次输入密码不一致')
return HttpResponseRedirect('/management/user/update/%s/' % (pk))
else:
user.email = email
user.username = username
userprofile.organization_id = o_id
@ -149,7 +131,7 @@ def user_update(request, pk):
user.save()
userprofile.save()
messages.success(request, "修改成功")
return HttpResponseRedirect("/index")
return HttpResponseRedirect("/management/user/management/")
return render(request, 'management/user-management-update.html',
{'usee': user, 'userprofile': userprofile, 'organization': organization})