newmediamonitoring1/management/views.py

1242 lines
59 KiB
Python

import json
from django.contrib import messages
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from dashboard.models import Userprofile, Group, Organization, Level, Organizationtype, Area_code_2020, Weixin, Weibo, \
Toutiao, Qita, Group_type, Group_admin, Group_user, News, Douyin
def user_management(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
userpaginator = None
if level == 1:
userpaginator = User.objects.filter(userprofile__organization__province=province).order_by('-date_joined')
elif level == 2:
userpaginator = User.objects.filter(userprofile__organization__province=province,userprofile__organization__cities=cities).order_by('-date_joined')
elif level == 3:
userpaginator = User.objects.filter(userprofile__organization__province=province,
userprofile__organization__cities=cities,userprofile__organization__district=district).order_by('-date_joined')
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)
userallinfo = []
for u in userpaginator:
o = dict()
o['id'] = str(u.id)
o['image'] = u.userprofile_set.get(user_id=u.id).image
o['name'] = u.userprofile_set.get(user_id=u.id).name
o['phone'] = u.username
o['organization'] = u.userprofile_set.get(user_id=u.id).organization.name
o['type'] = u.userprofile_set.get(user_id=u.id).organization.organizationtype.organizationtype
organization_id = Userprofile.objects.get(user_id=u.id).organization_id
print(organization_id)
o['administrativedivision'] = str(str(Organization.objects.get(id=organization_id).province) + '-' + str(
Organization.objects.get(id=organization_id).cities) + '-' + str(
Organization.objects.get(id=organization_id).district) + '-' + str(
Organization.objects.get(id=organization_id).town) + '-' + str(
Organization.objects.get(id=organization_id).village)).replace('None', '')
userallinfo.append(o)
print(userallinfo)
return render(request, 'management/user-management.html',
{'userallinfo': userallinfo, 'userpaginator': userpaginator})
def user_delete(request, pk):
user = User.objects.get(id=pk)
user.delete()
return HttpResponseRedirect('/management/user/management/')
def user_update(request, pk):
user = User.objects.get(id=pk)
userprofile = Userprofile.objects.get(user_id=user.id)
organization = Organization.objects.all()
if request.method == 'POST':
organization_id = request.POST.get('organization')
name = request.POST.get('name')
email = request.POST.get('email')
username = request.POST.get('username')
image = request.FILES.get('image')
passwordold = request.POST.get('passwordold')
passwordnew = request.POST.get('passwordnew')
confirm_password = request.POST.get('confirm_password')
if passwordold is not None and passwordnew is not None and confirm_password is not None:
if passwordnew == confirm_password:
user.email = email
user.username = username
user.password = make_password(passwordnew)
userprofile.organization_id = organization_id
userprofile.name = name
if image is not None:
userprofile.image = image
user.save()
userprofile.save()
messages.success(request, "修改成功")
return HttpResponseRedirect("/")
else:
messages.error(request, '两次输入密码不一致')
return HttpResponseRedirect('/management/user/update/%s/' % (pk))
else:
user.email = email
user.username = username
userprofile.organization_id = organization_id
userprofile.name = name
if image is not None:
userprofile.image = image
user.save()
userprofile.save()
messages.success(request, "修改成功")
return HttpResponseRedirect("/")
return render(request, 'management/user-management-update.html',
{'usee': user, 'userprofile': userprofile, 'organization': organization})
def group_management_init(request):
user = request.user
# 创建的矩阵
group_initer = Group.objects.filter(user_id=user.id)
print(group_initer)
paginator = Paginator(group_initer, 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)
res_g_i = []
for r_g_i in group:
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, 'res_g_i': res_g_i})
def group_management_admin(request):
# 管理的矩阵
user = request.user
group_admin_list = []
for g_a in Group_admin.objects.filter(user_id=user.id):
group_admin = Group.objects.get(id=g_a.group_id)
group_admin_list.append(group_admin)
paginator = Paginator(group_admin_list, 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)
res_g_a = []
for r_g_a in group:
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, 'res_g_a': res_g_a})
def group_management_user(request):
# 加入的矩阵
user = request.user
group_user_list = []
for g_u in Group_user.objects.filter(user_id=user.id):
group_user = Group.objects.get(id=g_u.group_id)
group_user_list.append(group_user)
paginator = Paginator(group_user_list, 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)
res_g_u = []
for r_g_u in group:
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, 'res_g_u': res_g_u})
def group_update(request, pk):
group = Group.objects.get(id=pk)
GROUP_STATUS_CHOICES = Group.GROUP_STATUS_CHOICES
group_status_choices_list = []
for g in GROUP_STATUS_CHOICES:
group_status_choices_list.append(list(g)[1])
group_type = Group_type.objects.all()
group_admin = Group_admin.objects.filter(group_id=pk)
print(pk)
g_a_list = []
for g_a in group_admin:
o = dict()
o['id'] = str(g_a.id)
o['image'] = Userprofile.objects.get(user_id=g_a.user.id).image.url
o['username'] = g_a.user.username
o['name'] = Userprofile.objects.get(user_id=g_a.user.id).name
o['organization'] = Userprofile.objects.get(user_id=g_a.user.id).organization.name
o['administrativedivision'] = str(g_a.group.province) + '-' + str(g_a.group.cities) + '-' + str(
g_a.group.district) + '-' + str(g_a.group.town) + '-' + str(g_a.group.village)
g_a_list.append(o)
group_user = Group_user.objects.filter(group_id=pk)
g_u_list = []
for g_u in group_user:
i = dict()
i['id'] = str(g_u.id)
i['image'] = Userprofile.objects.get(user_id=g_u.user.id).image.url
i['username'] = g_u.user.username
i['name'] = Userprofile.objects.get(user_id=g_u.user.id).name
i['organization'] = Userprofile.objects.get(user_id=g_u.user.id).organization.name
i['administrativedivision'] = str(g_u.group.province) + '-' + str(g_u.group.cities) + '-' + str(
g_u.group.district) + '-' + str(g_u.group.town) + '-' + str(g_u.group.village)
g_u_list.append(i)
if request.method == 'POST':
name = request.POST.get('name')
presentation = request.POST.get('presentation')
image = request.FILES.get('image')
type = request.POST.get('type')
status = request.POST.get('status')
province = request.POST.get('province')
print(str(province) + "66666666666666666666666666")
if province != '' and province.isdigit():
province_r = Area_code_2020.objects.get(code=province).name
else:
province_r = province
city = request.POST.get('city')
if city != '' and city.isdigit():
city_r = Area_code_2020.objects.get(code=city).name
else:
city_r = city
district = request.POST.get('district')
if district != '' and district.isdigit():
district_r = Area_code_2020.objects.get(code=district).name
else:
district_r = district
town = request.POST.get('town')
if town != '' and town.isdigit():
town_r = Area_code_2020.objects.get(code=town).name
else:
town_r = town
village = request.POST.get('village')
if village != '' and village.isdigit():
village_r = Area_code_2020.objects.get(code=village).name
else:
village_r = village
if image is not None:
Group.objects.filter(id=pk).update(name=name, presentation=presentation, type_id=type, status=status,
province=province_r, cities=city_r, district=district_r, town=town_r,
village=village_r)
g = Group.objects.get(id=pk)
g.image = image
g.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/group/management/init/')
else:
Group.objects.filter(id=pk).update(name=name, presentation=presentation, type_id=type, status=status,
province=province_r, cities=city_r, district=district_r, town=town_r,
village=village_r)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/group/management/init/')
return render(request, 'management/group-management-update.html',
{'group': group, 'group_status_choices_list': group_status_choices_list, 'group_type': group_type,
'g_a_list': g_a_list, 'g_u_list': g_u_list})
def group_create(request):
user = request.user
GROUP_STATUS_CHOICES = Group.GROUP_STATUS_CHOICES
group_status_choices_list = []
for g in GROUP_STATUS_CHOICES:
group_status_choices_list.append(list(g)[1])
group_type = Group_type.objects.all()
if request.method == 'POST':
name = request.POST.get('name')
presentation = request.POST.get('presentation')
image = request.FILES.get('image')
type = request.POST.get('type')
status = request.POST.get('status')
province = request.POST.get('province')
if province != '':
province_r = Area_code_2020.objects.get(code=province).name
else:
messages.error(request, '请选择行政区划')
return HttpResponseRedirect('/management/organization/create/')
city = request.POST.get('city')
if city != '':
city_r = Area_code_2020.objects.get(code=city).name
else:
city_r = city
district = request.POST.get('district')
if district != '':
district_r = Area_code_2020.objects.get(code=district).name
else:
district_r = district
town = request.POST.get('town')
if town != '':
town_r = Area_code_2020.objects.get(code=town).name
else:
town_r = town
village = request.POST.get('village')
if village != '':
village_r = Area_code_2020.objects.get(code=village).name
else:
village_r = village
print(name, presentation, image, type, status, province, city, district, town, village)
if name is not None:
group = Group(name=name, presentation=presentation, image=image, type_id=type, status=status,
province=province_r, cities=city_r, district=district_r, town=town_r, village=village_r,user_id=user.id)
group.save()
messages.success(request, '添加成功')
return render(request,'management/add-group-admin-and-user.html',{'group':group})
else:
messages.error(request, '矩阵名不能为空')
# return HttpResponseRedirect('/management/group/management/')
return render(request, 'management/group-management-create.html',
{'group_status_choices_list': group_status_choices_list, 'group_type': group_type})
def group_admin_create(request, pk):
if request.method == 'POST':
user = request.POST.get("user")
print(user)
results = Group_admin.objects.filter(user_id=user, group_id=pk).count()
if results != 0:
messages.success(request, "该管理员已经存在")
return HttpResponseRedirect('/management/group/update/%s/' % (pk))
group_admin = Group_admin(user_id=user, group_id=pk)
group_admin.save()
messages.success(request, "添加成功")
return HttpResponseRedirect('/management/group/update/%s/' % (pk))
group = Group.objects.get(id=pk).name
user = User.objects.all()
return render(request, 'management/group-admin-create.html', {'usee': user, 'group': group, 'pk': pk})
def group_admin_delete(request, pk, group_pk):
group_admin = Group_admin.objects.get(id=pk)
group_admin.delete()
messages.success(request, '删除成功')
return HttpResponseRedirect('/management/group/update/%s/' % (group_pk))
def group_user_create(request, pk):
if request.method == 'POST':
user = request.POST.get('user')
results = Group_user.objects.filter(user_id=user, group_id=pk).count()
if results != 0:
messages.success(request, "该成员已经存在")
return HttpResponseRedirect('/management/group/update/%s/' % (pk))
group_user = Group_user(user_id=user, group_id=pk)
group_user.save()
messages.success(request, '添加成功')
return HttpResponseRedirect('/management/group/update/%s' % (pk))
group = Group.objects.get(id=pk).name
user = User.objects.all()
return render(request, 'management/group-user-create.html', {'usee': user, 'group': group, 'pk': pk})
def group_user_delete(request, pk, group_pk):
group_user = Group_user.objects.get(id=pk)
group_user.delete()
messages.success(request, '删除成功')
return HttpResponseRedirect('/management/group/update/%s/' % (group_pk))
def group_delete(request, pk):
group = Group.objects.get(id=pk)
group.delete()
messages.success(request, '删除成功')
return HttpResponseRedirect('/management/group/management/')
def organization_management(request):
user = request.user
o = Organization.objects.get(userprofile__user_id=user.id)
print(o)
level = o.level.level
province = o.province
cities = o.cities
district = o.district
print(level, province, cities, district)
organization = None
if level == 1:
organization = Organization.objects.filter(province=province).order_by('-created')
elif level == 2:
organization = Organization.objects.filter(province=province, cities=cities).order_by('-created')
elif level == 3:
organization = Organization.objects.filter(province=province, cities=cities, district=district).order_by(
'-created')
if organization is not None:
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)
res = []
for i in organization:
o = dict()
o['id'] = str(i.id)
o['name'] = i.name
o['image'] = i.image.url
o['organizationtype'] = i.organizationtype.organizationtype
if len(i.province) > 0 and len(i.cities) > 0 and len(i.district) > 0 and len(i.town) > 0 and len(i.village) > 0:
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 len(i.province) > 0 and len(i.cities) > 0 and len(i.district) > 0 and len(i.town) > 0:
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 len(i.province) > 0 and len(i.cities) > 0 and len(i.district) > 0:
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 len(i.province) > 0 and len(i.cities) > 0 :
o['administrativedivision'] = str(Area_code_2020.objects.get(code=i.province).name) + '-' + str(
Area_code_2020.objects.get(code=i.cities).name)
elif len(i.province) > 0:
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})
def organization_delete(request, pk):
organization = Organization.objects.get(id=pk)
organization.delete()
messages.success(request, '删除成功')
return HttpResponseRedirect('/management/organization/management/')
def organization_update(request, pk):
organization = Organization.objects.get(id=pk)
organizationtype = Organizationtype.objects.all()
level = Level.objects.all()
if request.method == 'POST':
name = request.POST.get('name')
image = request.FILES.get('image')
organizationtype = request.POST.get('organizationtype')
province = request.POST.get('province')
level_id = request.POST.get('level')
if province != '' and province.isdigit():
province_r = province
else:
province_r = Area_code_2020.objects.get(name=province).code
city = request.POST.get('city')
if city != '' and city.isdigit():
city_r = city
else:
city_r = Area_code_2020.objects.get(name=city).code
district = request.POST.get('district')
if district != '' and district.isdigit():
district_r = district
else:
district_r = Area_code_2020.objects.get(name=district).code
town = request.POST.get('town')
if town != '' and town.isdigit():
town_r = town
else:
town_r = Area_code_2020.objects.get(name=town).code
village = request.POST.get('village')
if village != '' and village.isdigit():
village_r = village
else:
village_r = Area_code_2020.objects.get(name=village).code
if name is not None:
if image is not None:
Organization.objects.filter(id=pk).update(name=name, organizationtype_id=organizationtype,
province=province_r, cities=city_r, district=district_r,
town=town_r, village=village_r,level_id=level_id)
o = Organization.objects.get(id=pk)
o.image = image
o.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/organization/management/')
else:
Organization.objects.filter(id=pk).update(name=name, organizationtype_id=organizationtype,
province=province_r, cities=city_r, district=district_r,
town=town_r, village=village_r,level_id=level_id)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/organization/management/')
return render(request, 'management/organization-management-update.html',
{'organization': organization, 'organizationtype': organizationtype,'level':level})
def organization_create(request):
organizationtype = Organizationtype.objects.all()
level = Level.objects.all()
if request.method == 'POST':
name = request.POST.get('name')
image = request.FILES.get('image')
organizationtype = request.POST.get('organizationtype')
level_id = request.POST.get('level_id')
province = request.POST.get('province')
if province != '':
province = province
else:
messages.error(request, '请选择行政区划')
return HttpResponseRedirect('/management/organization/create/')
city = request.POST.get('city')
district = request.POST.get('district')
town = request.POST.get('town')
village = request.POST.get('village')
if name is not None:
organization = Organization(name=name, image=image, organizationtype_id=organizationtype,
province=province, cities=city, district=district, town=town,
village=village,level_id=level_id)
organization.save()
messages.success(request, '添加成功')
else:
messages.error(request, '单位名不能为空')
return HttpResponseRedirect('/management/organization/management/')
return render(request, 'management/organization-management-create.html', {'organizationtype': organizationtype,'level':level})
def newmedia_management_create_menu(request):
return render(request, 'management/newmedia-management-create-menu.html')
def newmedia_management_create_weixin(request):
WEIXIN_STATUS_CHOICES = Weixin.NEWMEDIA_STATUS_CHOICES
weixin_status_choices_list = []
for w in WEIXIN_STATUS_CHOICES:
weixin_status_choices_list.append(list(w)[1])
organization = Organization.objects.all().order_by('-name')
if request.method == 'POST':
code = request.POST.get('code')
weixinid = request.POST.get('weixinid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
weixin = Weixin(code=code, weixinid=weixinid, alias=alias, image=image,
organization_id=organization, status=status)
weixin.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/weixin/')
else:
weixin = Weixin(code=code, weixinid=weixinid, alias=alias, image='weixin.png',
organization_id=organization, status=status)
weixin.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/weixin/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-create-weixin.html',
{'weixin_status_choices_list': weixin_status_choices_list, "organization": organization})
else:
messages.success(request, "微信公众号不能为空")
return render(request, 'management/newmedia-management-create-weixin.html',
{'weixin_status_choices_list': weixin_status_choices_list, "organization": organization})
return render(request, 'management/newmedia-management-create-weixin.html',
{'weixin_status_choices_list': weixin_status_choices_list, "organization": organization})
def newmedia_management_create_weibo(request):
WEIBO_STATUS_CHOICES = Weibo.NEWMEDIA_STATUS_CHOICES
weibo_status_choices_list = []
for w in WEIBO_STATUS_CHOICES:
weibo_status_choices_list.append(list(w)[1])
organization = Organization.objects.all().order_by('-name')
if request.method == 'POST':
code = request.POST.get('code')
weiboid = request.POST.get('weiboid')
print(str(weiboid) + "11111111111111111111111111111111111111")
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
weibo = Weibo(code=code, weiboid=weiboid, alias=alias, image=image,
organization_id=organization, status=status)
weibo.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/weibo/')
else:
weibo = Weibo(code=code, weiboid=weiboid, alias=alias, image='weibo.png',
organization_id=organization, status=status)
weibo.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/weibo/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-create-weibo.html',
{'weibo_status_choices_list': weibo_status_choices_list, "organization": organization})
else:
messages.success(request, "微博号不能为空")
return render(request, 'management/newmedia-management-create-weibo.html',
{'weixin_status_choices_list': weibo_status_choices_list, "organization": organization})
return render(request, 'management/newmedia-management-create-weibo.html',
{'weibo_status_choices_list': weibo_status_choices_list, "organization": organization})
def newmedia_management_create_toutiao(request):
TOUTIAO_STATUS_CHOICES = Toutiao.NEWMEDIA_STATUS_CHOICES
toutiao_status_choices_list = []
for w in TOUTIAO_STATUS_CHOICES:
toutiao_status_choices_list.append(list(w)[1])
organization = Organization.objects.all().order_by('-name')
if request.method == 'POST':
code = request.POST.get('code')
toutiaoid = request.POST.get('toutiaoid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
toutiao = Toutiao(code=code, toutiaoid=toutiaoid, alias=alias, image=image,
organization_id=organization, status=status)
toutiao.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/toutiao/')
else:
toutiao = Toutiao(code=code, toutiaoid=toutiaoid, alias=alias, image='toutiao.png',
organization_id=organization, status=status)
toutiao.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/toutiao/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-create-toutiao.html',
{'toutiao_status_choices_list': toutiao_status_choices_list,
"organization": organization})
else:
messages.success(request, "头条号不能为空")
return render(request, 'management/newmedia-management-create-toutiao.html',
{'toutiao_status_choices_list': toutiao_status_choices_list, "organization": organization})
return render(request, 'management/newmedia-management-create-toutiao.html',
{'toutiao_status_choices_list': toutiao_status_choices_list, "organization": organization})
def newmedia_management_create_douyin(request):
DOUYIN_STATUS_CHOICES = Douyin.NEWMEDIA_STATUS_CHOICES
douyin_status_choices_list = []
for w in DOUYIN_STATUS_CHOICES:
douyin_status_choices_list.append(list(w)[1])
print(douyin_status_choices_list)
organization = Organization.objects.all().order_by('-name')
if request.method == 'POST':
code = request.POST.get('code')
douyinid = request.POST.get('douyinid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
douyin = Douyin(code=code, douyinid=douyinid, alias=alias, image=image,
organization_id=organization, status=status)
douyin.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/douyin/')
else:
douyin = Douyin(code=code, douyinid=douyinid, alias=alias, image='douyin.png',
organization_id=organization, status=status)
douyin.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/douyin/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-create-douyin.html',
{'douyin_status_choices_list': douyin_status_choices_list,
"organization": organization})
else:
messages.success(request, "抖音号不能为空")
return render(request, 'management/newmedia-management-create-douyin.html',
{'douyin_status_choices_list': douyin_status_choices_list, "organization": organization})
return render(request, 'management/newmedia-management-create-douyin.html',
{'douyin_status_choices_list': douyin_status_choices_list, "organization": organization})
def newmedia_management_create_qita(request):
QITA_STATUS_CHOICES = Qita.NEWMEDIA_STATUS_CHOICES
qita_status_choices_list = []
for w in QITA_STATUS_CHOICES:
qita_status_choices_list.append(list(w)[1])
organization = Organization.objects.all().order_by('-name')
if request.method == 'POST':
type = request.POST.get('type')
name = request.POST.get('name')
qitaid = request.POST.get('qitaid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if name is not None:
if organization is not None:
if image is not None:
qita = Qita(type=type, name=name, qitaid=qitaid, alias=alias, image=image,
organization_id=organization, status=status)
qita.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/qita/')
else:
qita = Qita(type=type, name=name, qitaid=qitaid, alias=alias, image='qita.png',
organization_id=organization, status=status)
qita.save()
messages.success(request, '创建成功')
return HttpResponseRedirect('/management/newmedia/management/create/qita/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-create-qita.html',
{'qita_status_choices_list': qita_status_choices_list, "organization": organization})
else:
messages.success(request, "新媒体名称不能为空")
return render(request, 'management/newmedia-management-create-qita.html',
{'qita_status_choices_list': qita_status_choices_list, "organization": organization})
return render(request, 'management/newmedia-management-create-qita.html',
{'qita_status_choices_list': qita_status_choices_list, "organization": organization})
def newmedia_management_edit_menu(request):
return render(request, 'management/newmedia-management-edit-menu.html')
def newmedia_management_edit_weixin(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
weixin = None
if level == 1:
weixin = Weixin.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
weixin = Weixin.objects.filter(organization__province=province,organization__cities=cities).order_by('-created')
elif level == 3:
weixin = Weixin.objects.filter(organization__province=province, organization__cities=cities,organization__district=district).order_by(
'-created')
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)
res = []
for w in weixin:
o = dict()
o['id'] = str(w.id)
o['image'] = w.image
o['code'] = w.code
o['weixinid'] = w.weixinid
o['organization'] = w.organization.name
o['organization_type'] = w.organization.organizationtype.organizationtype
o['administrativedivision'] = str(w.organization.province) + '-' + str(w.organization.cities) + '-' + str(
w.organization.district) + '-' + str(w.organization.town) + '-' + str(w.organization.village)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-weixin.html', {'weixin': weixin, 'res': res})
def newmedia_management_edit_weibo(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
weibo = None
if level == 1:
weibo = Weibo.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
weibo = Weibo.objects.filter(organization__province=province,organization__cities=cities).order_by('-created')
elif level == 3:
weibo = Weibo.objects.filter(organization__province=province, organization__cities=cities,organization__district=district).order_by('-created')
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)
res = []
for w in weibo:
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
o['administrativedivision'] = str(w.organization.province) + '-' + str(w.organization.cities) + '-' + str(
w.organization.district) + '-' + str(w.organization.town) + '-' + str(w.organization.village)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-weibo.html', {'weibo': weibo, 'res': res})
def newmedia_management_edit_toutiao(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
toutiao = None
if level == 1:
toutiao = Toutiao.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
toutiao = Toutiao.objects.filter(organization__province=province,organization__cities=cities).order_by('-created')
elif level == 3:
toutiao = Toutiao.objects.filter(organization__province=province, organization__cities=cities,organization__district=district).order_by(
'-created')
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)
res = []
for w in toutiao:
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
o['administrativedivision'] = str(w.organization.province) + '-' + str(w.organization.cities) + '-' + str(
w.organization.district) + '-' + str(w.organization.town) + '-' + str(w.organization.village)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-toutiao.html', {'toutiao': toutiao, 'res': res})
def newmedia_management_edit_douyin(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
douyin = None
if level == 1:
douyin = Douyin.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
douyin = Douyin.objects.filter(organization__province=province,organization__cities=cities).order_by('-created')
elif level == 3:
douyin = Douyin.objects.filter(organization__province=province, organization__cities=cities,organization__district=district).order_by(
'-created')
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)
res = []
for w in douyin:
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
o['administrativedivision'] = str(w.organization.province) + '-' + str(w.organization.cities) + '-' + str(
w.organization.district) + '-' + str(w.organization.town) + '-' + str(w.organization.village)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-douyin.html', {'douyin': douyin, 'res': res})
def newmedia_management_edit_qita(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
qita = None
if level == 1:
qita = Qita.objects.filter(organization__province=province).order_by('-created')
elif level == 2:
qita = Qita.objects.filter(organization__province=province,organization__cities=cities).order_by('-created')
elif level == 3:
qita = Qita.objects.filter(organization__province=province, organization__cities=cities,organization__district=district).order_by('-created')
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)
res = []
for w in qita:
o = dict()
o['id'] = str(w.id)
o['image'] = w.image
o['type'] = w.type
o['name'] = w.name
o['qitaid'] = w.qitaid
o['organization'] = w.organization.name
o['organization_type'] = w.organization.organizationtype.organizationtype
o['administrativedivision'] = str(w.organization.province) + '-' + str(w.organization.cities) + '-' + str(
w.organization.district) + '-' + str(w.organization.town) + '-' + str(w.organization.village)
o['status'] = w.status
res.append(o)
return render(request, 'management/newmedia-management-edit-qita.html', {'qita': qita, 'res': res})
def newmedia_management_update_weixin(request, pk):
WEIXIN_STATUS_CHOICES = Weixin.NEWMEDIA_STATUS_CHOICES
weixin_status_choices_list = []
for w in WEIXIN_STATUS_CHOICES:
weixin_status_choices_list.append(list(w)[1])
weixin = Weixin.objects.get(id=pk)
organization = Organization.objects.all()
if request.method == 'POST':
code = request.POST.get('code')
weixinid = request.POST.get('weixinid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
Weixin.objects.filter(id=pk).update(code=code, weixinid=weixinid, alias=alias,
organization_id=organization, status=status)
weixin.image = image
weixin.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/weixin/')
else:
Weixin.objects.filter(id=pk).update(code=code, weixinid=weixinid, alias=alias,
organization_id=organization, status=status)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/weixin/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-update-weixin.html',
{'weixin': weixin, 'organization': organization,
'weixin_status_choices_list': weixin_status_choices_list})
else:
messages.success(request, "微信公众号不能为空")
return render(request, 'management/newmedia-management-update-weixin.html',
{'weixin': weixin, 'organization': organization,
'weixin_status_choices_list': weixin_status_choices_list})
return render(request, 'management/newmedia-management-update-weixin.html',
{'weixin': weixin, 'organization': organization,
'weixin_status_choices_list': weixin_status_choices_list})
def newmedia_management_update_weibo(request, pk):
WEIBO_STATUS_CHOICES = Weibo.NEWMEDIA_STATUS_CHOICES
weibo_status_choices_list = []
for w in WEIBO_STATUS_CHOICES:
weibo_status_choices_list.append(list(w)[1])
weibo = Weibo.objects.get(id=pk)
organization = Organization.objects.all()
if request.method == 'POST':
code = request.POST.get('code')
weiboid = request.POST.get('weiboid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
Weibo.objects.filter(id=pk).update(code=code, weiboid=weiboid, alias=alias,
organization_id=organization, status=status)
weibo.image = image
weibo.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/weibo/')
else:
Weibo.objects.filter(id=pk).update(code=code, weiboid=weiboid, alias=alias,
organization_id=organization, status=status)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/weibo/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-update-weibo.html',
{'weibo': weibo, 'organization': organization,
'weibo_status_choices_list': weibo_status_choices_list})
else:
messages.success(request, "微博号不能为空")
return render(request, 'management/newmedia-management-update-weibo.html',
{'weibo': weibo, 'organization': organization,
'weibo_status_choices_list': weibo_status_choices_list})
return render(request, 'management/newmedia-management-update-weibo.html',
{'weibo': weibo, 'organization': organization,
'weibo_status_choices_list': weibo_status_choices_list})
def newmedia_management_update_toutiao(request, pk):
TOUTIAO_STATUS_CHOICES = Toutiao.NEWMEDIA_STATUS_CHOICES
toutiao_status_choices_list = []
for w in TOUTIAO_STATUS_CHOICES:
toutiao_status_choices_list.append(list(w)[1])
toutiao = Toutiao.objects.get(id=pk)
organization = Organization.objects.all()
if request.method == 'POST':
code = request.POST.get('code')
toutiaoid = request.POST.get('toutiaoid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
Toutiao.objects.filter(id=pk).update(code=code, toutiaoid=toutiaoid, alias=alias,
organization_id=organization, status=status)
toutiao.image = image
toutiao.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/toutiao/')
else:
Toutiao.objects.filter(id=pk).update(code=code, toutiaoid=toutiaoid, alias=alias,
organization_id=organization, status=status)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/toutiao/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-update-toutiao.html',
{'toutiao': toutiao, 'organization': organization,
'toutiao_status_choices_list': toutiao_status_choices_list})
else:
messages.success(request, "头条号不能为空")
return render(request, 'management/newmedia-management-update-toutiao.html',
{'toutiao': toutiao, 'organization': organization,
'toutiao_status_choices_list': toutiao_status_choices_list})
return render(request, 'management/newmedia-management-update-toutiao.html',
{'toutiao': toutiao, 'organization': organization,
'toutiao_status_choices_list': toutiao_status_choices_list})
def newmedia_management_update_douyin(request, pk):
DOUYIN_STATUS_CHOICES = Douyin.NEWMEDIA_STATUS_CHOICES
douyin_status_choices_list = []
for w in DOUYIN_STATUS_CHOICES:
douyin_status_choices_list.append(list(w)[1])
douyin = Douyin.objects.get(id=pk)
organization = Organization.objects.all()
if request.method == 'POST':
code = request.POST.get('code')
douyinid = request.POST.get('douyinid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if code is not None:
if organization is not None:
if image is not None:
Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias,
organization_id=organization, status=status)
douyin.image = image
douyin.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/douyin/')
else:
Douyin.objects.filter(id=pk).update(code=code, douyinid=douyinid, alias=alias,
organization_id=organization, status=status)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/douyin/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-update-douyin.html',
{'douyin': douyin, 'organization': organization,
'douyin_status_choices_list': douyin_status_choices_list})
else:
messages.success(request, "抖音号不能为空")
return render(request, 'management/newmedia-management-update-douyin.html',
{'douyin': douyin, 'organization': organization,
'douyin_status_choices_list': douyin_status_choices_list})
return render(request, 'management/newmedia-management-update-douyin.html',
{'douyin': douyin, 'organization': organization,
'douyin_status_choices_list': douyin_status_choices_list})
def newmedia_management_update_qita(request, pk):
QITA_STATUS_CHOICES = Qita.NEWMEDIA_STATUS_CHOICES
qita_status_choices_list = []
for w in QITA_STATUS_CHOICES:
qita_status_choices_list.append(list(w)[1])
organization = Organization.objects.all()
qita = Qita.objects.get(id=pk)
if request.method == 'POST':
type = request.POST.get('type')
name = request.POST.get('name')
qitaid = request.POST.get('qitaid')
alias = request.POST.get('alias')
image = request.FILES.get('image')
organization = request.POST.get('organization')
status = request.POST.get('status')
if name is not None:
if organization is not None:
if image is not None:
Qita.objects.filter(id=pk).update(type=type, name=name, qitaid=qitaid, alias=alias,
organization_id=organization, status=status)
qita.image = image
qita.save()
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/qita/')
else:
Qita.objects.filter(id=pk).update(type=type, name=name, qitaid=qitaid, alias=alias,
organization_id=organization, status=status)
messages.success(request, '修改成功')
return HttpResponseRedirect('/management/newmedia/management/edit/qita/')
else:
messages.success(request, "请选择单位")
return render(request, 'management/newmedia-management-update-qita.html',
{'qita': qita, 'organization': organization,
'qita_status_choices_list': qita_status_choices_list})
else:
messages.success(request, "新媒体名称不能为空")
return render(request, 'management/newmedia-management-update-qita.html',
{'qita': qita, 'organization': organization,
'qita_status_choices_list': qita_status_choices_list})
return render(request, 'management/newmedia-management-update-qita.html',
{'qita': qita, 'organization': organization,
'qita_status_choices_list': qita_status_choices_list})
def newmedia_management_delete_weixin(request, pk):
weixin = Weixin.objects.get(id=pk)
weixin.delete()
messages.success(request, "删除成功")
return HttpResponseRedirect('/management/newmedia/management/edit/weixin/')
def newmedia_management_delete_weibo(request, pk):
weibo = Weibo.objects.get(id=pk)
weibo.delete()
messages.success(request, "删除成功")
return HttpResponseRedirect('/management/newmedia/management/edit/weibo/')
def newmedia_management_delete_toutiao(request, pk):
toutiao = Toutiao.objects.get(id=pk)
toutiao.delete()
messages.success(request, "删除成功")
return HttpResponseRedirect('/management/newmedia/management/edit/toutiao/')
def newmedia_management_delete_douyin(request, pk):
douyin = Douyin.objects.get(id=pk)
douyin.delete()
messages.success(request, "删除成功")
return HttpResponseRedirect('/management/newmedia/management/edit/douyin/')
def newmedia_management_delete_qita(request, pk):
qita = Qita.objects.get(id=pk)
qita.delete()
messages.success(request, "删除成功")
return HttpResponseRedirect('/management/newmedia/management/edit/qita/')
def new_management(request):
news = News.objects.all()
news_list = []
for n in news:
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'] = '舆情热点'
news_list.append(o)
return render(request,'management/news-management.html',{'news':news_list})
def news_management_create(request):
if request.method == 'POST':
type = request.POST.get('type')
title = request.POST.get('title')
author = request.POST.get('author')
date = request.POST.get('date')
content = request.POST.get('content')
source = request.POST.get('source')
t = None
if type == '政策依据':
t = '0'
elif type == "基层动态":
t = '1'
elif type == '外省动态':
t = '2'
elif type == '监测通报':
t = '3'
elif type == '舆情热点':
t = '4'
print(str(title), str(content))
news = News(type=t, title=title, author=author, date=date, content=content,source=source)
news.save()
messages.success(request, '添加成功!!!')
return HttpResponseRedirect('/management/news/management/create/')
type = News.NEWMEDIA_NEWS_CHOICES
results = []
for i in type:
o = dict()
o['choices'] = list(i)[1]
results.append(o)
return render(request, 'management/news-management-create.html', {'type': results})
def news_management_detail(request,pk):
news = News.objects.get(id=pk)
return render(request,'management/news-management-detail.html',{'news':news})
def news_management_delete(request,pk):
news = News.objects.get(id=pk)
news.delete()
messages.success(request,'删除成功')
return HttpResponseRedirect('/management/news/management/')