862 lines
41 KiB
Python
862 lines
41 KiB
Python
import json
|
|
|
|
from django.contrib import messages
|
|
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
|
|
|
|
|
|
def user_management(request):
|
|
userpaginator = User.objects.all().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.url
|
|
o['name'] = u.userprofile_set.get(user_id=u.id).name
|
|
o['phone'] = u.first_name
|
|
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 group_management(request):
|
|
group = Group.objects.all().order_by('-created')
|
|
paginator = Paginator(group, 6)
|
|
page = int(request.GET.get('page', 1))
|
|
try:
|
|
group = paginator.page(page)
|
|
except PageNotAnInteger:
|
|
group = paginator.page(1)
|
|
except EmptyPage:
|
|
group = paginator.page(paginator.num_pages)
|
|
res = []
|
|
for g in group:
|
|
o = dict()
|
|
o['id'] = str(g.id)
|
|
o['image'] = g.image.url
|
|
o['name'] = g.name
|
|
o['type'] = g.type
|
|
o['admin_count'] = Group_admin.objects.filter(group_id=g.id).count()
|
|
o['user_count'] = Group_user.objects.filter(group_id=g.id).count()
|
|
o['status'] = g.status
|
|
res.append(o)
|
|
return render(request, 'management/group-management.html', {'res': res, 'group': group})
|
|
|
|
|
|
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/')
|
|
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/')
|
|
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):
|
|
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)
|
|
group.save()
|
|
messages.success(request, '添加成功')
|
|
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):
|
|
organization = Organization.objects.all().order_by('-created')
|
|
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
|
|
o['administrativedivision'] = str(i.province) + '-' + str(i.cities) + '-' + str(i.district) + '-' + str(
|
|
i.town) + '-' + str(i.village)
|
|
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()
|
|
if request.method == 'POST':
|
|
name = request.POST.get('name')
|
|
image = request.FILES.get('image')
|
|
organizationtype = request.POST.get('organizationtype')
|
|
province = request.POST.get('province')
|
|
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 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)
|
|
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)
|
|
messages.success(request, '修改成功')
|
|
return HttpResponseRedirect('/management/organization/management/')
|
|
return render(request, 'management/organization-management-update.html',
|
|
{'organization': organization, 'organizationtype': organizationtype})
|
|
|
|
|
|
def organization_create(request):
|
|
organizationtype = Organizationtype.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')
|
|
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(province, city)
|
|
if name is not None:
|
|
organization = Organization(name=name, image=image, organizationtype_id=organizationtype,
|
|
province=province_r, cities=city_r, district=district_r, town=town_r,
|
|
village=village_r)
|
|
organization.save()
|
|
messages.success(request, '添加成功')
|
|
else:
|
|
messages.error(request, '单位名不能为空')
|
|
return HttpResponseRedirect('/management/organization/management/')
|
|
return render(request, 'management/organization-management-create.html', {'organizationtype': organizationtype})
|
|
|
|
|
|
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.WEIXIN_STATUS_CHOICES
|
|
weixin_status_choices_list = []
|
|
for w in WEIXIN_STATUS_CHOICES:
|
|
weixin_status_choices_list.append(list(w)[1])
|
|
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 = 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.WEIBO_STATUS_CHOICES
|
|
weibo_status_choices_list = []
|
|
for w in WEIBO_STATUS_CHOICES:
|
|
weibo_status_choices_list.append(list(w)[1])
|
|
organization = Organization.objects.all()
|
|
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.TOUTIAO_STATUS_CHOICES
|
|
toutiao_status_choices_list = []
|
|
for w in TOUTIAO_STATUS_CHOICES:
|
|
toutiao_status_choices_list.append(list(w)[1])
|
|
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 = 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_qita(request):
|
|
QITA_STATUS_CHOICES = Qita.QITA_STATUS_CHOICES
|
|
qita_status_choices_list = []
|
|
for w in QITA_STATUS_CHOICES:
|
|
qita_status_choices_list.append(list(w)[1])
|
|
organization = Organization.objects.all()
|
|
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):
|
|
weixin = Weixin.objects.all().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):
|
|
weibo = Weibo.objects.all().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):
|
|
toutiao = Toutiao.objects.all().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_qita(request):
|
|
qita = Qita.objects.all().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.WEIXIN_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.WEIBO_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.TOUTIAO_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_qita(request, pk):
|
|
QITA_STATUS_CHOICES = Qita.QITA_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_qita(request,pk):
|
|
qita = Qita.objects.get(id=pk)
|
|
qita.delete()
|
|
messages.success(request,"删除成功")
|
|
return HttpResponseRedirect('/management/newmedia/management/edit/qita/')
|