#单位管理,群组管理,用户管理

This commit is contained in:
Bob 2020-08-13 17:55:52 +08:00
parent 5e6577bada
commit fbd99ad1d3
23 changed files with 1715 additions and 770 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from dashboard.models import Userprofile, Organization, Group, Level from dashboard.models import Userprofile, Organization, Group, Level, Organizationtype, Group_type
class UserProfileAdmin(admin.ModelAdmin): class UserProfileAdmin(admin.ModelAdmin):
@ -22,3 +22,9 @@ admin.site.register(Group,GroupAdmin)
class LevelAdmin(admin.ModelAdmin): class LevelAdmin(admin.ModelAdmin):
list_display = ('id',) list_display = ('id',)
admin.site.register(Level,LevelAdmin) admin.site.register(Level,LevelAdmin)
class OrganizationtypeAdmin(admin.ModelAdmin):
list_display = ('id',)
admin.site.register(Organizationtype,OrganizationtypeAdmin)
class Group_typeAdmin(admin.ModelAdmin):
list_display = ('id',)
admin.site.register(Group_type,Group_typeAdmin)

View File

@ -5,17 +5,56 @@ from django.db import models
# Create your models here. # Create your models here.
# 组 class Group_type(models.Model):
class Group(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('组名', max_length=256, null=True, blank=True) type = models.CharField('群组类型',max_length=256,null=True,blank=True)
def __str__(self):
return self.type
# 群组
class Group(models.Model):
GROUP_STATUS_CHOICES = (
('0','关闭'),
('1','开启')
)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('群组名称', max_length=256, null=True, blank=True)
presentation = models.TextField('群组描述', null=True, blank=True)
image = models.FileField(upload_to='groupimage', null=True, blank=True)
type = models.ForeignKey(Group_type,on_delete=models.CASCADE,null=True,blank=True)
status = models.CharField('状态',max_length=256,null=True,blank=True,choices=GROUP_STATUS_CHOICES)
province = models.CharField('', max_length=256, null=True, blank=True)
cities = models.CharField('', max_length=256, null=True, blank=True)
district = models.CharField('', max_length=256, null=True, blank=True)
town = models.CharField('', max_length=256, null=True, blank=True)
village = models.CharField('', max_length=256, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self): def __str__(self):
return self.name return self.name
#群组管理员
class Group_admin(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.group.name
#群组成员
class Group_user(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.user.username
# 权限等级 # 权限等级
class Level(models.Model): class Level(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
@ -27,14 +66,30 @@ class Level(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
#单位类型
class Organizationtype(models.Model):
id = models.UUIDField('id',primary_key=True,default=uuid.uuid4)
organizationtype = models.CharField('单位类型',blank=True,null=True,max_length=256)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.organizationtype
# 单位 # 单位
class Organization(models.Model): class Organization(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('单位名', max_length=256, null=True, blank=True) name = models.CharField('单位名', max_length=256, null=True, blank=True)
group = models.ForeignKey(Group, on_delete=models.CASCADE) image = models.FileField(upload_to='cover', null=True, blank=True)
level = models.ForeignKey(Level,on_delete=models.CASCADE,null=True,blank=True) organizationtype = models.ForeignKey(Organizationtype,on_delete=models.CASCADE, null=True, blank=True)
province = models.CharField('',max_length=256,null=True,blank=True)
cities = models.CharField('',max_length=256,null=True,blank=True)
district = models.CharField('',max_length=256,null=True,blank=True)
town = models.CharField('',max_length=256,null=True,blank=True)
village = models.CharField('',max_length=256,null=True,blank=True)
# group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
# level = models.ForeignKey(Level,on_delete=models.CASCADE,null=True,blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -46,8 +101,10 @@ class Organization(models.Model):
class Userprofile(models.Model): class Userprofile(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField('姓名', null=True, blank=True, max_length=256) name = models.CharField('姓名', null=True, blank=True, max_length=256)
sex = models.CharField('性别', null=True, blank=True, max_length=256)
image = models.FileField(upload_to='profile', null=True, blank=True) image = models.FileField(upload_to='profile', null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
def __str__(self): def __str__(self):
return self.user.username return self.user.username
@ -65,7 +122,8 @@ def create_user_profile(sender, instance, created, **kwargs):
class Weixin(models.Model): class Weixin(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
code = models.CharField('微信公众号', max_length=256, null=True, blank=True) code = models.CharField('微信公众号', max_length=256, null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) image = models.FileField(upload_to='cover', null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -85,7 +143,7 @@ class Weixin_data(models.Model):
comment = models.CharField('评论数', max_length=256, null=True, blank=True) comment = models.CharField('评论数', max_length=256, null=True, blank=True)
reply = models.CharField('作者回复数', max_length=256, null=True, blank=True) reply = models.CharField('作者回复数', max_length=256, null=True, blank=True)
content = models.TextField('正文', null=True, blank=True) content = models.TextField('正文', null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE) weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -99,7 +157,7 @@ class Weixin_comment(models.Model):
comment = models.TextField('评论', null=True, blank=True) comment = models.TextField('评论', null=True, blank=True)
user = models.CharField('用户', max_length=256, null=True, blank=True) user = models.CharField('用户', max_length=256, null=True, blank=True)
reply = models.TextField('回复', null=True, blank=True) reply = models.TextField('回复', null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE) weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -113,7 +171,7 @@ class Weixin_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True) wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True) idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True) site = models.CharField('位置', max_length=256, null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE) weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True) change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -126,7 +184,8 @@ class Weixin_Wrong(models.Model):
class Weibo(models.Model): class Weibo(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
code = models.CharField('微博号', max_length=256, null=True, blank=True) code = models.CharField('微博号', max_length=256, null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) image = models.FileField(upload_to='cover', null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -150,7 +209,7 @@ class Weibi_data(models.Model):
transpond = models.CharField('转发数', max_length=256, null=True, blank=True) transpond = models.CharField('转发数', max_length=256, null=True, blank=True)
comment = models.CharField('评论数', max_length=256, null=True, blank=True) comment = models.CharField('评论数', max_length=256, null=True, blank=True)
title = models.CharField('文章标题', max_length=256, null=True, blank=True) title = models.CharField('文章标题', max_length=256, null=True, blank=True)
weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE) weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -164,7 +223,7 @@ class Weibo_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True) wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True) idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True) site = models.CharField('位置', max_length=256, null=True, blank=True)
weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE) weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True) change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -174,7 +233,8 @@ class Weibo_Wrong(models.Model):
class Toutiao(models.Model): class Toutiao(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
code = models.CharField('头条号', max_length=256, null=True, blank=True) code = models.CharField('头条号', max_length=256, null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) image = models.FileField(upload_to='cover', null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -194,7 +254,7 @@ class Toutiao_data(models.Model):
date = models.CharField('时间', max_length=256, null=True, blank=True) date = models.CharField('时间', max_length=256, null=True, blank=True)
content = models.TextField('正文', null=True, blank=True) content = models.TextField('正文', null=True, blank=True)
comment = models.TextField('评论', null=True, blank=True) comment = models.TextField('评论', null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE) toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -208,7 +268,7 @@ class Toutiao_comment(models.Model):
comment = models.TextField('评论', null=True, blank=True) comment = models.TextField('评论', null=True, blank=True)
user = models.CharField('用户', max_length=256, null=True, blank=True) user = models.CharField('用户', max_length=256, null=True, blank=True)
reply = models.TextField('回复', null=True, blank=True) reply = models.TextField('回复', null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE) toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -222,7 +282,7 @@ class Toutiao_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True) wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True) idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True) site = models.CharField('位置', max_length=256, null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE) toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True) change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -234,7 +294,7 @@ class Toutiao_Wrong(models.Model):
# 其他新媒体 # 其他新媒体
class Qita(models.Model): class Qita(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE) organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
type = models.CharField('新媒体类型', max_length=256, null=True, blank=True) type = models.CharField('新媒体类型', max_length=256, null=True, blank=True)
name = models.CharField('新媒体名称', max_length=256, null=True, blank=True) name = models.CharField('新媒体名称', max_length=256, null=True, blank=True)
count = models.CharField('总发文量', max_length=256, null=True, blank=True) count = models.CharField('总发文量', max_length=256, null=True, blank=True)
@ -245,5 +305,15 @@ class Qita(models.Model):
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.name
#5级地名库
class Area_code_2020(models.Model):
code = models.CharField('区划代码',max_length=256,null=True,blank=True)
name = models.CharField('名称',max_length=256,null=True,blank=True)
level = models.CharField('级别1-5,省市县镇村',max_length=256,null=True,blank=True)
pcode = models.CharField('父级区划代码',max_length=256,null=True,blank=True)
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -0,0 +1,18 @@
<div id="pages" class="text-center">
<nav>
<ul class="pagination">
<li class="step-links">
{% if group.has_previous %}
<a class='active' href="?page={{ group.previous_page_number }}">上一页</a>
{% endif %}
<span class="current">
第{{ group.number }}页 共{{ group.paginator.num_pages }}页</span>
{% if group.has_next %}
<a class='active' href="?page={{ group.next_page_number }}">下一页</a>
{% endif %}
</li>
</ul>
</nav>
</div>

View File

@ -0,0 +1,18 @@
<div id="pages" class="text-center">
<nav>
<ul class="pagination">
<li class="step-links">
{% if organization.has_previous %}
<a class='active' href="?page={{ organization.previous_page_number }}">上一页</a>
{% endif %}
<span class="current">
第{{ organization.number }}页 共{{ organization.paginator.num_pages }}页</span>
{% if organization.has_next %}
<a class='active' href="?page={{ organization.next_page_number }}">下一页</a>
{% endif %}
</li>
</ul>
</nav>
</div>

View File

@ -0,0 +1,18 @@
<div id="pages" class="text-center">
<nav>
<ul class="pagination">
<li class="step-links">
{% if userpaginator.has_previous %}
<a class='active' href="?page={{ userpaginator.previous_page_number }}">上一页</a>
{% endif %}
<span class="current">
第{{ userpaginator.number }}页 共{{ userpaginator.paginator.num_pages }}页</span>
{% if userpaginator.has_next %}
<a class='active' href="?page={{ userpaginator.next_page_number }}">下一页</a>
{% endif %}
</li>
</ul>
</nav>
</div>

View File

@ -57,7 +57,8 @@
class="login loginpage col-lg-offset-4 col-lg-4 col-md-offset-3 col-md-6 col-sm-offset-3 col-sm-6 col-xs-offset-2 col-xs-8"> class="login loginpage col-lg-offset-4 col-lg-4 col-md-offset-3 col-md-6 col-sm-offset-3 col-sm-6 col-xs-offset-2 col-xs-8">
<h1><a href="#" title="Login Page" tabindex="-1">Ultra Admin</a></h1> <h1><a href="#" title="Login Page" tabindex="-1">Ultra Admin</a></h1>
<form name="loginform" id="loginform" action="{% url 'dashboard-register' %}" method="post" enctype="multipart/form-data">{% csrf_token %} <form name="loginform" id="loginform" action="{% url 'dashboard-register' %}" method="post"
enctype="multipart/form-data">{% csrf_token %}
<p> <p>
<label for="name">单位<br/> <label for="name">单位<br/>
<select class="form-control" name="organization"> <select class="form-control" name="organization">
@ -71,6 +72,15 @@
<label for="name">姓名<br/> <label for="name">姓名<br/>
<input type="text" name="name" id="user_login" class="input" value="" size="20"/></label> <input type="text" name="name" id="user_login" class="input" value="" size="20"/></label>
</p> </p>
<p>
<label for="sex">性别<br/>
<label style="text-align: center">
<input type="radio" name="sex" id="inlineRadio1" value="1" checked="checked">
<input type="radio" name="sex" id="inlineRadio2" value="2" style="margin-left: 50px">
</label>
</label>
</p>
<p> <p>
<label for="email">邮箱<br/> <label for="email">邮箱<br/>
<input type="text" name="email" id="user_login" class="input" value="" size="20"/></label> <input type="text" name="email" id="user_login" class="input" value="" size="20"/></label>

View File

@ -9,4 +9,12 @@ urlpatterns = [
path('refresh_captcha/', views.refresh_captcha, name='refresh-captcha'), path('refresh_captcha/', views.refresh_captcha, name='refresh-captcha'),
path('logout/', views.user_logout, name='dashboard-logout'), path('logout/', views.user_logout, name='dashboard-logout'),
path('register/', views.register, name='dashboard-register'), path('register/', views.register, name='dashboard-register'),
#省市县地区级联菜单
#获取省
path('get/province/',views.get_province),
path('get/city/',views.get_city),
path('get/district/',views.get_district),
path('get/town/',views.get_town),
path('get/village/',views.get_village),
] ]

View File

@ -10,7 +10,7 @@ import datetime
# Create your views here. # Create your views here.
from dashboard.models import Userprofile, Organization from dashboard.models import Userprofile, Organization, Area_code_2020
def refresh_captcha(request): def refresh_captcha(request):
@ -72,6 +72,7 @@ def register(request):
image = None image = None
flag = False flag = False
o = None o = None
sex = None
hash_key = CaptchaStore.generate_key() hash_key = CaptchaStore.generate_key()
image_url = captcha_image_url(hash_key) image_url = captcha_image_url(hash_key)
organization = Organization.objects.all() organization = Organization.objects.all()
@ -110,6 +111,10 @@ def register(request):
else: else:
image = request.FILES.get('image') image = request.FILES.get('image')
print(str(image)+"1111111111111111111111111111111111111111111") print(str(image)+"1111111111111111111111111111111111111111111")
if request.POST.get('sex') == 0:
sex = ''
else:
sex = ''
captcha_input = request.POST.get('captcha_1') captcha_input = request.POST.get('captcha_1')
captcha_hashkey = request.POST.get('captcha_0') captcha_hashkey = request.POST.get('captcha_0')
@ -136,8 +141,49 @@ def register(request):
user.is_staff = True user.is_staff = True
user.first_name = phone user.first_name = phone
user.save() user.save()
userprofile = Userprofile(name=name,image=image,user_id=user.id,organization_id=o) userprofile = Userprofile(name=name,image=image,user_id=user.id,organization_id=o,sex=sex)
userprofile.save() userprofile.save()
messages.success(request, '注册成功,请登录') messages.success(request, '注册成功,请登录')
return HttpResponseRedirect('/login/') return HttpResponseRedirect('/login/')
return render(request, 'dashboard/register.html', {'hash_key': hash_key, 'image_url': image_url,'organization':organization}) return render(request, 'dashboard/register.html', {'hash_key': hash_key, 'image_url': image_url,'organization':organization})
def get_province(request):
#省
province = Area_code_2020.objects.filter(level=1)
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})

Binary file not shown.

43
import_area.py Normal file
View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import csv
import re
import uuid
import os
import psycopg2
from pip._vendor import chardet
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB1 user=newmedia password=newmedia2020!@#'
def insert_area(code, name,level, pcode):
with psycopg2.connect(G2) as connection:
with connection.cursor() as cursor:
cursor.execute(
'insert into dashboard_area_code_2020(code, name,level, pcode) values (%s,%s, %s,%s)'
, (code, name,level, pcode))
connection.commit()
return code
if __name__ == '__main__':
f = open('D:/2020/荒漠植被调查/china_area-master/area_code_2020.sql/area_code_2020.sql',encoding='utf-8').read()
data = f.split('INSERT INTO dashboard_area_code_2020 (code, name, level, pcode)VALUES')
for d in data:
for i in d.split('\n'):
list = i.split(');')[0].split('),')[0].split('(')
# print(len(list))
if len(list) > 1:
success_data = list[1].split(',')
try:
code = success_data[0]
name = re.sub("'","",success_data[1])
level = success_data[2]
pcode = success_data[3]
print(code, name, level, pcode)
insert_area(code, name,level, pcode)
except:
pass

View File

@ -46,13 +46,67 @@
<div class="row"> <div class="row">
<div class="col-md-8 col-sm-9 col-xs-10"> <div class="col-md-8 col-sm-9 col-xs-10">
<form method="post" <form method="post"
action="{% url 'group-management-create' %}">{% csrf_token %} action="{% url 'group-management-create' %}" enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="name">群组名</label> <label class="form-label" for="name">群组名</label>
<div class="controls"> <div class="controls">
<input type="text" class="form-control" name="name"> <input type="text" class="form-control" name="name">
</div> </div>
</div> </div>
<div class="form-group">
<label class="form-label" for="presentation">群组介绍</label>
<div class="controls">
<textarea type="text" class="form-control"
name="presentation"></textarea>
</div>
</div>
<div class="form-group">
<label class="form-label" for="image">图标
<div class="controls">
<input type="file" name="image">
</div>
</label>
</div>
<div class="form-group">
<label class="form-label" for="type">群组类型</label>
<div class="controls">
<select class="form-control" name="type">
{% for g in group_type %}
<option value="{{ g.id }}">{{ g.type }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="status">群组状态</label>
<div class="controls">
<select class="form-control" name="status">
{% for g in group_status_choices_list %}
<option value="{{ g }}">{{ g }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="administrativedivision">行政区划</label>
<div class="controls">
<select id="province" name="province">
<option value="">请选择省</option>
</select>
<select id="city" name="city" style="margin-left: 20px">
<option value="">请选择市</option>
</select>
<select id="district" name="district" style="margin-left: 20px">
<option value="">请选择区/县</option>
</select>
<select id="town" name="town" style="margin-left: 20px">
<option value="">请选择乡/镇</option>
</select>
<select id="village" name="village" style="margin-left: 20px">
<option value="">请选择村/街道</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-success">点击创建</button> <button type="submit" class="btn btn-success">点击创建</button>
</form> </form>
@ -67,3 +121,77 @@
</div> </div>
</body> </body>
{% endblock %} {% endblock %}
{% block add_js %}
<script>
$(function () {
$.get('/get/province/', function (data) {
for (var i = 0, len = data.province.length; i < len; i++) {
$new = $("<option value=" + data.province[i][0] + ">" + data.province[i][1] + "</option>");
$("#province").append($new);
}
})
//当省份改变后
$("#province").change(function () {
$("#city").empty().append('<option value="">请选择市</option>');
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/city/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.city.length; i < len; i++) {
$new = $("<option value=" + data.city[i][0] + ">" + data.city[i][1] + "</option>");
$("#city").append($new);
}
})
})
//当城市改变后
$("#city").change(function () {
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/district/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.district.length; i < len; i++) {
$new = $("<option value=" + data.district[i][0] + ">" + data.district[i][1] + "</option>");
$("#district").append($new);
}
})
})
//当县改变后
$("#district").change(function () {
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/town/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.town.length; i < len; i++) {
$new = $("<option value=" + data.town[i][0] + ">" + data.town[i][1] + "</option>");
$("#town").append($new);
}
})
})
//当乡改变后
$("#district").change(function () {
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/village/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.village.length; i < len; i++) {
$new = $("<option value=" + data.village[i][0] + ">" + data.village[i][1] + "</option>");
$("#village").append($new);
}
})
})
})
</script>
{% endblock %}

View File

@ -36,24 +36,150 @@
<section class="box "> <section class="box ">
<header class="panel_header"> <header class="panel_header">
<h2 class="title pull-left">群组信息表单</h2> <h2 class="title pull-left">群组信息表单</h2>
{# <div class="actions panel_actions pull-right">#}
{# <i class="box_toggle fa fa-chevron-down"></i>#}
{# <i class="box_setting fa fa-cog" data-toggle="modal" href="#section-settings"></i>#}
{# <i class="box_close fa fa-times"></i>#}
{# </div>#}
</header> </header>
<div class="content-body"> <div class="content-body">
<div class="row"> <div class="row">
<div class="col-md-8 col-sm-9 col-xs-10"> <div class="col-md-8 col-sm-9 col-xs-10">
<form method="post" <form method="post"
action="{% url 'group-management-update' group.id %}">{% csrf_token %} action="{% url 'group-management-update' group.id %}" enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="name">群组名</label> <label class="form-label" for="name">群组名</label>
<div class="controls"> <div class="controls">
<input type="text" class="form-control" name="name" <input type="text" class="form-control" name="name"
value="{{ group.name }}"> value="{{ group.name }}">
</div> </div>
</div> </div>
<div class="form-group">
<label class="form-label" for="presentation">群组介绍</label>
<div class="controls">
<input type="text" class="form-control"
name="presentation" value="{{ group.presentation }}">
</div>
</div>
<div class="form-group">
<label class="form-label" for="image">图标
<div class="controls">
<input type="file" name="image"><img
src="{{ group.image.url }}"
style="width: 80px;height: 80px;"
class="img-circle">
</div>
</label>
</div>
<div class="form-group">
<label class="form-label" for="type">群组类型</label>
<div class="controls">
<select class="form-control" name="type">
<option value="{{ group.type.id }}">{{ group.type }}</option>
{% for g in group_type %}
<option value="{{ g.id }}">{{ g.type }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="status">群组状态</label>
<div class="controls">
<select class="form-control" name="status">
<option value="{{ group.status }}">{{ group.status }}</option>
{% for g in group_status_choices_list %}
<option value="{{ g }}">{{ g }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="administrativedivision">行政区划</label>
<div class="controls">
<select id="province" name="province">
<option value="{{ group.province }}">{{ group.province }}</option>
</select>
<select id="city" name="city" style="margin-left: 20px">
<option value="{{ group.cities }}">{{ group.cities }}</option>
</select>
<select id="district" name="district" style="margin-left: 20px">
<option value="{{ group.district }}">{{ group.district }}</option>
</select>
<select id="town" name="town" style="margin-left: 20px">
<option value="{{ group.town }}">{{ group.town }}</option>
</select>
<select id="village" name="village" style="margin-left: 20px">
<option value="{{ group.village }}">{{ group.village }}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="stauts">管理员</label>
<div class="controls" style="margin-left: 5%">
<span class="glyphicon glyphicon-plus" aria-hidden="true">添加管理员</span>
<table class="table table-hover" style="margin-top: 20px">
<thead>
<tr>
<th style="text-align: center">头像</th>
<th style="text-align: center">用户名</th>
<th style="text-align: center">姓名</th>
<th style="text-align: center">单位名称</th>
<th style="text-align: center">行政区划</th>
<th style="text-align: center">操作</th>
</tr>
</thead>
<tbody>
{% for g_a in g_a_list %}
<tr>
<td style="vertical-align: middle;text-align: center"><img
src="{{ g_a.image }}"
style="width: 80px;height: 80px;"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ g_a.username }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_a.name }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_a.organization }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_a.organization }}</td>
<td style="vertical-align: middle;text-align: center">
<a href=""
class="btn btn-danger btn-mini">删除</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="form-group">
<label class="form-label" for="stauts">成员</label>
<div class="controls" style="margin-left: 5%">
<span class="glyphicon glyphicon-plus" aria-hidden="true">添加成员</span>
<table class="table table-hover" style="margin-top: 20px">
<thead>
<tr>
<th style="text-align: center">头像</th>
<th style="text-align: center">用户名</th>
<th style="text-align: center">姓名</th>
<th style="text-align: center">单位名称</th>
<th style="text-align: center">行政区划</th>
<th style="text-align: center">操作</th>
</tr>
</thead>
<tbody>
{% for g_u in g_u_list %}
<tr>
<td style="vertical-align: middle;text-align: center"><img
src="{{ g_u.image }}"
style="width: 80px;height: 80px;"
class="img-circle"></td>
<td style="vertical-align: middle;text-align: center">{{ g_u.username }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_u.name }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_u.organization }}</td>
<td style="vertical-align: middle;text-align: center">{{ g_u.organization }}</td>
<td style="vertical-align: middle;text-align: center">
<a href=""
class="btn btn-danger btn-mini">删除</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<button type="submit" class="btn btn-success">提交修改</button> <button type="submit" class="btn btn-success">提交修改</button>
</form> </form>
@ -68,3 +194,77 @@
</div> </div>
</body> </body>
{% endblock %} {% endblock %}
{% block add_js %}
<script>
$(function () {
$.get('/get/province/', function (data) {
for (var i = 0, len = data.province.length; i < len; i++) {
$new = $("<option value=" + data.province[i][0] + ">" + data.province[i][1] + "</option>");
$("#province").append($new);
}
})
//当省份改变后
$("#province").change(function () {
$("#city").empty().append('<option value="">请选择市</option>');
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/city/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.city.length; i < len; i++) {
$new = $("<option value=" + data.city[i][0] + ">" + data.city[i][1] + "</option>");
$("#city").append($new);
}
})
})
//当城市改变后
$("#city").change(function () {
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/district/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.district.length; i < len; i++) {
$new = $("<option value=" + data.district[i][0] + ">" + data.district[i][1] + "</option>");
$("#district").append($new);
}
})
})
//当县改变后
$("#district").change(function () {
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/town/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.town.length; i < len; i++) {
$new = $("<option value=" + data.town[i][0] + ">" + data.town[i][1] + "</option>");
$("#town").append($new);
}
})
})
//当乡改变后
$("#district").change(function () {
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/village/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.village.length; i < len; i++) {
$new = $("<option value=" + data.village[i][0] + ">" + data.village[i][1] + "</option>");
$("#village").append($new);
}
})
})
})
</script>
{% endblock %}

View File

@ -42,52 +42,44 @@
<section class="box "> <section class="box ">
<header class="panel_header"> <header class="panel_header">
<h2 class="title pull-left">群组列表</h2> <h2 class="title pull-left">群组列表</h2>
{# <div class="actions panel_actions pull-right">#}
{# <i class="box_toggle fa fa-chevron-down"></i>#}
{# <i class="box_setting fa fa-cog" data-toggle="modal" href="#section-settings"></i>#}
{# <i class="box_close fa fa-times"></i>#}
{# </div>#}
</header> </header>
<div class="content-body"> <div class="content-body">
<div class="row"> <div class="row">
<div class="col-md-12 col-sm-12 col-xs-12"> <div class="col-md-12 col-sm-12 col-xs-12">
<div class="row"> <table class="table table-hover">
<div class="col-sm-8 col-md-8 col-xs-12"> <thead>
<ul id="nestableList-1" class="uk-nestable"> <tr>
{% for g in group %} <th style="text-align: center">头像</th>
<li data-item="Item 1" data-item-id="1"> <th style="text-align: center">群组名称</th>
<div class="uk-nestable-item"> <th style="text-align: center">群组类型</th>
<div class="uk-nestable-handle" <th style="text-align: center">管理员个数</th>
onclick="group_detail('{{ g.id }}')"></div> <th style="text-align: center">成员个数</th>
<div class="list-label">{{ g.name }}</div> <th style="text-align: center">状态</th>
<th style="text-align: center">操作</th>
<div class="list-label" style="float: right"> </tr>
<a href="{% url 'group-management-delete' g.id %}"> </thead>
<button type="button" class="btn btn-danger">删除 <tbody>
</button> {% for r in res %}
</a> <tr>
</div> <td><img src="{{ r.image }}" style="width: 80px;height: 80px;"
<div class="list-label" style="float: right"> class="img-circle"></td>
<a href="{% url 'group-management-update' g.id %}"> <td style="vertical-align: middle;text-align: center">{{ r.name }}</td>
<button type="button" class="btn btn-success">修改 <td style="vertical-align: middle;text-align: center">{{ r.type }}</td>
</button> <td style="vertical-align: middle;text-align: center">{{ r.admin_count }}</td>
</a> <td style="vertical-align: middle;text-align: center">{{ r.admin_count }}</td>
</div> <td style="vertical-align: middle;text-align: center">{{ r.status }}</td>
</div> <td style="vertical-align: middle;text-align: center">
</li> <a href="{% url 'group-management-update' r.id %}"
class="btn btn-primary btn-mini">编辑</a>
<a href="{% url 'group-management-delete' r.id %}"
class="btn btn-danger btn-mini">删除</a>
</td>
</tr>
{% endfor %} {% endfor %}
</ul> </tbody>
</div> </table>
<div class="col-sm-4 col-md-4 col-xs-12"> <div class="metadata-pagination">
<div class="panel panel-success"> {% include 'dashboard/paginator/group-management-paginate.html' %}
<div class="panel-heading">
<h3 class="panel-title">群组信息</h3>
</div>
<div class="panel-body" id="group_detail" style="min-height: 100px">
<p class="none">暂无数据,请点击左侧图标查询</p>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -46,7 +46,7 @@
<div class="row"> <div class="row">
<div class="col-md-8 col-sm-9 col-xs-10"> <div class="col-md-8 col-sm-9 col-xs-10">
<form method="post" <form method="post"
action="{% url 'organization-management-create' %}">{% csrf_token %} action="{% url 'organization-management-create' %}" enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="name">单位名</label> <label class="form-label" for="name">单位名</label>
<div class="controls"> <div class="controls">
@ -54,26 +54,43 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="form-label" for="group">群组</label> <label class="form-label" for="image">图标
<div class="controls"> <div class="controls">
<select class="form-control" name="group"> <input type="file" name="image">
{% for g in group %} </div></label>
<option value="{{ g.id }}">{{ g.name }}</option> </div>
<div class="form-group">
<label class="form-label" for="organizationtype">单位类型</label>
<div class="controls">
<select class="form-control" name="organizationtype">
{% for o in organizationtype %}
<option value="{{ o.id }}">{{ o.organizationtype }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="form-label" for="level">权限</label> <label class="form-label" for="administrativedivision">行政区划</label>
<div class="controls">
<select class="form-control" name="level"> <select id="province" name="province">
{% for l in level %} <option value="">请选择省</option>
<option value="{{ l.id }}">{{ l.name }}</option> </select>
{% endfor %} <select id="city" name="city" style="margin-left: 20px">
<option value="">请选择市</option>
</select>
<select id="district" name="district" style="margin-left: 20px">
<option value="">请选择区/县</option>
</select>
<select id="town" name="town" style="margin-left: 20px">
<option value="">请选择乡/镇</option>
</select>
<select id="village" name="village" style="margin-left: 20px">
<option value="">请选择村/街道</option>
</select> </select>
</div> </div>
<button type="submit" class="btn btn-success">点击新建</button> </div>
<button type="submit" class="btn btn-success" style="margin-top: 50px">点击新建
</button>
</form> </form>
</div> </div>
</div> </div>
@ -86,3 +103,78 @@
</div> </div>
</body> </body>
{% endblock %} {% endblock %}
{% block add_js %}
<script>
$(function () {
$.get('/get/province/', function (data) {
for (var i = 0, len = data.province.length; i < len; i++) {
$new = $("<option value=" + data.province[i][0] + ">" + data.province[i][1] + "</option>");
$("#province").append($new);
}
})
//当省份改变后
$("#province").change(function () {
$("#city").empty().append('<option value="">请选择市</option>');
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/city/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.city.length; i < len; i++) {
$new = $("<option value=" + data.city[i][0] + ">" + data.city[i][1] + "</option>");
$("#city").append($new);
}
})
})
//当城市改变后
$("#city").change(function () {
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/district/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.district.length; i < len; i++) {
$new = $("<option value=" + data.district[i][0] + ">" + data.district[i][1] + "</option>");
$("#district").append($new);
}
})
})
//当县改变后
$("#district").change(function () {
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/town/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.town.length; i < len; i++) {
$new = $("<option value=" + data.town[i][0] + ">" + data.town[i][1] + "</option>");
$("#town").append($new);
}
})
})
//当乡改变后
$("#district").change(function () {
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/village/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.village.length; i < len; i++) {
$new = $("<option value=" + data.village[i][0] + ">" + data.village[i][1] + "</option>");
$("#village").append($new);
}
})
})
})
</script>
{% endblock %}

View File

@ -46,7 +46,8 @@
<div class="row"> <div class="row">
<div class="col-md-8 col-sm-9 col-xs-10"> <div class="col-md-8 col-sm-9 col-xs-10">
<form method="post" <form method="post"
action="{% url 'organization-management-update' organization.id %}">{% csrf_token %} action="{% url 'organization-management-update' organization.id %}"
enctype="multipart/form-data">{% csrf_token %}
<div class="form-group"> <div class="form-group">
<label class="form-label" for="name">单位名</label> <label class="form-label" for="name">单位名</label>
<div class="controls"> <div class="controls">
@ -55,25 +56,45 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="form-label" for="group">群组</label> <label class="form-label" for="image">图标
<div class="controls"> <div class="controls">
<select class="form-control" name="group"> <input type="file" name="image"><img
<option value="{{ organization.group.id }}">{{ organization.group.name }}</option> src="{{ organization.image.url }}"
{% for g in group %} style="width: 80px;height: 80px;"
<option value="{{ g.id }}">{{ g.name }}</option> class="img-circle">
</div>
</label>
</div>
<div class="form-group">
<label class="form-label" for="organizationtype">单位类型</label>
<div class="controls">
<select class="form-control" name="organizationtype">
<option value="{{ organization.organizationtype.id }}">{{ organization.organizationtype.organizationtype }}</option>
{% for o in organizationtype %}
<option value="{{ o.id }}">{{ o.organizationtype }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="form-label" for="level">权限</label> <label class="form-label" for="administrativedivision">行政区划</label>
<div class="controls">
<select class="form-control" name="level"> <select id="province" name="province">
<option value="{{ organization.level.id }}">{{ organization.level.name }}</option> <option value="{{ organization.province }}">{{ organization.province }}</option>
{% for l in level %}
<option value="{{ l.id }}">{{ l.name }}</option>
{% endfor %}
</select> </select>
<select id="city" name="city" style="margin-left: 20px">
<option value="{{ organization.province }}">{{ organization.cities }}</option>
</select>
<select id="district" name="district" style="margin-left: 20px">
<option value="{{ organization.province }}">{{ organization.district }}</option>
</select>
<select id="town" name="town" style="margin-left: 20px">
<option value="{{ organization.province }}">{{ organization.town }}</option>
</select>
<select id="village" name="village" style="margin-left: 20px">
<option value="{{ organization.province }}">{{ organization.village }}</option>
</select>
</div>
</div> </div>
<button type="submit" class="btn btn-success">提交修改</button> <button type="submit" class="btn btn-success">提交修改</button>
@ -89,3 +110,77 @@
</div> </div>
</body> </body>
{% endblock %} {% endblock %}
{% block add_js %}
<script>
$(function () {
$.get('/get/province/', function (data) {
for (var i = 0, len = data.province.length; i < len; i++) {
$new = $("<option value=" + data.province[i][0] + ">" + data.province[i][1] + "</option>");
$("#province").append($new);
}
})
//当省份改变后
$("#province").change(function () {
$("#city").empty().append('<option value="">请选择市</option>');
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/city/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.city.length; i < len; i++) {
$new = $("<option value=" + data.city[i][0] + ">" + data.city[i][1] + "</option>");
$("#city").append($new);
}
})
})
//当城市改变后
$("#city").change(function () {
$("#district").empty().append('<option value="">请选择区/县</option>');
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/district/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.district.length; i < len; i++) {
$new = $("<option value=" + data.district[i][0] + ">" + data.district[i][1] + "</option>");
$("#district").append($new);
}
})
})
//当县改变后
$("#district").change(function () {
$("#town").empty().append('<option value="">请选择乡/镇</option>');
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/town/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.town.length; i < len; i++) {
$new = $("<option value=" + data.town[i][0] + ">" + data.town[i][1] + "</option>");
$("#town").append($new);
}
})
})
//当乡改变后
$("#district").change(function () {
$("#village").empty().append('<option value="">请选择村/街道</option>');
$.ajax({
url: '/get/village/',
type: 'get',
data: {"code": $(this).val()}
}).done(function (data) {
for (var i = 0, len = data.village.length; i < len; i++) {
$new = $("<option value=" + data.village[i][0] + ">" + data.village[i][1] + "</option>");
$("#village").append($new);
}
})
})
})
</script>
{% endblock %}

View File

@ -52,41 +52,42 @@
<div class="row"> <div class="row">
<div class="col-md-12 col-sm-12 col-xs-12"> <div class="col-md-12 col-sm-12 col-xs-12">
<div class="row"> <div class="row">
<div class="col-sm-8 col-md-8 col-xs-12"> <div class="col-sm-12 col-md-12 col-xs-12">
<ul id="nestableList-1" class="uk-nestable"> <table class="table table-hover">
{% for o in organization %} <thead>
<li data-item="Item 1" data-item-id="1"> <tr>
<div class="uk-nestable-item"> <th style="text-align: center">图标</th>
<div class="uk-nestable-handle" <th style="text-align: center">单位名称</th>
onclick="organization_detail('{{ o.id }}')"></div> <th style="text-align: center">行政区划</th>
<div class="list-label">{{ o.name }}</div> <th style="text-align: center">类型</th>
<th style="text-align: center">成员数量</th>
<div class="list-label" style="float: right"> <th style="text-align: center">新媒体数量</th>
<a href="{% url 'organization-management-delete' o.id %}"> <th style="text-align: center">操作</th>
<button type="button" class="btn btn-danger">删除 </tr>
</button> </thead>
</a> <tbody>
</div> {% for r in res %}
<div class="list-label" style="float: right"> <tr>
<a href="{% url 'organization-management-update' o.id %}"> <td style="vertical-align: middle;text-align: center"><img
<button type="button" class="btn btn-success">修改 src="{{ r.image }}" style="width: 80px;height: 80px;"
</button> class="img-circle"></td>
</a> <td style="vertical-align: middle;text-align: center">{{ r.name }}</td>
</div> <td style="vertical-align: middle;text-align: center">{{ r.organizationtype }}</td>
</div> <td style="vertical-align: middle;text-align: center">{{ r.administrativedivision }}</td>
</li> <td style="vertical-align: middle;text-align: center">{{ r.usercount }}</td>
<td style="vertical-align: middle;text-align: center">{{ r.mediacount }}</td>
<td style="vertical-align: middle;text-align: center">
<a href="{% url 'organization-management-update' r.id %}"
class="btn btn-primary btn-mini">编辑</a>
<a href="{% url 'organization-management-delete' r.id %}"
class="btn btn-danger btn-mini">删除</a>
</td>
</tr>
{% endfor %} {% endfor %}
</ul> </tbody>
</div> </table>
<div class="col-sm-4 col-md-4 col-xs-12"> <div class="metadata-pagination">
<div class="panel panel-success"> {% include 'dashboard/paginator/organization-management-paginate.html' %}
<div class="panel-heading">
<h3 class="panel-title">群组信息</h3>
</div>
<div class="panel-body" id="organization_detail"
style="min-height: 100px">
<p class="none">暂无数据,请点击左侧图标查询</p>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -106,19 +107,5 @@
<script src="{% static 'management/js/uikit.min.js' %}" type="text/javascript"></script> <script src="{% static 'management/js/uikit.min.js' %}" type="text/javascript"></script>
<script src="{% static 'management/js/nestable.min.js' %}" type="text/javascript"></script> <script src="{% static 'management/js/nestable.min.js' %}" type="text/javascript"></script>
<script> <script>
function organization_detail(id) {
console.log(id)
$.getJSON('/management/organization/detail/' + id, function (res) {
console.log(res)
if (res) {
$(".none").html("")
$("#organization_detail").html("")
$("#organization_detail").append("<p>单位名:" + res.name + "</p><p>所属群组:" + res.group + "</p><p>权限等级:" + res.level + "</p><p>创建时间:" + res.created + "</p>")
} else {
$("#organization_detail").append("暂无数据")
}
})
}
</script> </script>
{% endblock %} {% endblock %}

View File

@ -1,174 +1,80 @@
{% extends 'dashboard/base/base.html' %} {% extends 'dashboard/base/base.html' %}
{% load static %} {% load static %}
{% block css %} {% block css %}
<!-- OTHER SCRIPTS INCLUDED ON THIS PAGE - START -->
<link href="{% static 'management/css/uikit.min.css' %}" rel="stylesheet" type="text/css" media="screen"/> <link href="{% static 'management/css/uikit.min.css' %}" rel="stylesheet" type="text/css" media="screen"/>
<link href="{% static 'management/css/nestable.min.css' %}" rel="stylesheet" type="text/css" media="screen"/> <link href="{% static 'management/css/nestable.min.css' %}" rel="stylesheet" type="text/css" media="screen"/>
<!-- OTHER SCRIPTS INCLUDED ON THIS PAGE - END -->
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<body class=" "><!-- START TOPBAR --> <body class=" ">
<!-- START CONTAINER -->
<div class="page-container row-fluid"> <div class="page-container row-fluid">
<!-- SIDEBAR - START -->
<div class="page-sidebar "> <div class="page-sidebar ">
<!-- MAIN MENU - START -->
{% include 'dashboard/base/left.html' %} {% include 'dashboard/base/left.html' %}
</div> </div>
<!-- SIDEBAR - END -->
<!-- START CONTENT -->
<section id="main-content" class=" "> <section id="main-content" class=" ">
<section class="wrapper" style='margin-top:60px;display:inline-block;width:100%;padding:15px 0 0 15px;'> <section class="wrapper" style='margin-top:60px;display:inline-block;width:100%;padding:15px 0 0 15px;'>
<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'> <div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
<div class="page-title"> <div class="page-title">
<div class="pull-left"> <div class="pull-left">
<h1 class="title">用户管理</h1></div> <h1 class="title">用户管理</h1></div>
</div> </div>
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="col-lg-12"> <div class="col-lg-12">
<section class="box "> <section class="box ">
<header class="panel_header"> <header class="panel_header">
<h2 class="title pull-left">成员列表</h2> <h2 class="title pull-left">成员列表</h2>
{# <div class="actions panel_actions pull-right">#}
{# <i class="box_toggle fa fa-chevron-down"></i>#}
{# <i class="box_setting fa fa-cog" data-toggle="modal" href="#section-settings"></i>#}
{# <i class="box_close fa fa-times"></i>#}
{# </div>#}
</header> </header>
<div class="content-body"> <div class="content-body">
<div class="row"> <div class="row">
<div class="col-md-12 col-sm-12 col-xs-12"> <div class="col-md-12 col-sm-12 col-xs-12">
<table class="table table-hover">
<thead>
<div class="row"> <tr>
<div class="col-sm-8 col-md-8 col-xs-12"> <th style="text-align: center">头像</th>
<th style="text-align: center">姓名</th>
<ul id="nestableList-1" class="uk-nestable"> <th style="text-align: center">电话</th>
<th style="text-align: center">单位名称</th>
<th style="text-align: center">单位类型</th>
<th style="text-align: center">行政区划</th>
<th style="text-align: center">操作</th>
</tr>
</thead>
<tbody>
{% for u in userallinfo %} {% for u in userallinfo %}
<li data-item="Item 1" data-item-id="1"> <tr>
<div class="uk-nestable-item"> <td><img src="{{ u.image }}" style="width: 80px;height: 80px;"
<div class="uk-nestable-handle" class="img-circle"></td>
onclick="user_detail({{ u.id }})"></div> <td style="vertical-align: middle;text-align: center">{{ u.name }}</td>
{# <div data-nestable-action="toggle"></div>#} <td style="vertical-align: middle;text-align: center">{{ u.phone }}</td>
<div class="list-label">{{ u.username }}</div> <td style="vertical-align: middle;text-align: center">{{ u.organization }}</td>
<div class="list-label" style="float: right"> <td style="vertical-align: middle;text-align: center">{{ u.type }}</td>
<a href="{% url 'user-management-delete' u.id %}"><button type="button" class="btn btn-danger">删除</button></a> <td style="vertical-align: middle;text-align: center">{{ u.administrativedivision }}</td>
</div> <td style="vertical-align: middle;text-align: center">
</div> <a href="{% url 'user-management-delete' u.id %}"
</li> class="btn btn-danger btn-mini">删除</a>
</td>
</tr>
{% endfor %} {% endfor %}
</ul> </tbody>
</table>
<div class="metadata-pagination">
{% include 'dashboard/paginator/user-management-paginate.html' %}
</div> </div>
<div class="col-sm-4 col-md-4 col-xs-12">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">用户信息</h3>
</div>
<div class="panel-body" id="user_detail" style="min-height: 250px">
<p class="none">暂无数据,请点击左侧图标查询</p>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
</section> </section>
</div> </div>
{# <div class="col-lg-12">#}
{# <section class="box ">#}
{# <header class="panel_header">#}
{# <h2 class="title pull-left">Disable Nesting</h2>#}
{# <div class="actions panel_actions pull-right">#}
{# <i class="box_toggle fa fa-chevron-down"></i>#}
{# <i class="box_setting fa fa-cog" data-toggle="modal" href="#section-settings"></i>#}
{# <i class="box_close fa fa-times"></i>#}
{# </div>#}
{# </header>#}
{# <div class="content-body">#}
{# <div class="row">#}
{# <div class="col-md-12 col-sm-12 col-xs-12">#}
{##}
{##}
{# <ul class="uk-nestable" data-uk-nestable="{maxDepth:1}">#}
{# <li>#}
{# <div class="uk-nestable-item">#}
{# <div class="uk-nestable-handle"></div>#}
{# <div data-nestable-action="toggle"></div>#}
{# <div class="list-label">Item 1</div>#}
{# </div>#}
{# </li>#}
{# <li>#}
{# <div class="uk-nestable-item">#}
{# <div class="uk-nestable-handle"></div>#}
{# <div data-nestable-action="toggle"></div>#}
{# <div class="list-label">Item 2</div>#}
{# </div>#}
{# </li>#}
{# <li>#}
{# <div class="uk-nestable-item">#}
{# <div class="uk-nestable-handle"></div>#}
{# <div data-nestable-action="toggle"></div>#}
{# <div class="list-label">Item 3</div>#}
{# </div>#}
{# </li>#}
{# </ul>#}
{##}
{# </div>#}
{# </div>#}
{# </div>#}
{# </section>#}
{# </div>#}
</section> </section>
</section> </section>
<!-- END CONTENT -->
<div class="chatapi-windows "> <div class="chatapi-windows ">
</div> </div>
</div> </div>
<!-- OTHER SCRIPTS INCLUDED ON THIS PAGE - START -->
</body> </body>
{% endblock %} {% endblock %}
{% block add_js %} {% block add_js %}
<script src="{% static 'management/js/uikit.min.js' %}" type="text/javascript"></script> <script src="{% static 'management/js/uikit.min.js' %}" type="text/javascript"></script>
<script src="{% static 'management/js/nestable.min.js' %}" type="text/javascript"></script> <script src="{% static 'management/js/nestable.min.js' %}" type="text/javascript"></script>
<!-- OTHER SCRIPTS INCLUDED ON THIS PAGE - END -->
<script> <script>
function user_detail(id) {
console.log(id)
$.getJSON('/management/user/detail/' + id, function (res) {
console.log(res)
if (res) {
$(".none").html("")
$("#user_detail").html("")
$("#user_detail").append("<p>用户名:" + res.username + "</p>" + "<p>姓名:" + res.name + "</p>" + "<p>电话:" + res.first_name + "</p>" + "<p>单位:" + res.organization + "</p>" + "<p>注册时间:" + res.date_joined + "</p>" + "<p>上次登录:" + res.last_login + "</p>")
} else {
$("#user_detail").append("暂无数据")
}
})
}
</script> </script>
{% endblock %} {% endblock %}

View File

@ -5,18 +5,18 @@ from management import views
urlpatterns = [ urlpatterns = [
# 用户管理 # 用户管理
path('user/management/', views.user_management, name='user-management-management'), path('user/management/', views.user_management, name='user-management-management'),
path('user/detail/<str:pk>/', views.user_detail, name='user-management-detail'),
path('user/delete/<str:pk>/', views.user_delete, name='user-management-delete'), path('user/delete/<str:pk>/', views.user_delete, name='user-management-delete'),
# 群组管理 # 群组管理
path('group/management/', views.group_management, name='group-management-management'), path('group/management/', views.group_management, name='group-management-management'),
path('group/create/', views.group_create, name='group-management-create'), path('group/create/', views.group_create, name='group-management-create'),
path('group/detail/<str:pk>/', views.group_detail, name='group-management-detail'),
path('group/update/<str:pk>/', views.group_update, name='group-management-update'), path('group/update/<str:pk>/', views.group_update, name='group-management-update'),
path('group/delete/<str:pk>/', views.group_delete, name='group-management-delete'), path('group/delete/<str:pk>/', views.group_delete, name='group-management-delete'),
#添加管理员
#主体单位管理 #主体单位管理
path('organization/management/',views.organization_management,name='organization-management-management'), path('organization/management/',views.organization_management,name='organization-management-management'),
path('organization/create/',views.organization_create,name='organization-management-create'), path('organization/create/',views.organization_create,name='organization-management-create'),
path('organization/detail/<str:pk>/',views.organization_detail,name='organization-management-detail'),
path('organization/delete/<str:pk>/',views.organization_delete,name='organization-management-delete'), path('organization/delete/<str:pk>/',views.organization_delete,name='organization-management-delete'),
path('organization/update/<str:pk>/',views.organization_update,name='organization-management-update'), path('organization/update/<str:pk>/',views.organization_update,name='organization-management-update'),

View File

@ -2,114 +2,343 @@ import json
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render from django.shortcuts import render
from dashboard.models import Userprofile, Group, Organization, Level, Organizationtype, Area_code_2020, Weixin, Weibo, \
from dashboard.models import Userprofile, Group, Organization, Level Toutiao, Qita, Group_type, Group_admin, Group_user
def user_management(request): def user_management(request):
user = User.objects.all() userpaginator = User.objects.all().order_by('-date_joined')
return render(request,'management/user-management.html',{'userallinfo':user}) paginator = Paginator(userpaginator, 6)
def user_detail(request,pk): page = int(request.GET.get('page', 1))
user = User.objects.get(id=pk) try:
userprofile = Userprofile.objects.get(user_id=pk) userpaginator = paginator.page(page)
return HttpResponse(json.dumps({ except PageNotAnInteger:
"status":"1", userpaginator = paginator.page(1)
"id":str(user.id), except EmptyPage:
"username":user.username, userpaginator = paginator.page(paginator.num_pages)
"first_name":user.first_name, userallinfo = []
"last_login":str(user.last_login).split('.')[0], for u in userpaginator:
"date_joined":str(user.date_joined).split('.')[0], o = dict()
"name":userprofile.name, o['id'] = str(u.id)
"organization":userprofile.organization.name, o['image'] = u.userprofile_set.get(user_id=u.id).image.url
})) o['name'] = u.userprofile_set.get(user_id=u.id).name
def user_delete(request,pk): 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 = User.objects.get(id=pk)
user.delete() user.delete()
return HttpResponseRedirect('/management/user/management/') return HttpResponseRedirect('/management/user/management/')
def group_management(request): def group_management(request):
group = Group.objects.all() group = Group.objects.all().order_by('-created')
return render(request,'management/group-management.html',{'group':group}) paginator = Paginator(group, 6)
def group_detail(request,pk): page = int(request.GET.get('page', 1))
group = Group.objects.get(id=pk) try:
print(group) group = paginator.page(page)
return HttpResponse(json.dumps({ except PageNotAnInteger:
"status":"1", group = paginator.page(1)
"id": str(group.id), except EmptyPage:
"name":group.name, group = paginator.page(paginator.num_pages)
"created":str(group.created) res = []
})) for g in group:
def group_update(request,pk): 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 = 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)
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': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
Group.objects.filter(id=pk).update(name=name) presentation = request.POST.get('presentation')
messages.success(request,'修改成功') 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/') return HttpResponseRedirect('/management/group/management/')
return render(request,'management/group-management-update.html',{'group':group}) 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): 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': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
if name is not None: presentation = request.POST.get('presentation')
group = Group(name=name) image = request.FILES.get('image')
group.save() type = request.POST.get('type')
messages.success(request,'添加成功') status = request.POST.get('status')
province = request.POST.get('province')
if province != '':
province_r = Area_code_2020.objects.get(code=province).name
else: else:
messages.error(request,'群组名不能为空') 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 HttpResponseRedirect('/management/group/management/')
return render(request,'management/group-management-create.html') return render(request, 'management/group-management-create.html',
def group_delete(request,pk): {'group_status_choices_list': group_status_choices_list, 'group_type': group_type})
def group_delete(request, pk):
group = Group.objects.get(id=pk) group = Group.objects.get(id=pk)
group.delete() group.delete()
messages.success(request,'删除成功') messages.success(request, '删除成功')
return HttpResponseRedirect('/management/group/management/') return HttpResponseRedirect('/management/group/management/')
def organization_management(request): def organization_management(request):
organization = Organization.objects.all() organization = Organization.objects.all().order_by('-created')
return render(request,'management/organization-management.html',{"organization":organization}) paginator = Paginator(organization, 6)
def organization_detail(request,pk): page = int(request.GET.get('page', 1))
organization = Organization.objects.get(id=pk) try:
return HttpResponse(json.dumps({ organization = paginator.page(page)
"status":"1", except PageNotAnInteger:
"id":str(organization.id), organization = paginator.page(1)
"name":organization.name, except EmptyPage:
"group":organization.group.name, organization = paginator.page(paginator.num_pages)
"level":organization.level.name, res = []
"created":str(organization.created).split('.')[0], for i in organization:
})) o = dict()
def organization_delete(request,pk): 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 = Organization.objects.get(id=pk)
organization.delete() organization.delete()
messages.success(request, '删除成功') messages.success(request, '删除成功')
return HttpResponseRedirect('/management/organization/management/') return HttpResponseRedirect('/management/organization/management/')
def organization_update(request,pk):
def organization_update(request, pk):
organization = Organization.objects.get(id=pk) organization = Organization.objects.get(id=pk)
group = Group.objects.all() organizationtype = Organizationtype.objects.all()
level = Level.objects.all()
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
group = request.POST.get('group') image = request.FILES.get('image')
level = request.POST.get('level') organizationtype = request.POST.get('organizationtype')
Organization.objects.filter(id=pk).update(name=name,group=group,level=level) 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, '修改成功') messages.success(request, '修改成功')
return HttpResponseRedirect('/management/organization/management/') return HttpResponseRedirect('/management/organization/management/')
return render(request,'management/organization-management-update.html',{'organization':organization,'level':level,'group':group}) 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): def organization_create(request):
group = Group.objects.all() organizationtype = Organizationtype.objects.all()
level = Level.objects.all()
if request.method == 'POST': if request.method == 'POST':
name = request.POST.get('name') name = request.POST.get('name')
group = request.POST.get('group') image = request.FILES.get('image')
level = request.POST.get('level') organizationtype = request.POST.get('organizationtype')
if name is not None: province = request.POST.get('province')
organization = Organization(name=name,group_id=group,level_id=level) if province != '':
organization.save() province_r = Area_code_2020.objects.get(code=province).name
messages.success(request,'添加成功')
else: else:
messages.error(request,'单位名不能为空') 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 HttpResponseRedirect('/management/organization/management/')
return render(request,'management/organization-management-create.html',{'level':level,'group':group}) return render(request, 'management/organization-management-create.html', {'organizationtype': organizationtype})

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB