This commit is contained in:
baoliang 2021-04-07 18:49:47 +08:00
commit 933cec0b8c
7 changed files with 220 additions and 68 deletions

View File

@ -9,6 +9,7 @@ urlpatterns = [
path('backstage/comment/',views.backstage_comment,name='backstage-comment'), path('backstage/comment/',views.backstage_comment,name='backstage-comment'),
path('backstage/user/',views.backstage_user,name='backstage-user'), path('backstage/user/',views.backstage_user,name='backstage-user'),
path('backstage/organization/update/',views.backstage_organization_update,name='backstage-organization_update'), 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/weixin/update/',views.backstage_weixin_update,name='backstage-weixin_update'),
path('backstage/douyin/update/',views.backstage_douyin_update,name='backstage-douyin_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'), path('backstage/weibo/update/',views.backstage_weibo_update,name='backstage-weibo_update'),

View File

@ -6,7 +6,7 @@ from datetime import datetime
import xlrd import xlrd
from django.contrib import messages from django.contrib import messages
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect, FileResponse
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
@ -444,3 +444,95 @@ def add_unqualified_media(request):
print(media_id) print(media_id)
messages.success(request,"上传成功") messages.success(request,"上传成功")
return render(request,'backstage/backstage_add_unqualified_media.html') 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')
f = '/var/www/p3/newmediamonitoring/static/upload'
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;filename="data.csv"'
return response

View File

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

View File

@ -448,14 +448,21 @@ def import_user(request):
@login_required @login_required
def user_search_by_keyword(request): def user_search_by_keyword(request):
keytype = None
keyword = None
if request.method == 'POST':
keytype = request.POST.get('keytype')
keyword = request.POST.get('keyword')
else:
keytype = request.GET.get('keytype')
keyword = request.GET.get('keyword')
user = request.user user = request.user
o = Organization.objects.get(userprofile__user_id=user.id) o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level level = o.level.level
province = o.province province = o.province
cities = o.cities cities = o.cities
district = o.district district = o.district
keytype = request.POST.get('keytype')
keyword = request.POST.get('ketword')
userpaginator = None userpaginator = None
if level == 1: if level == 1:
if keytype == '1': if keytype == '1':
@ -464,6 +471,22 @@ def user_search_by_keyword(request):
elif keytype == '2': elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword, userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province) userprofile__organization__province=province)
elif keytype == '3':
userpaginator = Userprofile.objects.filter(user__username__contains=keyword,
userprofile__organization__province=province)
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__cities=k.code,
userprofile__organization__province=province)
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__district=k.code,
userprofile__organization__province=province)
elif keytype == '6':
userpaginator = Userprofile.objects.filter(message_status=True,name__contains=keyword,
userprofile__organization__province=province)
elif level == 2: elif level == 2:
if keytype == '1': if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword, userpaginator = Userprofile.objects.filter(name__contains=keyword,
@ -473,6 +496,26 @@ def user_search_by_keyword(request):
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword, userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province, userprofile__organization__province=province,
userprofile__organization__cities=cities) userprofile__organization__cities=cities)
elif keytype == '3':
userpaginator = Userprofile.objects.filter(user__username__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__cities=k.code,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__district=k.code,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif keytype == '6':
userpaginator = Userprofile.objects.filter(message_status=True,name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif level == 3: elif level == 3:
if keytype == '1': if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword, userpaginator = Userprofile.objects.filter(name__contains=keyword,
@ -484,25 +527,60 @@ def user_search_by_keyword(request):
userprofile__organization__province=province, userprofile__organization__province=province,
userprofile__organization__cities=cities, userprofile__organization__cities=cities,
userprofile__organization__district=district) userprofile__organization__district=district)
elif keytype == '3':
userpaginator = Userprofile.objects.filter(user__username__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__cities=k.code,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__district=k.code,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif keytype == '6':
userpaginator = Userprofile.objects.filter(message_status=True,name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif level == 9: elif level == 9:
if keytype == '1': if keytype == '1':
print(keyword)
userpaginator = Userprofile.objects.filter(name__contains=keyword) userpaginator = Userprofile.objects.filter(name__contains=keyword)
elif keytype == '2': elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword) userpaginator = Userprofile.objects.filter(organization__name__contains=keyword)
elif keytype == '3':
userpaginator = Userprofile.objects.filter(user__username__contains=keyword)
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__cities=k.code)
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
userpaginator = Userprofile.objects.filter(organization__district=k.code)
elif keytype == '6':
userpaginator = Userprofile.objects.filter(message_status=True,name__contains=keyword)
# paginator = Paginator(userpaginator, 6) user_count = userpaginator.count()
# page = int(request.GET.get('page', 1)) paginator = Paginator(userpaginator, 6)
# try: page = int(request.GET.get('page', 1))
# userpaginator = paginator.page(page) try:
# except PageNotAnInteger: userpaginator = paginator.page(page)
# userpaginator = paginator.page(1) except PageNotAnInteger:
# except EmptyPage: userpaginator = paginator.page(1)
# userpaginator = paginator.page(paginator.num_pages) except EmptyPage:
user_count = None userpaginator = paginator.page(paginator.num_pages)
if userpaginator:
user_count = userpaginator.count()
userallinfo = [] userallinfo = []
for u in userpaginator[:30]: for u in userpaginator:
o = dict() o = dict()
o['id'] = str(u.id) o['id'] = str(u.id)
o['user_id'] = str(u.user_id) o['user_id'] = str(u.user_id)
@ -553,7 +631,7 @@ def user_search_by_keyword(request):
'None', '') 'None', '')
userallinfo.append(o) userallinfo.append(o)
return render(request, 'management/user-management.html', return render(request, 'management/user-management.html',
{'userallinfo': userallinfo, 'userpaginator': userpaginator, 'user_count': user_count}) {'userallinfo': userallinfo, 'userpaginator': userpaginator, 'user_count': user_count,'keytype':keytype,'keyword':keyword})
@login_required @login_required

View File

@ -44,7 +44,7 @@
action="{% url 'user-management-update' usee.id %}" action="{% url 'user-management-update' usee.id %}"
enctype="multipart/form-data">{% csrf_token %} enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="organization">单位</label> <label class="form-label" for="organization">单位(请选择主体单位。新建或编辑单位名称在“主体单位管理”栏)</label>
{# <div class="controls">#} {# <div class="controls">#}
{# <select class="form-control" name="organization">#} {# <select class="form-control" name="organization">#}
{# <option value="{{ userprofile.organization.id }}">{{ userprofile.organization.name }}</option>#} {# <option value="{{ userprofile.organization.id }}">{{ userprofile.organization.name }}</option>#}
@ -88,6 +88,16 @@
value="{{ usee.username }}"> value="{{ usee.username }}">
</div> </div>
</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"> <div class="form-group">
<label class="form-label" for="image">图标 <label class="form-label" for="image">图标
@ -99,22 +109,7 @@
</div> </div>
</label> </label>
</div> </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 type="submit" class="btn btn-primary" style="margin-top: 50px">提交修改
</button> </button>
</form> </form>

View File

@ -29,13 +29,14 @@
<option value="1">姓名</option> <option value="1">姓名</option>
<option value="2">单位</option> <option value="2">单位</option>
<option value="3">电话</option> <option value="3">电话</option>
<option value="4">行政区划</option> <option value="4">行政区划(市)</option>
<option value="4">行政区划</option> <option value="5">行政区划(县)</option>
<option value="6">短信通知</option>
</select> </select>
</div> </div>
<div class="col-lg-6 title"> <div class="col-lg-6 title">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" placeholder="输入搜索关键字" name="ketword"> <input type="text" class="form-control" placeholder="输入搜索关键字" name="keyword" value="{{ keyword }}">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default" type="submit">搜索</button> <button class="btn btn-default" type="submit">搜索</button>
</span> </span>
@ -73,8 +74,11 @@
{# <td style="vertical-align: middle;text-align: center">{{ u.type }}</td>#} {# <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">{{ u.administrativedivision }}</td>
<td style="vertical-align: middle;text-align: center"> <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 %}" <a href="{% url 'user-management-delete' u.user_id %}"
class="btn btn-danger btn-mini">删除</a> class="btn btn-danger btn-mini">删除</a>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -120,36 +120,18 @@ def user_update(request, pk):
email = request.POST.get('email') email = request.POST.get('email')
username = request.POST.get('username') username = request.POST.get('username')
image = request.FILES.get('image') image = request.FILES.get('image')
passwordold = request.POST.get('passwordold')
passwordnew = request.POST.get('passwordnew')
confirm_password = request.POST.get('confirm_password') user.email = email
if len(passwordold) != 0 and len(passwordnew) != 0 and len(confirm_password) != 0: user.username = username
if passwordnew == confirm_password: userprofile.organization_id = o_id
user.email = email userprofile.name = name
user.username = username if image is not None:
user.password = make_password(passwordnew) userprofile.image = image
userprofile.organization_id = o_id user.save()
userprofile.name = name userprofile.save()
if image is not None: messages.success(request, "修改成功")
userprofile.image = image return HttpResponseRedirect("/management/user/management/")
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
userprofile.name = name
if image is not None:
userprofile.image = image
user.save()
userprofile.save()
messages.success(request, "修改成功")
return HttpResponseRedirect("/index")
return render(request, 'management/user-management-update.html', return render(request, 'management/user-management-update.html',
{'usee': user, 'userprofile': userprofile, 'organization': organization}) {'usee': user, 'userprofile': userprofile, 'organization': organization})