newmediamonitoring/dashboard/views.py

1796 lines
89 KiB
Python
Raw Normal View History

2020-10-17 09:12:56 +00:00
import csv
2020-10-13 02:56:12 +00:00
import json
2020-10-13 13:33:48 +00:00
import http.client
import random
2020-11-29 13:07:59 +00:00
from django.db.models import Sum
2020-10-22 09:41:31 +00:00
from django.contrib.auth.decorators import login_required
2020-10-22 07:15:02 +00:00
from django.contrib.auth.hashers import make_password
2020-10-22 09:41:31 +00:00
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
2020-10-15 03:51:00 +00:00
from django.utils import timezone
2020-10-13 13:33:48 +00:00
import time
from urllib import parse
2020-07-27 09:38:53 +00:00
from captcha.helpers import captcha_image_url
from captcha.models import CaptchaStore
2020-09-17 08:10:13 +00:00
from dateutil import relativedelta
2020-10-13 13:33:48 +00:00
from django.conf import settings
2020-07-27 09:38:53 +00:00
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
2020-10-13 14:33:07 +00:00
from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse
2020-07-24 03:01:32 +00:00
from django.shortcuts import render
2020-07-27 09:38:53 +00:00
import datetime
2020-07-24 03:01:32 +00:00
# Create your views here.
2020-10-13 13:33:48 +00:00
from dashboard.models import Userprofile, Organization, Area_code_2020, Weixin, Weibo, Toutiao, Qita, News, Douyin, \
2021-01-07 04:04:02 +00:00
CheckCode, Group, Group_admin, Group_user, TimelinessMonitoring, Weixin_data
2020-10-13 13:33:48 +00:00
from dashboard.yunpian import YunPian
2020-10-13 14:33:07 +00:00
import os
2020-07-27 09:38:53 +00:00
2020-08-20 07:50:21 +00:00
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)
2020-09-17 08:10:13 +00:00
2020-11-18 07:48:17 +00:00
2020-11-13 16:22:22 +00:00
def home(request):
2020-11-29 13:07:59 +00:00
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()
2021-01-26 06:50:17 +00:00
return render(request, 'dashboard/home.html',
{'newmedia_count': newmedia_count, 'article_count': article_count, 'news_count': news_count})
2020-11-18 07:48:17 +00:00
2020-08-20 07:50:21 +00:00
def index(request):
2021-01-07 04:04:02 +00:00
data = []
2020-08-20 07:50:21 +00:00
weixin_count = Weixin.objects.all().count()
weibo_count = Weibo.objects.all().count()
toutiao_count = Toutiao.objects.all().count()
qita_count = Qita.objects.all().count()
2020-09-17 08:10:13 +00:00
douyin_count = Douyin.objects.all().count()
2020-09-29 02:48:26 +00:00
organization_count = Organization.objects.filter(status='1').count()
2021-01-07 04:04:02 +00:00
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)
2020-09-17 08:10:13 +00:00
return render(request, 'dashboard/index.html',
{'weixin_count': weixin_count, 'weibo_count': weibo_count, 'toutiao_count': toutiao_count,
2021-01-26 06:50:17 +00:00
'qita_count': qita_count, 'douyin_count': douyin_count, 'organization_count': organization_count,
'weixin_data': data})
2020-09-17 08:10:13 +00:00
2020-08-20 07:50:21 +00:00
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, '验证码错误')
2020-11-13 16:22:22 +00:00
return HttpResponseRedirect('/login')
2020-08-20 07:50:21 +00:00
if username is not None and password is not None:
try:
2020-08-23 04:06:04 +00:00
user = authenticate(username=username, password=password)
# user = User.objects.get(username=phone)
2020-08-20 07:50:21 +00:00
if user is not None:
if user.check_password(password):
login(request, user)
2021-02-06 11:10:00 +00:00
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'
2020-09-30 12:29:10 +00:00
return HttpResponseRedirect('/index/')
2020-08-20 07:50:21 +00:00
else:
messages.error(request, '无效的账号')
else:
messages.error(request, '账号或密码错误,请您确认账号和密码')
except:
2020-08-29 02:21:12 +00:00
messages.error(request, '账号或密码错误,请您确认账号和密码')
2020-11-20 10:41:18 +00:00
return render(request, 'dashboard/login-new.html', {'hash_key': hash_key, 'image_url': image_url})
2020-09-17 08:10:13 +00:00
2020-10-14 08:02:25 +00:00
2020-10-13 13:33:48 +00:00
def user_login_for_phone(request):
if request.method == 'GET':
2020-11-20 10:41:18 +00:00
return render(request, 'dashboard/login-for-phone-new.html')
2020-10-13 13:33:48 +00:00
elif request.method == 'POST':
p_code = request.POST.get('check_code')
phone = request.POST.get('phone')
2020-10-22 07:15:02 +00:00
results = CheckCode.objects.filter(phone=phone).count()
2020-10-14 08:02:25 +00:00
# try:
2020-10-22 07:15:02 +00:00
res = User.objects.filter(username=phone).count()
if res > 0:
messages.error(request, '您的账号已经存在,请您使用密码登录!!!')
2020-11-13 16:22:22 +00:00
return HttpResponseRedirect('/login')
2020-10-14 08:02:25 +00:00
if results > 0:
2020-10-13 13:33:48 +00:00
check_code = CheckCode.objects.get(phone_code=p_code, phone=phone)
2020-10-14 08:02:25 +00:00
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()
2020-10-22 07:15:02 +00:00
return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id))
2020-10-14 08:02:25 +00:00
else:
2020-10-22 07:15:02 +00:00
user = User(username=phone, last_login=timezone.now())
2020-10-14 08:02:25 +00:00
user.save()
2020-10-22 07:15:02 +00:00
# userprofile = Userprofile(user_id=user.id, image='default.png')
# userprofile.save()
2020-10-14 08:02:25 +00:00
u = authenticate(username=phone)
login(request, u, backend='django.contrib.auth.backends.ModelBackend')
2020-10-22 07:15:02 +00:00
return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id))
2020-10-14 08:02:25 +00:00
# if float(time.time()) - float(check_code.c_time) > 60:
# check_code.delete()
# return '验证码超时已被删除'
#
# except:
else:
messages.error(request, '请输入正确的验证码!!!')
2020-11-20 10:41:18 +00:00
return render(request, 'dashboard/login-for-phone-new.html')
2020-10-14 08:02:25 +00:00
2020-10-22 07:15:02 +00:00
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:
2020-11-18 07:48:17 +00:00
messages.error(request, '您填写的单位不存在!!!')
2020-10-22 07:15:02 +00:00
if request.POST.get('name'):
name = request.POST.get('name')
else:
2020-11-18 07:48:17 +00:00
messages.error(request, '请输入您的姓名!!!')
2020-10-22 07:15:02 +00:00
if request.POST.get('email'):
email = request.POST.get('email')
else:
2020-11-18 07:48:17 +00:00
messages.error(request, '请输入您的邮箱!!!')
2020-10-22 07:15:02 +00:00
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:
2020-11-18 07:48:17 +00:00
messages.error(request, '请输入密码')
2020-10-22 07:15:02 +00:00
confirm_password = request.POST.get('confirm_password')
if password is not None and confirm_password is not None:
if password == confirm_password:
2020-11-18 07:48:17 +00:00
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)
2020-10-22 07:15:02 +00:00
userprofile.save()
2020-11-18 07:48:17 +00:00
messages.success(request, '修改成功')
2020-10-22 07:15:02 +00:00
return render(request, 'dashboard/user-improve-personal-information.html', {'usee': user})
2020-10-13 13:33:48 +00:00
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"
2020-10-14 08:02:25 +00:00
# mobile = "18119305139"
mobile = request.POST.get('mobile')
tpl_id = 4045320
2020-09-17 08:10:13 +00:00
2020-10-14 08:02:25 +00:00
code = ""
2020-10-13 13:33:48 +00:00
for i in range(6):
ch = chr(random.randrange(ord('0'), ord('9') + 1))
2020-10-14 08:02:25 +00:00
code += ch
# tpl_value = {'#dateStart#': '10月1日', '#dateEnd#': '10日', '#type#': '微信公众号', '#name#': code}
2020-10-22 07:15:02 +00:00
tpl_value = {'#code#': code}
2020-10-14 08:02:25 +00:00
2020-10-13 13:33:48 +00:00
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()
2020-10-14 08:02:25 +00:00
try:
check_code = CheckCode.objects.get(phone=mobile)
check_code.phone_code = code
check_code.save()
except:
check_code = CheckCode(phone_code=code, phone=mobile)
check_code.save()
2020-10-13 13:33:48 +00:00
conn.close()
return response_str
2020-10-14 08:02:25 +00:00
2020-08-20 07:50:21 +00:00
def user_logout(request):
logout(request)
return HttpResponseRedirect('/')
2020-09-17 08:10:13 +00:00
2020-08-20 07:50:21 +00:00
def register(request):
username = None
email = None
password = None
confirm_password = None
name = None
2020-08-23 04:06:04 +00:00
# phone = None
2020-08-20 07:50:21 +00:00
image = None
flag = False
2020-10-13 13:33:48 +00:00
user_organization = None
2020-08-20 07:50:21 +00:00
sex = None
2020-10-22 07:15:02 +00:00
user_organization = None
2020-08-20 07:50:21 +00:00
hash_key = CaptchaStore.generate_key()
image_url = captcha_image_url(hash_key)
2020-09-29 02:48:26 +00:00
organization = Organization.objects.filter(status='1')
2020-08-20 07:50:21 +00:00
if request.method == 'POST':
if not request.POST.get('organization'):
messages.error(request, '请选择单位')
else:
o = request.POST.get('organization')
2020-10-22 07:15:02 +00:00
res = Organization.objects.filter(name=o).count()
if res > 0:
user_organization = Organization.objects.get(name=o).id
else:
2020-11-18 07:48:17 +00:00
messages.error(request, '您填写的单位不存在')
2020-08-20 07:50:21 +00:00
if not request.POST.get('name'):
messages.error(request, '请输入姓名')
else:
name = request.POST.get('name')
2020-11-20 10:41:18 +00:00
# email = request.POST.get('email')
2020-08-20 07:50:21 +00:00
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'):
2020-11-18 07:48:17 +00:00
image = '/profile/user_default.jpg'
2020-08-20 07:50:21 +00:00
else:
image = request.FILES.get('image')
2020-08-23 04:06:04 +00:00
if request.POST.get('sex') == '1':
2020-08-20 07:50:21 +00:00
sex = ''
2020-08-23 04:06:04 +00:00
elif request.POST.get('sex') == '2':
2020-08-20 07:50:21 +00:00
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:
2020-08-23 04:06:04 +00:00
messages.error(request, '对不起,您输入的电话号码已被注册')
return HttpResponseRedirect('/register/')
2020-08-20 07:50:21 +00:00
2020-11-20 10:41:18 +00:00
if username is not None and password is not None and confirm_password is not None and flag:
2020-10-22 07:15:02 +00:00
user = User.objects.create_user(username, email, password, last_login=timezone.now())
2020-08-20 07:50:21 +00:00
user.is_active = True
2020-08-23 04:06:04 +00:00
# user.is_staff = True
# user.first_name = phone
2020-10-09 01:42:05 +00:00
2020-10-14 08:02:25 +00:00
userprofile = Userprofile(name=name, image=image, user_id=user.id, organization_id=user_organization,
sex=sex, status=0)
2020-10-13 13:33:48 +00:00
2020-08-20 07:50:21 +00:00
userprofile.save()
2020-10-13 13:33:48 +00:00
user.save()
2020-08-20 07:50:21 +00:00
messages.success(request, '注册成功,请登录')
2020-11-13 16:22:22 +00:00
return HttpResponseRedirect('/login')
2020-11-20 10:41:18 +00:00
return render(request, 'dashboard/register-new.html',
2020-09-17 08:10:13 +00:00
{'hash_key': hash_key, 'image_url': image_url, 'organization': organization})
2020-08-20 07:50:21 +00:00
def get_province(request):
2020-09-17 08:10:13 +00:00
# 省
2020-10-13 02:56:12 +00:00
province = Area_code_2020.objects.filter(level=1, name='甘肃省')
2020-08-20 07:50:21 +00:00
res = []
for i in province:
2020-09-17 08:10:13 +00:00
res.append([i.code, i.name, i.level, i.pcode])
return JsonResponse({"province": res})
2020-08-20 07:50:21 +00:00
def get_city(request):
code = request.GET.get('code')
2020-09-17 08:10:13 +00:00
# 市
2020-08-20 07:50:21 +00:00
cities = Area_code_2020.objects.filter(pcode=code)
res = []
for i in cities:
2020-09-17 08:10:13 +00:00
res.append([i.code, i.name, i.level, i.pcode])
2020-08-20 07:50:21 +00:00
return JsonResponse({"city": res})
2020-09-17 08:10:13 +00:00
2020-08-20 07:50:21 +00:00
def get_district(request):
code = request.GET.get('code')
2020-09-17 08:10:13 +00:00
# 县
2020-08-20 07:50:21 +00:00
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})
2020-09-17 08:10:13 +00:00
2020-08-20 07:50:21 +00:00
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})
2020-09-17 08:10:13 +00:00
2020-08-20 07:50:21 +00:00
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})
2020-09-17 08:10:13 +00:00
2020-09-13 06:06:21 +00:00
2020-10-13 02:56:12 +00:00
def get_organization(request):
2020-10-13 06:46:15 +00:00
keywords = request.GET.get('keyword')
if len(keywords) != 0:
2020-10-13 10:13:08 +00:00
o = Organization.objects.filter(Q(name__contains=keywords))[:10]
topten_list = []
for i in o:
d = dict()
2020-10-13 13:33:48 +00:00
d['id'] = str(i.id)
2020-10-13 10:13:08 +00:00
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)
2020-10-13 06:46:15 +00:00
return render(request, 'dashboard/results_by_keywords.html', {'topten_list': topten_list})
2020-10-13 14:33:07 +00:00
def wechat_verify(request):
2020-10-13 14:42:50 +00:00
return HttpResponse("11833201729252855821")
2020-10-17 09:12:56 +00:00
2020-10-22 07:15:02 +00:00
2020-10-17 09:12:56 +00:00
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]
o = Organization.objects.get(name=organization)
password = str(phone)[5:]
if phone:
try:
2021-02-06 06:50:55 +00:00
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:
Userprofile.objects.filter(user__username=phone).update(organization_id=o.id)
2020-10-17 09:12:56 +00:00
except:
2021-04-11 14:00:19 +00:00
pass
2020-10-22 07:15:02 +00:00
return HttpResponse('ok')
2020-11-18 07:48:17 +00:00
2020-10-22 09:41:31 +00:00
@login_required
def user_search_by_keyword(request):
2021-03-30 03:09:04 +00:00
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')
2020-10-27 13:04:28 +00:00
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
2021-03-30 03:09:04 +00:00
2020-10-27 13:04:28 +00:00
userpaginator = None
if level == 1:
if keytype == '1':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province)
2020-10-27 13:04:28 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province)
2021-03-30 03:09:04 +00:00
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)
2020-10-27 13:04:28 +00:00
elif level == 2:
if keytype == '1':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
2020-10-27 13:04:28 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities)
2021-03-30 03:09:04 +00:00
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)
2020-10-27 13:04:28 +00:00
elif level == 3:
if keytype == '1':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
2020-10-27 13:04:28 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword,
userprofile__organization__province=province,
userprofile__organization__cities=cities,
userprofile__organization__district=district)
2021-03-30 03:09:04 +00:00
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)
2020-10-27 13:04:28 +00:00
elif level == 9:
if keytype == '1':
2020-10-27 13:38:02 +00:00
userpaginator = Userprofile.objects.filter(name__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '2':
2020-10-27 13:38:02 +00:00
userpaginator = Userprofile.objects.filter(organization__name__contains=keyword)
2021-03-30 03:09:04 +00:00
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)
user_count = userpaginator.count()
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)
2020-10-27 13:04:28 +00:00
userallinfo = []
2021-03-30 03:09:04 +00:00
for u in userpaginator:
2020-10-22 09:41:31 +00:00
o = dict()
o['id'] = str(u.id)
2020-11-17 01:03:09 +00:00
o['user_id'] = str(u.user_id)
2020-10-27 13:04:28 +00:00
if u.image:
o['image'] = u.image
2021-03-28 07:43:18 +00:00
else:
o['image'] = '/profile/user_default.jpg'
2020-10-22 09:41:31 +00:00
o['name'] = u.name
2020-10-27 13:04:28 +00:00
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',
2021-03-30 03:09:04 +00:00
{'userallinfo': userallinfo, 'userpaginator': userpaginator, 'user_count': user_count,'keytype':keytype,'keyword':keyword})
2020-11-18 07:48:17 +00:00
2020-10-22 09:41:31 +00:00
2020-10-27 13:04:28 +00:00
@login_required
def news_search_by_keyword(request):
keytype = request.POST.get('keytype')
keyword = request.POST.get('keyword')
news = None
if keytype == '1':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='0', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='1', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '3':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='2', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '4':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='3', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '5':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='4', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '6':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='5', title__contains=keyword)
2020-10-27 13:04:28 +00:00
elif keytype == '7':
2020-11-18 07:48:17 +00:00
news = News.objects.filter(type='6', title__contains=keyword)
elif keytype == '0':
news = News.objects.filter(title__contains=keyword)
2020-10-27 13:04:28 +00:00
news_list = []
news_count = news.count()
2020-10-27 13:38:02 +00:00
for n in news[:30]:
2020-10-27 13:04:28 +00:00
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})
2020-11-18 07:48:17 +00:00
2020-10-27 13:04:28 +00:00
@login_required
def organization_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
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':
2020-11-18 07:48:17 +00:00
organization = Organization.objects.filter(province=province, name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 2:
if keytype == '1':
2020-11-18 07:48:17 +00:00
organization = Organization.objects.filter(province=province, cities=cities,
name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 3:
if keytype == '1':
2020-11-18 07:48:17 +00:00
organization = Organization.objects.filter(province=province, cities=cities, district=district,
name__contains=keyword).order_by(
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 9:
if keytype == '1':
organization = Organization.objects.filter(name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
organization_count = organization.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 13:38:02 +00:00
o = dict()
o['id'] = str(i.id)
o['name'] = i.name
2021-03-28 07:43:18 +00:00
if i.image:
o['image'] = i.image.url
else:
o['image'] = 'danweimoren.jpg'
2020-10-27 13:38:02 +00:00
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)
2020-11-18 07:48:17 +00:00
return render(request, 'management/organization-management.html',
2021-03-28 07:43:18 +00:00
{"organization": organization, 'res': res, 'organization_count': organization_count,'keytype':keytype,'keyword':keyword})
2020-11-18 07:48:17 +00:00
2020-10-27 13:38:02 +00:00
@login_required
def weixin_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
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 = []
if level == 1:
if keytype == '1':
2020-11-18 07:48:17 +00:00
weixin = Weixin.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
2020-10-27 13:38:02 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
weixin = Weixin.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 2:
if keytype == '1':
2020-11-18 07:48:17 +00:00
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by(
'-created')
2020-10-27 13:38:02 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by(
2020-10-27 13:38:02 +00:00
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 3:
if keytype == '1':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, code__contains=keyword).order_by(
'-created')
2020-10-27 13:38:02 +00:00
elif keytype == '2':
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district,
organization__name__contains=keyword).order_by(
2020-10-27 13:38:02 +00:00
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
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')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
weixin_count = weixin.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 13:38:02 +00:00
o = dict()
o['id'] = str(w.id)
if w.image:
o['image'] = w.image
2021-03-28 07:43:18 +00:00
else:
o['image'] = 'weixin.png'
2020-10-27 13:38:02 +00:00
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)
2020-11-18 07:48:17 +00:00
return render(request, 'management/newmedia-management-edit-weixin.html',
2021-03-28 07:43:18 +00:00
{'weixin':weixin,'res': res, 'weixin_count': weixin_count,'keytype':keytype,'keyword':keyword})
2020-11-18 07:48:17 +00:00
2020-10-27 13:38:02 +00:00
@login_required
def weibo_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
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':
2020-11-18 07:48:17 +00:00
weibo = Weibo.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
2020-10-27 13:38:02 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
weibo = Weibo.objects.filter(organization__province=province,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 2:
2020-10-27 23:34:23 +00:00
if keytype == '1':
2020-11-18 07:48:17 +00:00
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 3:
if keytype == '1':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
weibo_count = weibo.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o = dict()
o['id'] = str(w.id)
2021-03-28 07:43:18 +00:00
if w.image:
o['image'] = w.image
else:
o['image'] = 'weibo.png'
2020-10-27 23:34:23 +00:00
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)
2020-11-18 07:48:17 +00:00
return render(request, 'management/newmedia-management-edit-weibo.html',
2021-03-28 07:43:18 +00:00
{'weibo': weibo, 'res': res, 'weibo_count': weibo_count,'keytype':keytype,'keyword':keyword})
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def toutiao_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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':
2020-11-18 07:48:17 +00:00
toutiao = Toutiao.objects.filter(organization__province=province, code__contains=keyword).order_by(
'-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province,
2020-11-18 07:48:17 +00:00
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 2:
if keytype == '1':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 3:
if keytype == '1':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, code__contains=keyword).order_by(
'-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
toutiao_count = toutiao.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o = dict()
o['id'] = str(w.id)
2021-03-28 07:43:18 +00:00
if w.image:
o['image'] = w.image
else:
o['image'] = 'toutiao.png'
2020-10-27 23:34:23 +00:00
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)
2020-11-18 07:48:17 +00:00
return render(request, 'management/newmedia-management-edit-toutiao.html',
2021-03-28 07:43:18 +00:00
{'toutiao': toutiao, 'res': res, 'toutiao_count': toutiao_count,'keytype':keytype,'keyword':keyword})
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def douyin_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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,
2020-11-18 07:48:17 +00:00
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 2:
if keytype == '1':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 3:
2020-10-27 23:34:23 +00:00
if keytype == '1':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district,
organization__name__contains=keyword).order_by('-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 13:38:02 +00:00
elif level == 9:
2020-10-27 23:34:23 +00:00
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')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
douyin_count = douyin.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o = dict()
o['id'] = str(w.id)
2021-03-28 07:43:18 +00:00
if w.image:
o['image'] = w.image
else:
o['image'] = 'douyin.jpg'
2020-10-27 23:34:23 +00:00
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',
2021-03-28 07:43:18 +00:00
{'douyin': douyin, 'res': res, 'douyin_count': douyin_count,'keytype':keytype,'keyword':keyword})
2020-10-27 23:34:23 +00:00
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def qita_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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':
2020-11-18 07:48:17 +00:00
qita = Qita.objects.filter(organization__province=province, code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
qita = Qita.objects.filter(organization__province=province, organization__name__contains=keyword).order_by(
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 2:
if keytype == '1':
2020-11-18 07:48:17 +00:00
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
organization__name__contains=keyword).order_by(
2020-10-27 23:34:23 +00:00
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
elif level == 3:
if keytype == '1':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, code__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,
2020-11-18 07:48:17 +00:00
organization__district=district, organization__name__contains=keyword).order_by(
'-created')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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')
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
qita_count = qita.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o = dict()
o['id'] = str(w.id)
2021-03-28 07:43:18 +00:00
if w.image:
o['image'] = w.image
else:
o['image'] = 'qita.png'
2020-10-27 23:34:23 +00:00
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)
2020-11-18 07:48:17 +00:00
return render(request, 'management/newmedia-management-edit-qita.html',
2021-03-28 07:43:18 +00:00
{'qita': qita, 'res': res, 'qita_count': qita_count,'keyword':keyword,'keytype':keytype})
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def group_init_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
group_initer = None
user = request.user
level = Userprofile.objects.get(user_id=user.id).organization.level.level
if keytype == '1':
2020-11-18 07:48:17 +00:00
group_initer = Group.objects.filter(user_id=user.id, name__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
group_initer = Group.objects.filter(user_id=user.id, type__type__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
res_g_i = []
init_count = group_initer.count()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o1 = dict()
o1['id'] = str(r_g_i.id)
2021-03-28 07:43:18 +00:00
if r_g_i.image:
o1['image'] = r_g_i.image.url
else:
o1['image'] = 'groupimage/danweimoren.jpg'
2020-10-27 23:34:23 +00:00
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',
2021-03-28 07:43:18 +00:00
{'group': group_initer, 'res_g_i': res_g_i, 'init_count': init_count, 'level': level,'keytype':keytype,'keyword':keyword})
2020-10-27 23:34:23 +00:00
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def group_admin_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
user = request.user
level = Userprofile.objects.get(user_id=user.id).organization.level.level
group_admin_list = []
g = None
if keytype == '1':
2020-11-18 07:48:17 +00:00
g = Group_admin.objects.filter(user_id=user.id, group__name__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
g = Group_admin.objects.filter(user_id=user.id, group__type__type__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
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)
2021-03-28 07:43:18 +00:00
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)
2020-10-27 23:34:23 +00:00
for r_g_a in group_admin_list:
o2 = dict()
o2['id'] = str(r_g_a.id)
2021-03-28 07:43:18 +00:00
if r_g_a.image:
o2['image'] = r_g_a.image.url
else:
o2['image'] = 'groupimage/danweimoren.jpg'
2020-10-27 23:34:23 +00:00
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',
2021-03-28 07:43:18 +00:00
{'group': group_admin_list, 'res_g_a': res_g_a, 'admin_count': admin_count, 'level': level,'keytype':keytype,'keyword':keyword})
2020-10-27 23:34:23 +00:00
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def group_user_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
user = request.user
level = Userprofile.objects.get(user_id=user.id).organization.level.level
group_user_list = []
if keytype == '1':
2020-11-18 07:48:17 +00:00
g = Group_user.objects.filter(user_id=user.id, group__name__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
elif keytype == '2':
2020-11-18 07:48:17 +00:00
g = Group_user.objects.filter(user_id=user.id, group__type__type__contains=keyword).order_by('-created')
2020-10-27 23:34:23 +00:00
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)
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o3 = dict()
o3['id'] = str(r_g_u.id)
2021-03-28 07:43:18 +00:00
if r_g_u.image:
o3['image'] = r_g_u.image.url
else:
o3['image'] = 'groupimage/danweimoren.jpg'
2020-10-27 23:34:23 +00:00
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',
2021-03-28 07:43:18 +00:00
{'group': group_user_list, 'res_g_u': res_g_u, 'user_count': user_count, 'level': level,'keyword':keyword,'keytype':keytype})
2020-10-27 23:34:23 +00:00
2020-11-18 07:48:17 +00:00
2020-10-27 23:34:23 +00:00
@login_required
def group_super_search_by_keyword(request):
2021-03-28 07:43:18 +00:00
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')
2020-10-27 23:34:23 +00:00
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()
2021-03-28 07:43:18 +00:00
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:
2020-10-27 23:34:23 +00:00
o1 = dict()
o1['id'] = str(r_g_i.id)
2021-03-28 07:43:18 +00:00
if r_g_i.image:
o1['image'] = r_g_i.image.url
else:
o1['image'] = 'groupimage/danweimoren.jpg'
2020-10-27 23:34:23 +00:00
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',
2021-03-28 07:43:18 +00:00
{'group': group, 'res_g_i': res_g_i, 'count': count, 'level': level,'keyword':keyword,'keytype':keytype})
2020-11-13 16:22:22 +00:00
2020-11-18 07:48:17 +00:00
2020-11-20 10:41:18 +00:00
def download(request):
2020-11-29 13:07:59 +00:00
return render(request, 'dashboard/download-app.html')
2020-11-13 16:22:22 +00:00
def app_download(request):
2020-11-13 16:33:36 +00:00
file = open('/var/www/p3/newmediamonitoring/media/app-10.apk', 'rb')
2020-11-13 16:22:22 +00:00
response = HttpResponse(file)
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="app.apk"'
2020-11-18 07:48:17 +00:00
return response
2021-01-26 06:50:17 +00:00
# 政务新媒体的个数, 对应管理员的账号已经激活的
def xxxx(request):
# u = Userprofile.objects.filter(status='1')
weixin_count = []
weibo_count = []
toutiao_count = []
douyin_count = []
qita_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)
# #
u = Userprofile.objects.filter(status='1')
o_list = []
for i in u:
o_list.append(i.organization_id)
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))