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 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): 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() 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}) 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) 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] o = Organization.objects.get(name=organization) password = str(phone)[5:] if phone: try: 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() 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) 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 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 = request.POST.get('keytype') keyword = request.POST.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 level == 2: if keytype == '1': organization = Organization.objects.filter(province=province, cities=cities, 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 level == 9: if keytype == '1': organization = Organization.objects.filter(name__contains=keyword).order_by('-created') organization_count = organization.count() for i in organization[:30]: o = dict() o['id'] = str(i.id) o['name'] = i.name o['image'] = i.image.url 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}) @login_required def weixin_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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 = [] 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 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 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 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') weixin_count = weixin.count() for w in weixin[:30]: o = dict() o['id'] = str(w.id) if w.image: o['image'] = w.image 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}) @login_required def weibo_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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 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 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 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') weibo_count = weibo.count() for w in weibo[:30]: o = dict() o['id'] = str(w.id) o['image'] = w.image 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}) @login_required def toutiao_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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 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 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 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') toutiao_count = toutiao.count() for w in toutiao[:30]: o = dict() o['id'] = str(w.id) o['image'] = w.image 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}) @login_required def douyin_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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 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 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 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') douyin_count = douyin.count() for w in douyin[:30]: o = dict() o['id'] = str(w.id) o['image'] = w.image 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}) @login_required def qita_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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 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 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 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') qita_count = qita.count() for w in qita[:30]: o = dict() o['id'] = str(w.id) o['image'] = w.image 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}) @login_required def group_init_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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() for r_g_i in group_initer[:30]: o1 = dict() o1['id'] = str(r_g_i.id) o1['image'] = r_g_i.image.url 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}) @login_required def group_admin_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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) for r_g_a in group_admin_list: o2 = dict() o2['id'] = str(r_g_a.id) o2['image'] = r_g_a.image.url 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}) @login_required def group_user_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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) for r_g_u in group_user_list[:30]: o3 = dict() o3['id'] = str(r_g_u.id) o3['image'] = r_g_u.image.url 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}) @login_required def group_super_search_by_keyword(request): keytype = request.POST.get('keytype') keyword = request.POST.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() for r_g_i in group[:30]: o1 = dict() o1['id'] = str(r_g_i.id) o1['image'] = r_g_i.image.url 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}) 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