Beispiel #1
0
def edit(request, *args, **kwargs):
    # 如果编辑教师时,修改教师的生日,导致(name, birthday, school)
    # 与已删除的隐藏记录重复,这里先删掉隐藏教师。
    if request.method == 'POST':
        try:
            uu = request.POST.get('uuid')
            record = models.Teacher.objects.get(uuid=uu)
        except:
            traceback.print_exc()
            return create_failure_dict(msg='错误的uuid!')

        teacher_form = TeacherForm(request.POST, instance=record)

        if teacher_form.is_valid():
            teacher = teacher_form.save(commit=False)
            school = models.Group.objects.get(group_type='school')
            teacher.school = school
            try:
                teacher.save()
            except IntegrityError, e:
                if 'Duplicate entry' in str(e):
                    return create_failure_dict(msg='已存在同名且同生日的教师')
                old = models.Teacher.objects.get(name=teacher.name,
                                                 school=school,
                                                 birthday=teacher.birthday,
                                                 deleted=True)
                old.delete()
                teacher.save()
            except Exception as e:
                traceback.print_exc()
                return create_failure_dict(msg='服务器错误', debug=str(e))
            return create_success_dict(msg='编辑教师成功!',
                                       data=model_to_dict(teacher))
Beispiel #2
0
def get_settings(request):
    try:
        server_type = models.Setting.getvalue('server_type')
        func = models.Setting.objects.get
        if server_type == 'school':
            obj = func(name='desktop-preview-interval')
            interval = int(obj.value)
            data = {'desktop-preview-interval': interval}
        elif server_type == 'country':
            interval = int(func(name='desktop-preview-interval').value)
            days = int(func(name='desktop-preview-days-to-keep').value)
            sp = func(name='cloud-service-provider').value
            username = func(name='cloud-service-username').value
            password = func(name='cloud-service-password').value
            data = {
                'desktop-preview-interval': interval,
                'desktop-preview-days-to-keep': days,
                'cloud-service-provider': sp,
                'cloud-service-username': username,
                'cloud-service-password': password,
            }
        else:
            return create_failure_dict(msg='错误的服务器级别')
        return create_success_dict(data=data)
    except:
        return create_failure_dict(msg='管理员尚未设置参数')
Beispiel #3
0
def get_mac_status(request, *args, **kwargs):
    '''从MAC地址查询班级申报状态'''
    if models.Setting.getvalue('server_type') != 'school':
        return create_failure_dict()
    terms = models.Term.get_current_term_list()
    if not terms:
        return create_failure_dict(msg=u'当前时间不在任何学期内')

    mac = request.GET.get('mac', '').strip()
    ip = request.META['REMOTE_ADDR']
    data = {
        'reported': False,
        'computerclass': False,
        'class_uuid': None,
        'grade_uuid': None
    }

    if not mac:
        return create_failure_dict(msg=u'客户端MAC获取失败.')
    try:
        o = models.ClassMacV2.objects.get(mac=mac,
                                          class_uuid__grade__term__in=terms)
        if o.ip != ip:
            o.ip = ip
            o.save()
        data['reported'] = True
        data['class_uuid'] = o.class_uuid.uuid
        data['grade_uuid'] = o.class_uuid.grade.uuid
        data['computerclass'] = (o.class_uuid.grade.number == 13)
    except models.ClassMacV2.DoesNotExist:
        simplecache.set_class_noreport_heartbeat_ip(ip)
    except Exception as e:
        logger.exception('')
        return create_failure_dict(data=data, msg=u'客户端状态获取失败', debug=str(e))
    return create_success_dict(data=data)
Beispiel #4
0
def edit_school_post(request):
    '''
        编辑校园公告
    '''
    if models.Setting.getvalue('server_type') != 'school':
        return create_failure_dict(msg='仅校服务器可用')

    if request.method == 'POST':
        id = request.POST.get('id', None)
        title = request.POST.get('title', '').strip()
        content = request.POST.get('content', '').strip()
        active = request.POST.get('active', False)

        try:
            obj = models.SchoolPost.objects.get(pk=id)
        except Exception:
            return create_failure_dict(msg=u'没有该校园公告')

        obj.title = title
        obj.content = content
        obj.active = active

        obj.save()

        return create_success_dict(msg=u'编辑校园公告成功')

    return create_failure_dict(msg=u'编辑校园公告失败')
Beispiel #5
0
def lesson_enable(request):
    if request.method == 'POST':
        if not cache.get('sudo'):
            return create_failure_dict(msg='请输入正确的超级管理员admin密码!')

        lesson_name = request.POST.get('lesson_name', '')
        grade_name = request.POST.get('grade_name', '')
        publish = request.POST.get('publish', '')
        bookversion = request.POST.get('bookversion', '')
        term_uuid = request.POST.get('term_uuid', '')
        try:
            t = models.NewTerm.objects.get(uuid=term_uuid)
        except:
            return create_failure_dict(msg='错误的学年学期')

        try:
            obj = models.SyllabusGradeLesson.objects.get(
                syllabus_grade__school_year=t.school_year,
                syllabus_grade__term_type=t.term_type,
                syllabus_grade__grade_name=grade_name,
                lesson_name=lesson_name,
                publish=publish,
                bookversion=bookversion)
        except:
            return create_failure_dict(msg='错误的课程')

        if obj.in_use:
            return create_failure_dict(msg='该课程已启用')

        obj.in_use = True
        obj.save()

        return create_success_dict(msg='启用成功')
Beispiel #6
0
def lesson_del(request):
    if request.method == 'POST':
        if not cache.get('sudo'):
            return create_failure_dict(msg='请输入正确的超级管理员admin密码!')

        id = request.POST.get('id', '')
        try:
            lesson = models.SyllabusGradeLesson.objects.get(id=id)
        except Exception:
            return create_failure_dict(msg='错误的课程信息')

        # if lesson.syllabus_grade.in_use:
        #    return create_failure_dict(msg='已启用的年级不能删除课程')

        # 处理该课程下的大纲
        contents = lesson.syllabusgradelessoncontent_set.all()
        for content in contents:
            # 大纲对应的登录记录
            content.teacherloginloglessoncontent_set.all().delete()
            # 大纲本身
            content.delete()

        # 处理课程
        lesson.delete()

        return create_success_dict(msg='课程删除成功')
Beispiel #7
0
def clean_token(request, *args, **kwargs):
    """客户端取消当前的登录操作,清除掉本次登录产生的token"""
    client_mac = request.GET.get('mac')
    term = models.Term.get_current_term_list()
    if not term:
        return create_failure_dict(msg=u'无可用学年学期.', debug='no term')
    cls = models.ClassMacV2.objects.filter(
        mac=client_mac,
        class_uuid__grade__term=term[0]
    )
    if not cls.exists():
        return create_failure_dict(msg=u'客户端尚未申报.', debug='not reported')

    uuid = str(cls[0].class_uuid.pk).lower().replace('-', '')
    models.Token.objects.filter(
        token_type='lesson_start',
        value=uuid
    ).all().delete()
    return create_success_dict(debug=uuid)

    # 前端要求这里只传递MAC地址,所以换成上面的清理方法.
    token_key = request.GET.get('token')
    if token_key:
        tokens = models.Token.objects.filter(token_type='lesson_start', value=token_key)
        tokens.all().delete()
        return create_success_dict(debug=token_key)
    return create_failure_dict(msg=u'参数获取失败.', debug='token')
Beispiel #8
0
def lesson_list(request):
    #pk = request.GET.get('id')
    grade_name = request.GET.get('grade_name', '')
    term_uuid = request.GET.get('term_uuid', '')
    try:
        t = models.NewTerm.objects.get(uuid=term_uuid)
    except:
        return create_failure_dict(msg='错误的学年学期')

    # 保存syllabusgrade
    try:
        obj, c = models.SyllabusGrade.objects.get_or_create(
            school_year=t.school_year,
            term_type=t.term_type,
            grade_name=grade_name,
            defaults={'in_use': False})
    except:
        return create_failure_dict(msg='错误的班级信息')

    q = models.SyllabusGradeLesson.objects.filter(syllabus_grade=obj)
    q = q.values()

    return create_success_dict(
        data={
            'records': model_list_to_dict(q),
            'host': 'http://oebbt-cover.qiniudn.com',
            'RESOURCE_PLATFORM_HOST': constants.RESOURCE_PLATFORM_HOST
        })
Beispiel #9
0
def get_unreported(request, *args, **kwargs):
    """客户端获取未申报的电脑教室列表"""
    if models.Setting.getvalue('server_type') != 'school':
        return create_failure_dict()
    term = models.Term.get_current_term_list()
    if not term:
        return create_failure_dict(msg='当前时间不在任何学期内')
    t = term[0]
    cc = models.ComputerClass.objects.filter(class_bind_to__grade__term=t)
    if cc.exists():
        uuids = models.ClassMacV2.objects.all().values_list('class_uuid',
                                                            flat=True)
        cc = cc.exclude(class_bind_to__in=uuids).order_by(
            'class_bind_to__name',
            'class_bind_to__number').values_list('class_bind_to',
                                                 'class_bind_to__name',
                                                 'class_bind_to__number',
                                                 'class_bind_to__grade__uuid',
                                                 flat=False)
        data = map(
            lambda c: {
                'uuid': c[0],
                'name': c[1],
                'number': c[2],
                'grade_uuid': c[3]
            }, cc)
        return create_success_dict(data=data, term=model_list_to_dict(term))
    return create_success_dict(data=[])
Beispiel #10
0
def lesson_name(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(failure)

        f = LessonNameFormSet(request.POST)
        if f.is_valid():
            models.LessonName.objects.all().delete()  # 删除旧数据进行全新安装
            school = models.Group.objects.get(group_type='school')
            for i in f.forms:
                obj = i.save(commit=False)
                obj.school = school
                obj.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)
    elif request.method == 'GET':
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.LessonName.objects.all().values('name')
        return create_success_dict(data=model_list_to_dict(q))
Beispiel #11
0
def delete(request, *args, **kwargs):
    """
        教学点管理>删除节点
    """
    if request.method == 'POST':
        if not cache.get('sudo'):
            return create_failure_dict(msg='请输入正确的超级管理员admin密码!')

        if Setting.getvalue('server_type') != 'country':
            return create_failure_dict(msg='教学点仅支持县级服务器')

        id = request.POST.get('uuid')
        try:
            obj = EduPoint.objects.get(id=id)
        except Exception, e:
            logger.exception(e)
            return create_failure_dict(msg='无该教学点ID, 不能删除')

        # 如果该教学点下的教室有已申报的情况,需要提示先取消申报才可删除教学点
        if not obj.has_delete():
            return create_failure_dict(msg='先解除终端绑定,才能删除教学点!')

        obj.delete()

        return create_success_dict(msg='成功删除教学点')
Beispiel #12
0
def resource_catalog_add(request):
    '''
        教学点对应的卫星资源接收目录添加
    '''
    if request.method == 'POST':
        if Setting.getvalue('server_type') != 'country':
            return create_failure_dict(msg='教学点仅支持县级服务器')

        f = EduPointResourceCatalogForm(request.POST)
        if f.is_valid():
            catalog = f.cleaned_data['catalog']
            edupoint_id = request.POST.get('edupoint_id')
            try:
                edupoint = EduPoint.objects.get(id=edupoint_id)
            except Exception, e:
                logger.exception(e)
                return create_failure_dict(msg='无该教学点ID')

            if edupoint.edupointresourcecatalog_set.all().count() >= 10:
                return create_failure_dict(msg='教学点只能拥有10个资源接收目录')

            obj, c = EduPointResourceCatalog.objects.get_or_create(edupoint=edupoint, catalog=catalog)

            if not c:
                return create_failure_dict(msg='教学点不能保存相同的资源接收目录')

            return create_success_dict(msg='成功添加教学点卫星资源接收目录')
Beispiel #13
0
def grade_class(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)

        f = ClassFormSet(request.POST)
        if f.is_valid():
            # 删除旧数据进行全新安装
            cursor = connection.cursor()
            cursor.execute('DELETE FROM `Class`')
            cursor.execute('DELETE FROM `Grade`')
            for i in f.forms:
                i.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)

    elif request.method == 'GET':
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.Class.objects.all().values('grade__name', 'name')
        return create_success_dict(data=model_list_to_dict(q))
Beispiel #14
0
def edit(request):
    '''
        教学点管理>编辑
    '''
    if request.method == 'POST':
        if Setting.getvalue('server_type') != 'country':
            return create_failure_dict(msg='教学点仅支持县级服务器')

        id = request.POST.get('uuid')
        obj = EduPoint.objects.get(id=id)

        f = EduPointEditForm(request.POST, instance=obj)
        if f.is_valid():
            number = f.cleaned_data['number']
            remark = f.cleaned_data['remark']
            if number < obj.number:
                return create_failure_dict(msg='教学点修改终端数量不能小于原始数量')

            obj.number = number
            obj.remark = remark
            obj.save()

            return create_success_dict(msg='成功编辑教学点')

        return create_failure_dict(msg='教学点添加失败', errors=f.errors)
Beispiel #15
0
def add(request, *args, **kwargs):
    if request.method == 'POST':
        try:
            f = LessonTeacherForm(request.POST)
            if f.is_valid():
                lesson_teacher = f.save()
                simplecache.LessonTeacher.update(
                    lesson_teacher.class_uuid.uuid)
                data = model_to_dict(lesson_teacher)
                school_year = lesson_teacher.class_uuid.grade.term.school_year
                data['class_uuid__grade__term__school_year'] = school_year
                term_type = lesson_teacher.class_uuid.grade.term.term_type
                data['class_uuid__grade__term__term_type'] = term_type
                grade_name = lesson_teacher.class_uuid.grade.name
                data['class_uuid__grade__name'] = grade_name
                data['class_uuid__name'] = lesson_teacher.class_uuid.name
                data['lesson_name__name'] = lesson_teacher.lesson_name.name
                data['teacher__name'] = lesson_teacher.teacher.name
                try:
                    stat_obj = models.Statistic.objects.get(
                        key=lesson_teacher.class_uuid.pk)
                    stat_obj.cala('teacher_num', True)
                except Exception as e:
                    logger.exception(e)
                return create_success_dict(msg='添加班级课程授课教师记录成功!', data=data)

            return create_failure_dict(msg='添加班级课程授课教师记录失败!', errors=f.errors)
        except IntegrityError:
            msg = '已有相同的年级班级-课程-教师姓名,无法重复添加!'
            return create_failure_dict(msg=msg)
        except Exception as e:
            logger.exception(e)
            return create_failure_dict(msg=u'添加班级课程授课教师记录失败!', debug=str(e))
Beispiel #16
0
def usb_check(request):
    if models.Setting.getvalue('server_type') != 'school':
        return create_failure_dict()
    if request.method == 'GET':
        key = request.GET.get('key')
        mac = request.GET.get('mac')
        try:
            u = models.UsbkeyTeacher.objects.get(usbkey_uuid=key)
        except:
            return create_failure_dict(msg='无效的USBKey!')
        try:
            t = models.Teacher.objects.get(uuid=u.teacher_uuid)
        except:
            return create_failure_dict(msg='找不到对应教师!')
        try:
            c = models.Class.objects.get(classmacv2__mac=mac)
        except:
            return create_failure_dict(msg='MAC地址未申报!')
        q = models.LessonTeacher.objects.filter(class_uuid=c, teacher=t)
        if not q.exists():
            return create_failure_dict(msg='教师在本班没有排课!')
        data = {
            'teacher': {
                'key': t.uuid,
                'sequence': t.sequence,
                'name': t.name,
                'password': t.password
            }
        }
        return create_success_dict(data=data)
Beispiel #17
0
def delete(request, *args, **kwargs):
    if request.method == 'POST':
        if not cache.get('sudo'):
            return create_failure_dict(msg='请输入正确的超级管理员admin密码!')
        uu = request.POST.get('uuid')
        if uu:
            try:
                l = models.LessonPeriod.objects.get(uuid=uu)
            except:
                return create_failure_dict(msg='错误的uuid!')
            term = l.term
            try:
                if not term.allow_import_lesson():
                    return create_failure_dict(msg='该作息时间对应的学年学期已过期,不能删除')
            except Exception, e:
                logger.exception(e)
                return create_failure_dict(msg='该作息时间对应学年学期有误,删除失败')

            max_sequence = models.LessonPeriod.objects.filter(term=term)
            max_sequence = max_sequence.aggregate(Max('sequence'))
            if l.sequence == max_sequence['sequence__max']:
                l.delete()
                return create_success_dict(msg='删除作息时间成功!')
            else:
                return create_failure_dict(msg='只能删除最大的一个节次!')
Beispiel #18
0
def term(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)

        f = TermFormSet(request.POST)
        if f.is_valid():
            models.Term.objects.all().delete()  # 删除旧数据进行全新安装
            for i in f.forms:
                i.save()
            install_step = models.Setting.objects.get(name='install_step')
            install_step.value = request.POST['install_step']
            install_step.save()
            return create_success_dict(msg='安装成功!')

        return create_failure_dict(msg='安装失败!', errors=f.errors)

    elif request.method == "GET":
        if models.Setting.getvalue('installed') == 'True':
            return HttpResponseRedirect('/')

        q = models.Term.objects.all().values('term_type', 'start_date',
                                             'end_date', 'school_year')
        return create_success_dict(data=model_list_to_dict(q))
Beispiel #19
0
def add(request, *args, **kwargs):
    """年级班级管理>班班通电脑教室>添加教室"""
    term = models.Term.get_current_term_list()[0]
    if not term:
        return create_failure_dict(msg=u'当前时间不在任何学年学期内')
    f = ComputerClassForm(request.POST, request=request)
    if not f.is_valid():
        return create_failure_dict(msg=u'添加失败', errors=f.errors)
    f.save()
    return create_success_dict(msg=u'添加成功')
Beispiel #20
0
def resource_type_delete(request):
    if request.method == 'POST':
        uu = request.POST.get('uuid')
        if uu:
            try:
                obj = models.ResourceType.objects.get(uuid=uu)
                obj.delete()
                return create_success_dict(msg='删除资源类型成功')
            except:
                return create_failure_dict(msg='错误的uuid')
        return create_failure_dict(msg='uuid不能为空')
Beispiel #21
0
def get_settinginfo(request):
    field_name = request.GET.get('field', None)
    if not field_name:
        return create_failure_dict()
    try:
        o = models.Setting.objects.get(name=field_name)
        return create_success_dict(data={field_name: o.value})
    except models.Setting.DoesNotExist:
        return create_failure_dict()
    except Exception as e:
        return create_failure_dict(msg=str(e))
Beispiel #22
0
def lesson_teacher_import(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)
        f = LessonTeacherUploadForm(request.POST, request.FILES)
        if f.is_valid():
            objs = f.save()
            return create_success_dict(data=model_list_to_dict(objs))

        return create_failure_dict(msg='导入班级课程授课老师失败!', errors=f.errors)
Beispiel #23
0
def grade_class_import(request, *args, **kwargs):
    if request.method == 'POST':
        if models.Setting.getvalue('installed') == 'True':
            failure = '您已经配置过本服务器,无法重新配置!'
            return create_failure_dict(msg=failure)
        f = ClassUploadForm(request.POST, request.FILES)
        if f.is_valid():
            classes = f.save()
            return create_success_dict(data=model_list_to_dict(classes))

        return create_failure_dict(msg='导入学校年级班级失败!', errors=f.errors)
Beispiel #24
0
def make_term_uuid():
    if models.Setting.getvalue('server_type') == 'school':
        try:
            school = models.Group.objects.get(group_type='school')
        except Exception:
            return create_failure_dict(msg='学校错误')
        terms = models.Term.get_current_term_list(school=school)
        if terms:
            return terms[0].uuid
    else:
        return create_failure_dict(msg='非校级服务器!')
Beispiel #25
0
def clear_mac(request, *args, **kwargs):
    """年级班级管理>班班通电脑教室>清除绑定"""
    class_uuid = request.POST.get('uuid', None)
    if not class_uuid:
        return create_failure_dict(msg='未获取到电脑教室信息')
    try:
        models.ClassMacV2.objects.get(class_uuid=class_uuid).delete()
        return create_success_dict(msg='清除绑定成功')
    except Exception as e:
        return create_failure_dict(msg='清除绑定失败', errors=[
            [str(e)],
        ])
Beispiel #26
0
def computerclass_realtime(request, *args, **kwargs):
    """实时概况>电脑教室桌面预览"""
    node = request.GET.get('uuid', None)
    if not node:
        return create_failure_dict(msg='未获取到获取节点信息')

    only_computerclass = True
    is_ok, records = _get_globalpreviews(node, only_computerclass)
    if is_ok:
        return paginatoooor(request, records)

    return create_failure_dict(msg=records)
Beispiel #27
0
def export(request, *args, **kwargs):
    '''导出班级课程表'''
    grade_name = request.GET.get('grade_name', None)
    class_name = request.GET.get('class_name', None)
    xls = xlwt.Workbook(encoding='utf8')
    title = u'%s年级%s班课程表' % (grade_name, class_name)
    sheet = xls.add_sheet(title)
    header = (u'节次', u'周一', u'周二', u'周三', u'周四', u'周五', u'周六', u'周日')
    weekday = (u'mon', u'tue', u'wed', u'thu', u'fri', u'sat', u'sun')
    for i in range(len(header)):
        sheet.write(0, i, header[i])
    row = 1
    try:
        t = models.Term.get_current_term_list()[0]
    except:
        return create_failure_dict(msg='当前时间不在任何学期内')

    if not (grade_name and class_name):
        return create_failure_dict(
            msg='grade_name and class_name are required')
    klass = models.Class.objects.filter(grade__term=t,
                                        grade__name=grade_name,
                                        name=class_name)
    if not klass.exists():
        return create_failure_dict(msg='This class is not exists!')
    klass = klass[0]
    objs = models.LessonSchedule.objects.filter(class_uuid=klass)

    objs = objs.values(
        'lesson_period__sequence',
        'weekday',
        'lesson_name__name',
    )

    for i in objs:
        row = int(i['lesson_period__sequence'])
        column = weekday.index(i['weekday']) + 1
        try:
            sheet.write(row, 0, row)
        except:
            pass
        sheet.write(row, column, i['lesson_name__name'])

    cached_id = str(uuid.uuid1())
    tmp_file = os.path.join(constants.CACHE_TMP_ROOT, cached_id)
    xls.save(tmp_file)
    filename = u'%s.xls' % title
    return create_success_dict(url=reverse('base:xls_download',
                                           kwargs={
                                               'cached_id': cached_id,
                                               'name': filename
                                           }))
Beispiel #28
0
def edit(request, *args, **kwargs):
    if request.method == 'POST':
        try:
            pk = request.POST.get('id')
            node = models.Node.objects.get(id=pk)
            f = NodeForm(request.POST, instance=node)
            if f.is_valid():
                node = f.save()
                return create_success_dict(msg=u'编辑成功!',
                                           data=model_to_dict(node))
            return create_failure_dict(msg=u'操作失败', errors=f.errors)
        except Exception as e:
            return create_failure_dict(msg='操作失败', debug=str(e))
Beispiel #29
0
def delete(request, *args, **kwargs):
    if request.method == 'POST':
        uu = request.POST.get('uuid')
        record = models.User.objects.get(uuid=uu)
        if not is_admin(record):
            if request.current_user.username == record.username:
                return create_failure_dict(msg='当前登录用户无法删除!')
            models.UserPermittedGroup.objects.filter(user=record).delete()
            record.delete()
            return create_success_dict(msg='删除用户成功!')

        else:
            return create_failure_dict(msg='超级管理员不允许删除!')
Beispiel #30
0
def delete(request, *args, **kwargs):
    if request.method == 'POST':
        uu = request.POST.get('uuid')
        if uu:
            try:
                role = models.Role.objects.get(uuid=uu)
            except:
                return create_failure_dict(msg='错误的uuid!')
            if role.user_set.exists():
                return create_failure_dict(msg='有用户属于该角色,不能删除!')
            role.roleprivilege_set.all().delete()
            role.delete()
            return create_success_dict(msg='删除角色成功!')