diff --git a/dashboard/models.py b/dashboard/models.py index c97319c..b3eb3f0 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -2,6 +2,7 @@ import uuid from django.contrib.auth.models import User from django.db import models + # 权限等级 @@ -22,6 +23,8 @@ class Group_type(models.Model): def __str__(self): return self.type + + # 矩阵 @@ -58,6 +61,7 @@ class Group(models.Model): def __str__(self): return self.name + # 矩阵管理员 @@ -72,6 +76,8 @@ class Group_admin(models.Model): def __str__(self): return self.group.name + + # 矩阵成员 @@ -87,6 +93,7 @@ class Group_user(models.Model): def __str__(self): return self.user.username + # 单位类型 @@ -118,8 +125,8 @@ class Organization(models.Model): directly = models.CharField('单位类型', max_length=256, null=True, blank=True) status = models.CharField('状态', max_length=256, null=True, blank=True) - #20201014新添加字段 - id_code = models.CharField('单位唯一标识码',max_length=256,null=True,blank=True) + # 20201014新添加字段 + id_code = models.CharField('单位唯一标识码', max_length=256, null=True, blank=True) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) @@ -147,8 +154,8 @@ class Userprofile(models.Model): Organization, on_delete=models.CASCADE, null=True, blank=True) # 用户状态:注册进来默认为0,为未审核状态,审核后status=1 status = models.IntegerField('用户状态', null=True, blank=True, default=0) - #20201017新增字段(职位) - zhiwei = models.CharField('职位',max_length=256,null=True,blank=True) + # 20201017新增字段(职位) + zhiwei = models.CharField('职位', max_length=256, null=True, blank=True) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) @@ -186,6 +193,15 @@ def create_user_profile(sender, instance, created, **kwargs): class NewMedia(models.Model): + """ + status: + '0': '已删除', + '1': '添加申请市级审核中', + '2': '添加申请省级审核中', + '3': '正常', + '4': '注销申请市级审核中', + '5': '注销申请省级审核中', + """ id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) code = models.CharField('微信公众号', max_length=256, null=True, blank=True) alias = models.CharField('别名', max_length=256, null=True, blank=True) @@ -199,10 +215,11 @@ class NewMedia(models.Model): remark = models.CharField('备注', null=True, blank=True, max_length=2560) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) - #20201015新增字段 - identificationcode = models.CharField('新媒体标识码',max_length=256,null=True,blank=True) - function = models.CharField('功能',max_length=256,null=True,blank=True) - articleurl = models.TextField('文章URL',null=True,blank=True) + # 20201015新增字段 + identificationcode = models.CharField('新媒体标识码', max_length=256, null=True, blank=True) + function = models.CharField('功能', max_length=256, null=True, blank=True) + articleurl = models.TextField('文章URL', null=True, blank=True) + class Meta: abstract = True ordering = ["-created"] @@ -549,6 +566,8 @@ class Douyin_data(models.Model): def __str__(self): return self.mewnedia.code + + # 其他新媒体 @@ -559,6 +578,7 @@ class Qita(NewMedia): def __str__(self): return self.qitaid + # 其他新媒体监测 @@ -576,6 +596,8 @@ class Qita_jc(models.Model): def __str__(self): return self.mewnedia.name + + # 5级地名库 @@ -620,8 +642,9 @@ class News(models.Model): def __str__(self): return self.title -#手机验证码验证表 + +# 手机验证码验证表 class CheckCode(models.Model): - phone_code = models.CharField('手机验证码',max_length=256,null=True,blank=True) - phone = models.CharField('电话号',max_length=256,null=True,blank=True) - c_time =models.DateTimeField('时间', auto_now_add=True) + phone_code = models.CharField('手机验证码', max_length=256, null=True, blank=True) + phone = models.CharField('电话号', max_length=256, null=True, blank=True) + c_time = models.DateTimeField('时间', auto_now_add=True) diff --git a/dashboard/templates/dashboard/user-improve-personal-information.html b/dashboard/templates/dashboard/user-improve-personal-information.html new file mode 100644 index 0000000..cb0cf14 --- /dev/null +++ b/dashboard/templates/dashboard/user-improve-personal-information.html @@ -0,0 +1,145 @@ +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block content %} + + + + +
+ +
+ {% include 'dashboard/base/left.html' %} +
+
+
+ {% if messages %} + + {% endif %} +
+
+ +
+

个人信息完善

+
+
+
+ +
+
+
+

用户信息

+
+
+
+
+
{% csrf_token %} +
+ +
+ +
+
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ +{% endblock %} +{% block add_js %} + +{% endblock %} + diff --git a/dashboard/urls.py b/dashboard/urls.py index 68a0324..f288e24 100644 --- a/dashboard/urls.py +++ b/dashboard/urls.py @@ -7,6 +7,8 @@ urlpatterns = [ path('index/', views.index, name='dashboard-index'), path('', views.user_login, name='dashboard-login'), path('user/login/for/phone/', views.user_login_for_phone, name='dashboard-login-for-phone'), + #手机用户第一次登录后完善个人信息 + path('user/improve/personal/information//',views.improve_personal_information,name = 'user-improve-personal-information'), #发送手机验证码 path('author/code/',views.author_code,name='author-code'), path('refresh_captcha/', views.refresh_captcha, name='refresh-captcha'), diff --git a/dashboard/views.py b/dashboard/views.py index c26ae6a..344e081 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -2,6 +2,8 @@ import csv import json import http.client import random + +from django.contrib.auth.hashers import make_password from django.utils import timezone import time from urllib import parse @@ -95,25 +97,30 @@ def user_login_for_phone(request): p_code = request.POST.get('check_code') phone = request.POST.get('phone') print(phone, p_code) - results = CheckCode.objects.filter(phone=18119305139).count() + results = CheckCode.objects.filter(phone=phone).count() print(str(results) + "11111111111111111") # try: + res = User.objects.filter(username=phone).count() + if res > 0: + messages.error(request, '您的账号已经存在,请您使用密码登录!!!') + return HttpResponseRedirect('/') if results > 0: check_code = CheckCode.objects.get(phone_code=p_code, phone=phone) if User.objects.filter(username=phone).count() > 0: user = User.objects.get(username=phone) login(request, user, backend='django.contrib.auth.backends.ModelBackend') # check_code.delete() - return HttpResponseRedirect('/index/') + + return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id)) else: - user = User(username=phone) + user = User(username=phone, last_login=timezone.now()) user.save() - userprofile = Userprofile(user_id=user.id, image='default.png') - userprofile.save() + # userprofile = Userprofile(user_id=user.id, image='default.png') + # userprofile.save() u = authenticate(username=phone) login(request, u, backend='django.contrib.auth.backends.ModelBackend') - return HttpResponseRedirect('/index/') + return HttpResponseRedirect('/user/improve/personal/information/%s/' % (user.id)) # if float(time.time()) - float(check_code.c_time) > 60: # check_code.delete() # return '验证码超时已被删除' @@ -126,6 +133,46 @@ def user_login_for_phone(request): return render(request, 'dashboard/login-for-phone.html') +def improve_personal_information(request, pk): + name = None + email = None + image = None + password = None + confirm_password = None + o_id = None + user = User.objects.get(id=pk) + if request.method == 'POST': + o = request.POST.get('organization') + if Organization.objects.get(name=o): + o_id = Organization.objects.get(name=o).id + else: + messages.error(request,'您填写的单位不存在!!!') + if request.POST.get('name'): + name = request.POST.get('name') + else: + messages.error(request,'请输入您的姓名!!!') + if request.POST.get('email'): + email = request.POST.get('email') + else: + messages.error(request,'请输入您的邮箱!!!') + if request.FILES.get('image'): + image = request.POST.get('image') + else: + image = '/profile/user_default.jpg' + if request.POST.get('password'): + password = request.POST.get('password') + else: + messages.error(request,'请输入密码') + confirm_password = request.POST.get('confirm_password') + if password is not None and confirm_password is not None: + if password == confirm_password: + User.objects.filter(id=pk).update(email=email,password=make_password(password)) + userprofile=Userprofile(name=name,image=image,organization_id=o_id,user_id=user.id) + userprofile.save() + messages.success(request,'修改成功') + return render(request, 'dashboard/user-improve-personal-information.html', {'usee': user}) + + def author_code(request): sms_host = "sms.yunpian.com" voice_host = "voice.yunpian.com" @@ -147,8 +194,7 @@ def author_code(request): code += ch print(code) # tpl_value = {'#dateStart#': '10月1日', '#dateEnd#': '10日', '#type#': '微信公众号', '#name#': code} - tpl_value = {'#code#':code} - + tpl_value = {'#code#': code} params = parse.urlencode({ 'apikey': apikey, @@ -192,6 +238,7 @@ def register(request): flag = False user_organization = None sex = None + user_organization = None hash_key = CaptchaStore.generate_key() image_url = captcha_image_url(hash_key) organization = Organization.objects.filter(status='1') @@ -200,7 +247,11 @@ def register(request): messages.error(request, '请选择单位') else: o = request.POST.get('organization') - user_organization = Organization.objects.get(name=o).id + res = Organization.objects.filter(name=o).count() + if res > 0: + user_organization = Organization.objects.get(name=o).id + else: + messages.error(request,'您填写的单位不存在') if not request.POST.get('name'): messages.error(request, '请输入姓名') else: @@ -223,7 +274,7 @@ def register(request): else: confirm_password = request.POST.get('confirm_password') if not request.FILES.get('image'): - messages.error(request, '请选择头像') + image='/profile/user_default.jpg' else: image = request.FILES.get('image') print(str(image) + "1111111111111111111111111111111111111111111") @@ -252,7 +303,7 @@ def register(request): return HttpResponseRedirect('/register/') if username is not None and password is not None and confirm_password is not None and email is not None and flag: - user = User.objects.create_user(username, email, password,last_login = timezone.now() ) + user = User.objects.create_user(username, email, password, last_login=timezone.now()) user.is_active = True # user.is_staff = True # user.first_name = phone @@ -347,6 +398,7 @@ def get_organization(request): def wechat_verify(request): return HttpResponse("11833201729252855821") + def import_user(request): with open('F:/总.csv') as csvfile: reader = csv.reader(csvfile) @@ -366,4 +418,4 @@ def import_user(request): u.save() except: print(phone) - return HttpResponse('ok') \ No newline at end of file + return HttpResponse('ok') diff --git a/management/templates/management/group-admin-create.html b/management/templates/management/group-admin-create.html index 0d113a0..e449930 100644 --- a/management/templates/management/group-admin-create.html +++ b/management/templates/management/group-admin-create.html @@ -53,7 +53,11 @@
diff --git a/management/templates/management/group-management-admin.html b/management/templates/management/group-management-admin.html index 7d861d4..78cf649 100644 --- a/management/templates/management/group-management-admin.html +++ b/management/templates/management/group-management-admin.html @@ -49,6 +49,28 @@ href="{% url 'group-management-management-admin' %}">我管理的矩阵
  • 我加入的矩阵
  • + {% if level == 9 %} +
  • 所有的矩阵
  • + {% endif %} +
    +
    + +
    +
    +
    + + + + +
    +
    +
    我共管理{% if admin_count %}{{ admin_count }}{% else %} 0{% endif %}个矩阵
    diff --git a/management/templates/management/group-management-init.html b/management/templates/management/group-management-init.html index c4bd2a5..5b41c30 100644 --- a/management/templates/management/group-management-init.html +++ b/management/templates/management/group-management-init.html @@ -41,15 +41,39 @@
    {#

    矩阵列表

    #} +
    diff --git a/management/templates/management/group-management-superuser.html b/management/templates/management/group-management-superuser.html new file mode 100644 index 0000000..c3e108c --- /dev/null +++ b/management/templates/management/group-management-superuser.html @@ -0,0 +1,127 @@ +{% extends 'dashboard/base/base.html' %} +{% load static %} +{% block css %} + + + + +{% endblock %} +{% block content %} + +
    +
    + {% include 'dashboard/base/left.html' %} +
    +
    +
    + + {% if messages %} + + {% endif %} +
    +
    + +
    +

    矩阵管理

    + + +
    +
    +
    + + +
    +
    +
    + {#

    矩阵列表

    #} + +
    +
    +
    +
    + + + + + + + + + + + + + + {% for r in res_g_i %} + + + + + + + + + + {% endfor %} + +
    序号头像矩阵名称矩阵类型管理员个数成员个数状态
    {{ forloop.counter }}{{ r.name }}{{ r.type }}{{ r.admin_count }}{{ r.user_count }}{{ r.status }}
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +{% endblock %} +{% block add_js %} + + +{% endblock %} diff --git a/management/templates/management/group-management-user.html b/management/templates/management/group-management-user.html index d71ed22..cb45f1c 100644 --- a/management/templates/management/group-management-user.html +++ b/management/templates/management/group-management-user.html @@ -49,6 +49,28 @@ href="{% url 'group-management-management-admin' %}">我管理的矩阵 + {% if level == 9 %} +
  • 所有的矩阵
  • + {% endif %} +
    +
    + +
    +
    +
    + + + + +
    +
    +
    我共加入{% if user_count %}{{ user_count }}{% else %} 0{% endif %}个矩阵
    diff --git a/management/templates/management/group-user-create.html b/management/templates/management/group-user-create.html index 6d27705..94d7302 100644 --- a/management/templates/management/group-user-create.html +++ b/management/templates/management/group-user-create.html @@ -41,19 +41,25 @@
    {% csrf_token %} + action="{% url 'group-user-create' pk %}" + enctype="multipart/form-data">{% csrf_token %}
    - +
    - +
    diff --git a/management/templates/management/newmedia-management-edit-douyin.html b/management/templates/management/newmedia-management-edit-douyin.html index 4f1d05d..a4be724 100644 --- a/management/templates/management/newmedia-management-edit-douyin.html +++ b/management/templates/management/newmedia-management-edit-douyin.html @@ -23,6 +23,23 @@

    抖音列表

    + +
    + +
    +
    +
    + + + + +
    +
    +

    抖音总计:{{ douyin_count }}

    diff --git a/management/templates/management/newmedia-management-edit-qita.html b/management/templates/management/newmedia-management-edit-qita.html index e2abc36..56a88ed 100644 --- a/management/templates/management/newmedia-management-edit-qita.html +++ b/management/templates/management/newmedia-management-edit-qita.html @@ -23,11 +23,29 @@

    其他新媒体列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    其他新媒体总计:{{ qita_count }}

    + diff --git a/management/templates/management/newmedia-management-edit-toutiao.html b/management/templates/management/newmedia-management-edit-toutiao.html index a699ad4..68a7bb0 100644 --- a/management/templates/management/newmedia-management-edit-toutiao.html +++ b/management/templates/management/newmedia-management-edit-toutiao.html @@ -23,6 +23,23 @@

    头条列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    头条总计:{{ toutiao_count }}

    diff --git a/management/templates/management/newmedia-management-edit-weibo.html b/management/templates/management/newmedia-management-edit-weibo.html index 73471ac..ef31d63 100644 --- a/management/templates/management/newmedia-management-edit-weibo.html +++ b/management/templates/management/newmedia-management-edit-weibo.html @@ -23,6 +23,24 @@

    微博列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    + +

    微博总计:{{ weibo_count }}

    diff --git a/management/templates/management/newmedia-management-edit-weixin.html b/management/templates/management/newmedia-management-edit-weixin.html index 1de8a04..c6f83b9 100644 --- a/management/templates/management/newmedia-management-edit-weixin.html +++ b/management/templates/management/newmedia-management-edit-weixin.html @@ -23,6 +23,23 @@

    微信公众号列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    微信总计:{{ weixin_count }}

    diff --git a/management/templates/management/news-management.html b/management/templates/management/news-management.html index 1d36081..c47e6aa 100644 --- a/management/templates/management/news-management.html +++ b/management/templates/management/news-management.html @@ -42,6 +42,27 @@

    新闻列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    新闻总计:{{ news_count }}

    {#
    #} {# #} diff --git a/management/templates/management/organization-management.html b/management/templates/management/organization-management.html index f9e36d6..d9768f4 100644 --- a/management/templates/management/organization-management.html +++ b/management/templates/management/organization-management.html @@ -42,6 +42,22 @@

    单位列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    单位总计:{{ organization_count }}

    {#
    #} {# #} @@ -60,7 +76,7 @@
    -{# #} + {# #} @@ -70,12 +86,12 @@ {% for r in res %} - + -{# #} + {# #} diff --git a/management/templates/management/user-management.html b/management/templates/management/user-management.html index ab1dfce..5c8feca 100644 --- a/management/templates/management/user-management.html +++ b/management/templates/management/user-management.html @@ -23,6 +23,23 @@

    成员列表

    +
    +
    + +
    +
    +
    + + + + +
    +
    +

    成员总计:{{ user_count }}

    @@ -45,8 +62,9 @@ {% for u in userallinfo %}
    - + diff --git a/management/urls.py b/management/urls.py index 22e1f6d..77765c3 100644 --- a/management/urls.py +++ b/management/urls.py @@ -11,6 +11,7 @@ urlpatterns = [ path('group/management/init/', views.group_management_init, name='group-management-management-init'), path('group/management/admin/', views.group_management_admin, name='group-management-management-admin'), path('group/management/user/', views.group_management_user, name='group-management-management-user'), + path('group/management/super/', views.group_management_superuser, name='group-management-management-superuser'), path('group/create/', views.group_create, name='group-management-create'), path('group/update//', views.group_update, name='group-management-update'), path('group/delete//', views.group_delete, name='group-management-delete'), diff --git a/management/views.py b/management/views.py index 8e3de4d..ad292a4 100644 --- a/management/views.py +++ b/management/views.py @@ -153,6 +153,8 @@ def user_update(request, pk): def group_management_init(request): user = request.user + level = Userprofile.objects.get(user_id=user.id).organization.level.level + print(level) init_count = Group.objects.filter(user_id=user.id).count() # 创建的矩阵 group_initer = Group.objects.filter(user_id=user.id).order_by('-created') @@ -176,13 +178,14 @@ def group_management_init(request): o1['user_count'] = Group_user.objects.filter(group_id=r_g_i.id).count() o1['status'] = r_g_i.status res_g_i.append(o1) - return render(request, 'management/group-management-init.html', {'group': group, 'res_g_i': res_g_i,'init_count':init_count}) + return render(request, 'management/group-management-init.html', {'group': group, 'res_g_i': res_g_i,'init_count':init_count,'level':level}) @login_required def group_management_admin(request): # 管理的矩阵 user = request.user + level = Userprofile.objects.get(user_id=user.id).organization.level.level admin_count = Group_admin.objects.filter(user_id=user.id).count() group_admin_list = [] for g_a in Group_admin.objects.filter(user_id=user.id).order_by('-created'): @@ -207,13 +210,14 @@ def group_management_admin(request): o2['user_count'] = Group_user.objects.filter(group_id=r_g_a.id).count() o2['status'] = r_g_a.status res_g_a.append(o2) - return render(request, 'management/group-management-admin.html', {'group': group, 'res_g_a': res_g_a,'admin_count':admin_count}) + return render(request, 'management/group-management-admin.html', {'group': group, 'res_g_a': res_g_a,'admin_count':admin_count,'level':level}) @login_required def group_management_user(request): # 加入的矩阵 user = request.user + level = Userprofile.objects.get(user_id=user.id).organization.level.level user_count = Group_user.objects.filter(user_id=user.id).count() group_user_list = [] for g_u in Group_user.objects.filter(user_id=user.id).order_by('-created'): @@ -238,7 +242,35 @@ def group_management_user(request): o3['user_count'] = Group_user.objects.filter(group_id=r_g_u.id).count() o3['status'] = r_g_u.status res_g_u.append(o3) - return render(request, 'management/group-management-user.html', {'group': group, 'res_g_u': res_g_u,'user_count':user_count}) + return render(request, 'management/group-management-user.html', {'group': group, 'res_g_u': res_g_u,'user_count':user_count,'level':level}) +@login_required +def group_management_superuser(request): + + user = request.user + level = Userprofile.objects.get(user_id=user.id).organization.level.level + count = Group.objects.all().count() + # 创建的矩阵 + 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_g_i = [] + for r_g_i in group: + o1 = dict() + o1['id'] = str(r_g_i.id) + o1['image'] = r_g_i.image.url + o1['name'] = r_g_i.name + o1['type'] = r_g_i.type + o1['admin_count'] = Group_admin.objects.filter(group_id=r_g_i.id).count() + o1['user_count'] = Group_user.objects.filter(group_id=r_g_i.id).count() + o1['status'] = r_g_i.status + res_g_i.append(o1) + return render(request, 'management/group-management-superuser.html', {'group': group, 'res_g_i': res_g_i,'count':count,'level':level}) @login_required @@ -979,7 +1011,8 @@ def newmedia_management_edit_weixin(request): for w in weixin: o = dict() o['id'] = str(w.id) - o['image'] = w.image + if w.image: + o['image'] = w.image o['code'] = w.code o['weixinid'] = w.weixinid o['organization'] = w.organization.name
    序号 图标 单位名称类型类型行政区划 成员数量 新媒体数量
    {{ forloop.counter }}{{ forloop.counter }} {{ r.name }}{{ r.organizationtype }}{{ r.organizationtype }}{{ r.administrativedivision }} {{ r.usercount }} {{ r.mediacount }}
    {{ forloop.counter }} {{ u.name }} {{ u.phone }} {{ u.organization }}