newmediamonitoring/dashboard/views.py

1737 lines
85 KiB
Python

import csv
import json
import http.client
import random
from django.db.models import Sum
from django.contrib.auth.decorators import login_required
from django.contrib.auth.hashers import make_password
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.utils import timezone
import time
from urllib import parse
from captcha.helpers import captcha_image_url
from captcha.models import CaptchaStore
from dateutil import relativedelta
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.models import User
from django.db.models import Q
from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import render
import datetime
# Create your views here.
from dashboard.models import Userprofile, Organization, Area_code_2020, Weixin, Weibo, Toutiao, Qita, News, Douyin, \
CheckCode, Group, Group_admin, Group_user, TimelinessMonitoring, Weixin_data
from dashboard.yunpian import YunPian
import os
def refresh_captcha(request):
to_json_response = dict()
to_json_response['status'] = 1
to_json_response['new_cptch_key'] = CaptchaStore.generate_key()
to_json_response['new_cptch_image'] = captcha_image_url(to_json_response['new_cptch_key'])
return JsonResponse(to_json_response)
def home(request):
weixin_count = Weixin.objects.all().count()
weibo_count = Weibo.objects.all().count()
toutiao_count = Toutiao.objects.all().count()
qita_count = Qita.objects.all().count()
douyin_count = Douyin.objects.all().count()
newmedia_count = weixin_count + weibo_count + toutiao_count + qita_count + douyin_count
article_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
news_count = News.objects.filter(type='3').count()
return render(request, 'dashboard/home.html',
{'newmedia_count': newmedia_count, 'article_count': article_count, 'news_count': news_count})
def index(request):
data = []
weixin_count = Weixin.objects.all().count()
weibo_count = Weibo.objects.all().count()
toutiao_count = Toutiao.objects.all().count()
qita_count = Qita.objects.all().count()
douyin_count = Douyin.objects.all().count()
organization_count = Organization.objects.filter(status='1').count()
weixin_data = Weixin_data.objects.all().order_by('-timestamp')[:100]
for w in weixin_data:
o = dict()
o['id'] = str(w.id)
o['title'] = w.title
o['timestamp'] = w.timestamp
o['mp'] = w.mp
data.append(o)
return render(request, 'dashboard/index.html',
{'weixin_count': weixin_count, 'weibo_count': weibo_count, 'toutiao_count': toutiao_count,
'qita_count': qita_count, 'douyin_count': douyin_count, 'organization_count': organization_count,
'weixin_data': data})
def user_login(request):
username = None
password = None
hash_key = CaptchaStore.generate_key()
image_url = captcha_image_url(hash_key)
if request.method == 'POST':
if not request.POST.get('username'):
messages.error(request, '请输入用户名')
else:
username = request.POST.get('username')
if not request.POST.get('password'):
messages.error(request, '请输入密码')
else:
password = request.POST.get('password')
captcha_input = request.POST.get('captcha_1')
captcha_hashkey = request.POST.get('captcha_0')
try:
CaptchaStore.objects.get(response=captcha_input.lower(), hashkey=captcha_hashkey,
expiration__gt=datetime.datetime.now()).delete()
except CaptchaStore.DoesNotExist:
messages.error(request, '验证码错误')
return HttpResponseRedirect('/login')
if username is not None and password is not None:
try:
user = authenticate(username=username, password=password)
# user = User.objects.get(username=phone)
if user is not None:
if user.check_password(password):
login(request, user)
if Userprofile.objects.get(user_id=user.id).image is None:
userpro = Userprofile.objects.get(user_id=user.id)
userpro.image = '/profile/user_default.jpg'
return HttpResponseRedirect('/index/')
else:
messages.error(request, '无效的账号')
else:
messages.error(request, '账号或密码错误,请您确认账号和密码')
except:
messages.error(request, '账号或密码错误,请您确认账号和密码')
return render(request, 'dashboard/login-new.html', {'hash_key': hash_key, 'image_url': image_url})
def user_login_for_phone(request):
if request.method == 'GET':
return render(request, 'dashboard/login-for-phone-new.html')
elif request.method == 'POST':
p_code = request.POST.get('check_code')
phone = request.POST.get('phone')
results = CheckCode.objects.filter(phone=phone).count()
# try:
res = User.objects.filter(username=phone).count()
if res > 0:
messages.error(request, '您的账号已经存在,请您使用密码登录!!!')
return HttpResponseRedirect('/login')
if results > 0:
check_code = CheckCode.objects.get(phone_code=p_code, phone=phone)
if User.objects.filter(username=phone).count() > 0:
user = User.objects.get(username=phone)
login(request, user, backend='django.contrib.auth.backends.ModelBackend')
# check_code.delete()
return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id))
else:
user = User(username=phone, last_login=timezone.now())
user.save()
# userprofile = Userprofile(user_id=user.id, image='default.png')
# userprofile.save()
u = authenticate(username=phone)
login(request, u, backend='django.contrib.auth.backends.ModelBackend')
return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id))
# if float(time.time()) - float(check_code.c_time) > 60:
# check_code.delete()
# return '验证码超时已被删除'
# print(21333333333)
#
# except:
else:
print(1233333333)
messages.error(request, '请输入正确的验证码!!!')
return render(request, 'dashboard/login-for-phone-new.html')
def improve_personal_information(request, pk):
name = None
email = None
image = None
password = None
confirm_password = None
o_id = None
user = User.objects.get(id=pk)
if request.method == 'POST':
o = request.POST.get('organization')
if Organization.objects.get(name=o):
o_id = Organization.objects.get(name=o).id
else:
messages.error(request, '您填写的单位不存在!!!')
if request.POST.get('name'):
name = request.POST.get('name')
else:
messages.error(request, '请输入您的姓名!!!')
if request.POST.get('email'):
email = request.POST.get('email')
else:
messages.error(request, '请输入您的邮箱!!!')
if request.FILES.get('image'):
image = request.POST.get('image')
else:
image = '/profile/user_default.jpg'
if request.POST.get('password'):
password = request.POST.get('password')
else:
messages.error(request, '请输入密码')
confirm_password = request.POST.get('confirm_password')
if password is not None and confirm_password is not None:
if password == confirm_password:
User.objects.filter(id=pk).update(email=email, password=make_password(password))
userprofile = Userprofile(name=name, image=image, organization_id=o_id, user_id=user.id)
userprofile.save()
messages.success(request, '修改成功')
return render(request, 'dashboard/user-improve-personal-information.html', {'usee': user})
def author_code(request):
sms_host = "sms.yunpian.com"
voice_host = "voice.yunpian.com"
# 端口号
port = 443
# 版本号
version = "v2"
# 模板短信接口的URI
sms_tpl_send_uri = "/" + version + "/sms/tpl_single_send.json"
apikey = "304eb08353f7ebf00596737acfc31f53"
# mobile = "18119305139"
mobile = request.POST.get('mobile')
print(str(mobile) + "99999999999999999999999999999999999999999")
tpl_id = 4045320
code = ""
for i in range(6):
ch = chr(random.randrange(ord('0'), ord('9') + 1))
code += ch
print(code)
# tpl_value = {'#dateStart#': '10月1日', '#dateEnd#': '10日', '#type#': '微信公众号', '#name#': code}
tpl_value = {'#code#': code}
params = parse.urlencode({
'apikey': apikey,
'tpl_id': tpl_id,
'tpl_value': parse.urlencode(tpl_value),
'mobile': mobile
})
headers = {
"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"
}
conn = http.client.HTTPSConnection(sms_host, port=port, timeout=30)
conn.request("POST", sms_tpl_send_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
try:
check_code = CheckCode.objects.get(phone=mobile)
check_code.phone_code = code
check_code.save()
except:
print(code, mobile, 1111111111)
check_code = CheckCode(phone_code=code, phone=mobile)
check_code.save()
conn.close()
return response_str
def user_logout(request):
logout(request)
return HttpResponseRedirect('/')
def register(request):
username = None
email = None
password = None
confirm_password = None
name = None
# phone = None
image = None
flag = False
user_organization = None
sex = None
user_organization = None
hash_key = CaptchaStore.generate_key()
image_url = captcha_image_url(hash_key)
organization = Organization.objects.filter(status='1')
if request.method == 'POST':
if not request.POST.get('organization'):
messages.error(request, '请选择单位')
else:
o = request.POST.get('organization')
res = Organization.objects.filter(name=o).count()
if res > 0:
user_organization = Organization.objects.get(name=o).id
else:
messages.error(request, '您填写的单位不存在')
if not request.POST.get('name'):
messages.error(request, '请输入姓名')
else:
name = request.POST.get('name')
# email = request.POST.get('email')
if not request.POST.get('username'):
messages.error(request, '请输入用户名')
else:
username = request.POST.get('username')
if not request.POST.get('password'):
messages.error(request, '请输入密码')
else:
password = request.POST.get('password')
if not request.POST.get('confirm_password'):
messages.error(request, '请再次输入密码')
else:
confirm_password = request.POST.get('confirm_password')
if not request.FILES.get('image'):
image = '/profile/user_default.jpg'
else:
image = request.FILES.get('image')
if request.POST.get('sex') == '1':
sex = ''
elif request.POST.get('sex') == '2':
sex = ''
captcha_input = request.POST.get('captcha_1')
captcha_hashkey = request.POST.get('captcha_0')
try:
CaptchaStore.objects.get(response=captcha_input.lower(), hashkey=captcha_hashkey,
expiration__gt=datetime.datetime.now()).delete()
except CaptchaStore.DoesNotExist:
messages.error(request, '验证码错误')
return HttpResponseRedirect('/register/')
if password is not None and confirm_password is not None:
if password == confirm_password:
flag = True
else:
messages.error(request, '两次输入的密码不一致,请重新输入')
filter_result = User.objects.filter(username=username)
if len(filter_result) > 0:
messages.error(request, '对不起,您输入的电话号码已被注册')
return HttpResponseRedirect('/register/')
if username is not None and password is not None and confirm_password is not None and flag:
user = User.objects.create_user(username, email, password, last_login=timezone.now())
user.is_active = True
# user.is_staff = True
# user.first_name = phone
userprofile = Userprofile(name=name, image=image, user_id=user.id, organization_id=user_organization,
sex=sex, status=0)
userprofile.save()
user.save()
messages.success(request, '注册成功,请登录')
return HttpResponseRedirect('/login')
return render(request, 'dashboard/register-new.html',
{'hash_key': hash_key, 'image_url': image_url, 'organization': organization})
def get_province(request):
# 省
province = Area_code_2020.objects.filter(level=1, name='甘肃省')
res = []
for i in province:
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"province": res})
def get_city(request):
code = request.GET.get('code')
print(code)
# 市
cities = Area_code_2020.objects.filter(pcode=code)
res = []
for i in cities:
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"city": res})
def get_district(request):
code = request.GET.get('code')
# 县
district = Area_code_2020.objects.filter(pcode=code)
res = []
for i in district:
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"district": res})
def get_town(request):
code = request.GET.get('code')
# 乡
town = Area_code_2020.objects.filter(pcode=code)
res = []
for i in town:
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"town": res})
def get_village(request):
code = request.GET.get('code')
# 村
village = Area_code_2020.objects.filter(pcode=code)
res = []
for i in village:
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"village": res})
def get_organization(request):
keywords = request.GET.get('keyword')
if len(keywords) != 0:
o = Organization.objects.filter(Q(name__contains=keywords))[:10]
topten_list = []
for i in o:
d = dict()
d['id'] = str(i.id)
d['name'] = i.name
if i.province:
d['province'] = Area_code_2020.objects.get(code=i.province).name
else:
d['province'] = ''
if i.cities:
d['cities'] = Area_code_2020.objects.get(code=i.cities).name
else:
d['cities'] = ''
if i.district:
d['district'] = Area_code_2020.objects.get(code=i.district).name
else:
d['district'] = ''
topten_list.append(d)
return render(request, 'dashboard/results_by_keywords.html', {'topten_list': topten_list})
def wechat_verify(request):
return HttpResponse("11833201729252855821")
def import_user(request):
with open('F:/总.csv') as csvfile:
reader = csv.reader(csvfile)
for r in reader:
organization = r[0]
name = r[1]
zhiwei = r[2]
phone = r[3]
print(organization)
o = Organization.objects.get(name=organization)
password = str(phone)[5:]
if phone:
try:
if User.objects.filter(username=phone).count() == 0:
user = User.objects.create_user(username=phone, password=password, last_login=timezone.now())
user.save()
u = Userprofile(user_id=user.id, organization_id=o.id, status=1, image='/profile/user_default.jpg',
sex='', name=name, zhiwei=zhiwei)
u.save()
else:
if '平凉' in organization:
print(organization)
Userprofile.objects.filter(user__username=phone).update(organization_id=o.id)
except:
print(phone)
return HttpResponse('ok')
@login_required
def user_search_by_keyword(request):
user = request.user
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
keytype = request.POST.get('keytype')
keyword = request.POST.get('ketword')
userpaginator = None
if level == 1:
if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province)
elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province)
elif level == 2:
if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
elif level == 3:
if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
elif level == 9:
if keytype == '1':
userpaginator = Userprofile.objects.filter(name__contains=keyword)
elif keytype == '2':
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword)
# paginator = Paginator(userpaginator, 6)
# page = int(request.GET.get('page', 1))
# try:
# userpaginator = paginator.page(page)
# except PageNotAnInteger:
# userpaginator = paginator.page(1)
# except EmptyPage:
# userpaginator = paginator.page(paginator.num_pages)
user_count = None
if userpaginator:
user_count = userpaginator.count()
userallinfo = []
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
else:
o['image'] = '/profile/user_default.jpg'
o['name'] = u.name
o['phone'] = User.objects.get(id=u.user_id).username
o['organization'] = u.organization.name
organization_id = u.organization_id
if Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get(
id=organization_id).district and Organization.objects.get(
id=organization_id).town and Organization.objects.get(id=organization_id).village:
o['administrativedivision'] = str(str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).town)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).village))).replace(
'None', '')
elif Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get(
id=organization_id).district and Organization.objects.get(id=organization_id).town:
o['administrativedivision'] = str(str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).town))).replace('None',
'')
elif Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities and Organization.objects.get(id=organization_id).district:
o['administrativedivision'] = str(str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).district))).replace(
'None', '')
elif Organization.objects.get(id=organization_id).province and Organization.objects.get(
id=organization_id).cities:
o['administrativedivision'] = str(str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province)) + '-' + str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).cities))).replace(
'None', '')
elif Organization.objects.get(id=organization_id).province:
o['administrativedivision'] = str(str(
Area_code_2020.objects.get(code=Organization.objects.get(id=organization_id).province))).replace(
'None', '')
userallinfo.append(o)
return render(request, 'management/user-management.html',
{'userallinfo': userallinfo, 'userpaginator': userpaginator, 'user_count': user_count})
@login_required
def news_search_by_keyword(request):
keytype = request.POST.get('keytype')
keyword = request.POST.get('keyword')
news = None
if keytype == '1':
news = News.objects.filter(type='0', title__contains=keyword)
elif keytype == '2':
news = News.objects.filter(type='1', title__contains=keyword)
elif keytype == '3':
news = News.objects.filter(type='2', title__contains=keyword)
elif keytype == '4':
news = News.objects.filter(type='3', title__contains=keyword)
elif keytype == '5':
news = News.objects.filter(type='4', title__contains=keyword)
elif keytype == '6':
news = News.objects.filter(type='5', title__contains=keyword)
elif keytype == '7':
news = News.objects.filter(type='6', title__contains=keyword)
elif keytype == '0':
news = News.objects.filter(title__contains=keyword)
news_list = []
news_count = news.count()
for n in news[:30]:
o = dict()
o['id'] = str(n.id)
o['title'] = n.title
o['date'] = n.date
o['author'] = n.author
if n.type == '0':
o['type'] = '政策依据'
elif n.type == '1':
o['type'] = '基层动态'
elif n.type == '2':
o['type'] = '外省动态'
elif n.type == '3':
o['type'] = '监测通报'
elif n.type == '4':
o['type'] = '舆情热点'
elif n.type == '5':
o['type'] = '通知'
elif n.type == '6':
o['type'] = '重点新闻'
news_list.append(o)
return render(request, 'management/news-management.html',
{'news': news_list, 'new': news, 'news_count': news_count})
@login_required
def organization_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
organization = None
res = []
if level == 1:
if keytype == '1':
organization = Organization.objects.filter(province=province, name__contains=keyword).order_by('-created')
elif keytype == '2':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province,cities=k.code).order_by('-created')
elif keytype == '3':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province,district=k.code).order_by('-created')
elif keytype == '4':
organization = Organization.objects.filter(province=province,userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
organization = Organization.objects.filter(province=province, cities=cities,
name__contains=keyword).order_by('-created')
elif keytype == '2':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province,cities=k.code).order_by('-created')
elif keytype == '3':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province, cities=cities,district=k.code).order_by('-created')
elif keytype == '4':
organization = Organization.objects.filter(province=province, cities=cities,userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
organization = Organization.objects.filter(province=province, cities=cities, district=district,
name__contains=keyword).order_by(
'-created')
elif keytype == '2':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province, district=district,cities=k.code).order_by('-created')
elif keytype == '3':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(province=province, cities=cities, district=k.code).order_by('-created')
elif keytype == '4':
organization = Organization.objects.filter(province=province, cities=cities, district=district,userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
organization = Organization.objects.filter(name__contains=keyword).order_by('-created')
elif keytype == '2':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(cities=k.code).order_by('-created')
elif keytype == '3':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
organization = Organization.objects.filter(district=k.code).order_by('-created')
elif keytype == '4':
organization = Organization.objects.filter(userprofile__name__contains=keyword).order_by('-created')
organization_count = organization.count()
paginator = Paginator(organization, 6)
page = int(request.GET.get('page', 1))
try:
organization = paginator.page(page)
except PageNotAnInteger:
organization = paginator.page(1)
except EmptyPage:
organization = paginator.page(paginator.num_pages)
for i in organization:
print(i)
o = dict()
o['id'] = str(i.id)
o['name'] = i.name
if i.image:
o['image'] = i.image.url
else:
o['image'] = 'danweimoren.jpg'
if i.province and i.cities and i.district and i.town and i.village:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str(
Area_code_2020.objects.get(code=i.cities).name) + '-' + str(
Area_code_2020.objects.get(code=i.district).name) + '-' + str(
Area_code_2020.objects.get(code=i.town).name) + '-' + str(
Area_code_2020.objects.get(code=i.village).name)
elif i.province and i.cities and i.district and i.town:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str(
Area_code_2020.objects.get(code=i.cities).name) + '-' + str(
Area_code_2020.objects.get(code=i.district).name) + '-' + str(
Area_code_2020.objects.get(code=i.town).name)
elif i.province and i.cities and i.district:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str(
Area_code_2020.objects.get(code=i.cities).name) + '-' + str(
Area_code_2020.objects.get(code=i.district).name)
elif i.province and i.cities:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str(
Area_code_2020.objects.get(code=i.cities).name)
elif i.province:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name)
o['usercount'] = Userprofile.objects.filter(organization_id=i.id).count()
o['mediacount'] = Weixin.objects.filter(organization_id=i.id).count() + Weibo.objects.filter(
organization_id=i.id).count() + Toutiao.objects.filter(
organization_id=i.id).count() + Qita.objects.filter(
organization_id=i.id).count()
res.append(o)
return render(request, 'management/organization-management.html',
{"organization": organization, 'res': res, 'organization_count': organization_count,'keytype':keytype,'keyword':keyword})
@login_required
def weixin_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
weixin = None
res = []
print(level)
if level == 1:
if keytype == '1':
weixin = Weixin.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
elif keytype == '2':
weixin = Weixin.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weixin = Weixin.objects.filter(organization__province=province,
status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(organization__province=province,name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__province=province,organization__district=k.code).order_by('-created')
elif keytype == '6':
weixin = Weixin.objects.filter(organization__province=province,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by(
'-created')
elif keytype == '2':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by(
'-created')
elif keytype == '3':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
status=int(keyword)).order_by(
'-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__province=province,organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
weixin = Weixin.objects.filter(organization__province=province,organization__cities=cities,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, code__contains=keyword).order_by(
'-created')
elif keytype == '2':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,
organization__name__contains=keyword).order_by(
'-created')
elif keytype == '3':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,
status=int(keyword)).order_by(
'-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__province=province,
organization__district=district,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
weixin = Weixin.objects.filter(code__contains=keyword).order_by('-created')
elif keytype == '2':
weixin = Weixin.objects.filter(organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weixin = Weixin.objects.filter(status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weixin = Weixin.objects.filter(organization__district=k.code).order_by('-created')
elif keytype == '6':
weixin = Weixin.objects.filter(organization__userprofile__name__contains=keyword).order_by('-created')
weixin_count = weixin.count()
paginator = Paginator(weixin, 6)
page = int(request.GET.get('page', 1))
try:
weixin = paginator.page(page)
except PageNotAnInteger:
weixin = paginator.page(1)
except EmptyPage:
weixin = paginator.page(paginator.num_pages)
for w in weixin:
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
else:
o['image'] = 'weixin.png'
o['code'] = w.code
o['weixinid'] = w.weixinid
o['organization'] = w.organization.name
# o['organization_type'] = w.organization.organizationtype.organizationtype
if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.village).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name)
elif len(w.organization.province) > 0:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-weixin.html',
{'weixin':weixin,'res': res, 'weixin_count': weixin_count,'keytype':keytype,'keyword':keyword})
@login_required
def weibo_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
weibo = None
res = []
if level == 1:
if keytype == '1':
weibo = Weibo.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
elif keytype == '2':
weibo = Weibo.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weibo = Weibo.objects.filter(organization__province=province,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province,organization__district=k.code).order_by('-created')
elif keytype == '6':
weibo = Weibo.objects.filter(organization__province=province,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
elif keytype == '2':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, code__contains=keyword).order_by('-created')
elif keytype == '2':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province,
organization__district=district,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__district=k.code).order_by('-created')
elif keytype == '6':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
weibo = Weibo.objects.filter(code__contains=keyword).order_by('-created')
elif keytype == '2':
weibo = Weibo.objects.filter(organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
weibo = Weibo.objects.filter(status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
weibo = Weibo.objects.filter(organization__district=k.code).order_by('-created')
elif keytype == '6':
weibo = Weibo.objects.filter(organization__userprofile__name__contains=keyword).order_by('-created')
weibo_count = weibo.count()
paginator = Paginator(weibo, 6)
page = int(request.GET.get('page', 1))
try:
weibo = paginator.page(page)
except PageNotAnInteger:
weibo = paginator.page(1)
except EmptyPage:
weibo = paginator.page(paginator.num_pages)
for w in weibo:
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
else:
o['image'] = 'weibo.png'
o['code'] = w.code
o['weiboid'] = w.weiboid
o['organization'] = w.organization.name
# o['organization_type'] = w.organization.organizationtype.organizationtype
if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.village).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name)
elif len(w.organization.province) > 0:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-weibo.html',
{'weibo': weibo, 'res': res, 'weibo_count': weibo_count,'keytype':keytype,'keyword':keyword})
@login_required
def toutiao_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
toutiao = None
res = []
if level == 1:
if keytype == '1':
toutiao = Toutiao.objects.filter(organization__province=province, code__contains=keyword).order_by(
'-created')
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
toutiao = Toutiao.objects.filter(organization__province=province,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province,organization__district=k.code).order_by('-created')
elif keytype == '6':
toutiao = Toutiao.objects.filter(organization__province=province,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, code__contains=keyword).order_by(
'-created')
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province,
organization__district=district,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__district=k.code).order_by('-created')
elif keytype == '6':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
toutiao = Toutiao.objects.filter(code__contains=keyword).order_by('-created')
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
toutiao = Toutiao.objects.filter(status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
toutiao = Toutiao.objects.filter(organization__district=k.code).order_by('-created')
elif keytype == '6':
toutiao = Toutiao.objects.filter(organization__userprofile__name__contains=keyword).order_by('-created')
toutiao_count = toutiao.count()
paginator = Paginator(toutiao, 6)
page = int(request.GET.get('page', 1))
try:
toutiao = paginator.page(page)
except PageNotAnInteger:
toutiao = paginator.page(1)
except EmptyPage:
toutiao = paginator.page(paginator.num_pages)
for w in toutiao:
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
else:
o['image'] = 'toutiao.png'
o['code'] = w.code
o['toutiaoid'] = w.toutiaoid
o['organization'] = w.organization.name
# o['organization_type'] = w.organization.organizationtype.organizationtype
if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.village).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name)
elif len(w.organization.province) > 0:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-toutiao.html',
{'toutiao': toutiao, 'res': res, 'toutiao_count': toutiao_count,'keytype':keytype,'keyword':keyword})
@login_required
def douyin_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
douyin = None
res = []
if level == 1:
if keytype == '1':
douyin = Douyin.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
elif keytype == '2':
douyin = Douyin.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
douyin = Douyin.objects.filter(organization__province=province,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province,organization__district=k.code).order_by('-created')
elif keytype == '6':
douyin = Douyin.objects.filter(organization__province=province,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
elif keytype == '2':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, code__contains=keyword).order_by('-created')
elif keytype == '2':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,
organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province,
organization__district=district,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=k.code).order_by('-created')
elif keytype == '6':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
douyin = Douyin.objects.filter(code__contains=keyword).order_by('-created')
elif keytype == '2':
douyin = Douyin.objects.filter(organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
douyin = Douyin.objects.filter(status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
douyin = Douyin.objects.filter(organization__district=k.code).order_by('-created')
elif keytype == '6':
douyin = Douyin.objects.filter(organization__userprofile__name__contains=keyword).order_by('-created')
douyin_count = douyin.count()
paginator = Paginator(douyin, 6)
page = int(request.GET.get('page', 1))
try:
douyin = paginator.page(page)
except PageNotAnInteger:
douyin = paginator.page(1)
except EmptyPage:
douyin = paginator.page(paginator.num_pages)
for w in douyin:
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
else:
o['image'] = 'douyin.jpg'
o['code'] = w.code
o['douyinid'] = w.douyinid
o['organization'] = w.organization.name
# o['organization_type'] = w.organization.organizationtype.organizationtype
if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.village).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name)
elif len(w.organization.province) > 0:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-douyin.html',
{'douyin': douyin, 'res': res, 'douyin_count': douyin_count,'keytype':keytype,'keyword':keyword})
@login_required
def qita_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
o = Organization.objects.get(userprofile__user_id=user.id)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
qita = None
res = []
if level == 1:
if keytype == '1':
qita = Qita.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
elif keytype == '2':
qita = Qita.objects.filter(organization__province=province, organization__name__contains=keyword).order_by(
'-created')
elif keytype == '3':
qita = Qita.objects.filter(organization__province=province,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province,organization__district=k.code).order_by('-created')
elif keytype == '6':
qita = Qita.objects.filter(organization__province=province,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 2:
if keytype == '1':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
elif keytype == '2':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by(
'-created')
elif keytype == '3':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,organization__district=k.code).order_by('-created')
elif keytype == '6':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 3:
if keytype == '1':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, code__contains=keyword).order_by('-created')
elif keytype == '2':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district, organization__name__contains=keyword).order_by(
'-created')
elif keytype == '3':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province,
organization__district=district,organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__district=k.code).order_by('-created')
elif keytype == '6':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__district=district,organization__userprofile__name__contains=keyword).order_by('-created')
elif level == 9:
if keytype == '1':
qita = Qita.objects.filter(code__contains=keyword).order_by('-created')
elif keytype == '2':
qita = Qita.objects.filter(organization__name__contains=keyword).order_by('-created')
elif keytype == '3':
qita = Qita.objects.filter(status=int(keyword)).order_by('-created')
elif keytype == '4':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__cities=k.code).order_by('-created')
elif keytype == '5':
key = Area_code_2020.objects.filter(name__contains=keyword)
for k in key:
qita = Qita.objects.filter(organization__district=k.code).order_by('-created')
elif keytype == '6':
qita = Qita.objects.filter(organization__userprofile__name__contains=keyword).order_by('-created')
qita_count = qita.count()
paginator = Paginator(qita, 6)
page = int(request.GET.get('page', 1))
try:
qita = paginator.page(page)
except PageNotAnInteger:
qita = paginator.page(1)
except EmptyPage:
qita = paginator.page(paginator.num_pages)
for w in qita:
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
else:
o['image'] = 'qita.png'
o['type'] = w.type
o['name'] = w.code
o['qitaid'] = w.qitaid
o['organization'] = w.organization.name
# o['organization_type'] = w.organization.organizationtype.organizationtype
if len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0 and len(w.organization.village) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.village).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0 and len(w.organization.town) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.town).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0 and len(
w.organization.district) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.district).name)
elif len(w.organization.province) > 0 and len(w.organization.cities) > 0:
o['administrativedivision'] = str(
Area_code_2020.objects.get(code=w.organization.province).name) + '-' + str(
Area_code_2020.objects.get(code=w.organization.cities).name)
elif len(w.organization.province) > 0:
o['administrativedivision'] = str(Area_code_2020.objects.get(code=w.organization.province).name)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-qita.html',
{'qita': qita, 'res': res, 'qita_count': qita_count,'keyword':keyword,'keytype':keytype})
@login_required
def group_init_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')
group_initer = None
user = request.user
level = Userprofile.objects.get(user_id=user.id).organization.level.level
if keytype == '1':
group_initer = Group.objects.filter(user_id=user.id, name__contains=keyword).order_by('-created')
elif keytype == '2':
group_initer = Group.objects.filter(user_id=user.id, type__type__contains=keyword).order_by('-created')
res_g_i = []
init_count = group_initer.count()
paginator = Paginator(group_initer, 6)
page = int(request.GET.get('page', 1))
try:
group_initer = paginator.page(page)
except PageNotAnInteger:
group_initer = paginator.page(1)
except EmptyPage:
group_initer = paginator.page(paginator.num_pages)
for r_g_i in group_initer:
o1 = dict()
o1['id'] = str(r_g_i.id)
if r_g_i.image:
o1['image'] = r_g_i.image.url
else:
o1['image'] = 'groupimage/danweimoren.jpg'
o1['name'] = r_g_i.name
o1['type'] = r_g_i.type
o1['admin_count'] = Group_admin.objects.filter(group_id=r_g_i.id).count()
o1['user_count'] = Group_user.objects.filter(group_id=r_g_i.id).count()
o1['status'] = r_g_i.status
res_g_i.append(o1)
return render(request, 'management/group-management-init.html',
{'group': group_initer, 'res_g_i': res_g_i, 'init_count': init_count, 'level': level,'keytype':keytype,'keyword':keyword})
@login_required
def group_admin_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
level = Userprofile.objects.get(user_id=user.id).organization.level.level
group_admin_list = []
g = None
if keytype == '1':
g = Group_admin.objects.filter(user_id=user.id, group__name__contains=keyword).order_by('-created')
elif keytype == '2':
g = Group_admin.objects.filter(user_id=user.id, group__type__type__contains=keyword).order_by('-created')
for g_a in g:
group_admin = Group.objects.get(id=g_a.group_id)
group_admin_list.append(group_admin)
res_g_a = []
admin_count = len(group_admin_list)
paginator = Paginator(group_admin_list, 6)
page = int(request.GET.get('page', 1))
try:
group_admin_list = paginator.page(page)
except PageNotAnInteger:
group_admin_list = paginator.page(1)
except EmptyPage:
group_admin_list = paginator.page(paginator.num_pages)
for r_g_a in group_admin_list:
o2 = dict()
o2['id'] = str(r_g_a.id)
if r_g_a.image:
o2['image'] = r_g_a.image.url
else:
o2['image'] = 'groupimage/danweimoren.jpg'
o2['name'] = r_g_a.name
o2['type'] = r_g_a.type
o2['admin_count'] = Group_admin.objects.filter(group_id=r_g_a.id).count()
o2['user_count'] = Group_user.objects.filter(group_id=r_g_a.id).count()
o2['status'] = r_g_a.status
res_g_a.append(o2)
return render(request, 'management/group-management-admin.html',
{'group': group_admin_list, 'res_g_a': res_g_a, 'admin_count': admin_count, 'level': level,'keytype':keytype,'keyword':keyword})
@login_required
def group_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
level = Userprofile.objects.get(user_id=user.id).organization.level.level
group_user_list = []
if keytype == '1':
g = Group_user.objects.filter(user_id=user.id, group__name__contains=keyword).order_by('-created')
elif keytype == '2':
g = Group_user.objects.filter(user_id=user.id, group__type__type__contains=keyword).order_by('-created')
for g_u in g:
group_user = Group.objects.get(id=g_u.group_id)
group_user_list.append(group_user)
res_g_u = []
user_count = len(group_user_list)
paginator = Paginator(group_user_list, 6)
page = int(request.GET.get('page', 1))
try:
group_user_list = paginator.page(page)
except PageNotAnInteger:
group_user_list = paginator.page(1)
except EmptyPage:
group_user_list = paginator.page(paginator.num_pages)
for r_g_u in group_user_list:
o3 = dict()
o3['id'] = str(r_g_u.id)
if r_g_u.image:
o3['image'] = r_g_u.image.url
else:
o3['image'] = 'groupimage/danweimoren.jpg'
o3['name'] = r_g_u.name
o3['type'] = r_g_u.type
o3['admin_count'] = Group_admin.objects.filter(group_id=r_g_u.id).count()
o3['user_count'] = Group_user.objects.filter(group_id=r_g_u.id).count()
o3['status'] = r_g_u.status
res_g_u.append(o3)
return render(request, 'management/group-management-user.html',
{'group': group_user_list, 'res_g_u': res_g_u, 'user_count': user_count, 'level': level,'keyword':keyword,'keytype':keytype})
@login_required
def group_super_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
group = None
level = Userprofile.objects.get(user_id=user.id).organization.level.level
if keytype == '1':
group = Group.objects.filter(name__contains=keyword).order_by('-created')
elif keytype == '2':
group = Group.objects.filter(type__type__contains=keyword).order_by('-created')
res_g_i = []
count = group.count()
paginator = Paginator(group, 6)
page = int(request.GET.get('page', 1))
try:
group = paginator.page(page)
except PageNotAnInteger:
group = paginator.page(1)
except EmptyPage:
group = paginator.page(paginator.num_pages)
for r_g_i in group:
o1 = dict()
o1['id'] = str(r_g_i.id)
if r_g_i.image:
o1['image'] = r_g_i.image.url
else:
o1['image'] = 'groupimage/danweimoren.jpg'
o1['name'] = r_g_i.name
o1['type'] = r_g_i.type
o1['admin_count'] = Group_admin.objects.filter(group_id=r_g_i.id).count()
o1['user_count'] = Group_user.objects.filter(group_id=r_g_i.id).count()
o1['status'] = r_g_i.status
res_g_i.append(o1)
return render(request, 'management/group-management-superuser.html',
{'group': group, 'res_g_i': res_g_i, 'count': count, 'level': level,'keyword':keyword,'keytype':keytype})
def download(request):
return render(request, 'dashboard/download-app.html')
def app_download(request):
file = open('/var/www/p3/newmediamonitoring/media/app-10.apk', 'rb')
response = HttpResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="app.apk"'
return response
# 政务新媒体的个数, 对应管理员的账号已经激活的
def xxxx(request):
# u = Userprofile.objects.filter(status='1')
weixin_count = []
weibo_count = []
toutiao_count = []
douyin_count = []
qita_count = []
# print(u.count())
# o = []
# weixin = None
# for i in u:
# o.append(i.organization_id)
# for j in o:
# if Weixin.objects.filter(organization_id=j).count() > 0:
# weixin_count.append(Weixin.objects.filter(organization_id=j))
# # # toutiao = Toutiao.objects.filter(organization_id=j)
# # weixin_count.append(weixin)
# # # toutiao_count.append(toutiao)
# #
# print(len(weixin_count),len(toutiao_count))
# # print(len(o))
# # print(len(list(set(o))))
u = Userprofile.objects.filter(status='1')
o_list = []
for i in u:
o_list.append(i.organization_id)
print(list(set(o_list)))
print(len(list(set(o_list))))
for j in list(set(o_list)):
if Weixin.objects.filter(organization_id=j).count() > 0:
weixin_count.append(Weixin.objects.filter(organization_id=j))
if Weibo.objects.filter(organization_id=j).count() > 0:
weibo_count.append(Weibo.objects.filter(organization_id=j))
if Toutiao.objects.filter(organization_id=j).count() > 0:
toutiao_count.append(Toutiao.objects.filter(organization_id=j))
if Douyin.objects.filter(organization_id=j).count() > 0:
douyin_count.append(Douyin.objects.filter(organization_id=j))
if Qita.objects.filter(organization_id=j).count() > 0:
qita_count.append(Qita.objects.filter(organization_id=j))
print(len(weixin_count), len(weibo_count), len(toutiao_count), len(douyin_count), len(qita_count))
print(int(len(weixin_count))+ len(weibo_count)+len(toutiao_count)+len(douyin_count)+ len(qita_count))