Ejemplo n.º 1
0
def table_add(request, app_name, model_name):
    admin_obj = site.registered_sites[app_name][model_name]  #获取表对象
    model_form = forms.CreateModelForm(
        request, admin_obj=admin_obj)  ##modelform 生成表单 加验证
    if request.method == "GET":
        obj_form = model_form()

    elif request.method == "POST":
        password = request.POST.get('password')  #取前端输入的密码
        email = request.POST.get('email')  #取前端输入的邮箱

        obj_form = model_form(data=request.POST)  #创建数据
        if obj_form.is_valid():
            obj_form.save()

        if not obj_form.errors:  #没有错误返回原来的页面
            #from django.shortcuts import redirect
            if email:
                obj = admin_obj.model.objects.filter(email=email).first()  # 对象
                obj.set_password(password)  # 加密
            try:
                obj.save()  #表单验证通过保存
            except Exception as e:
                return redirect("/king_admin/%s/%s/" % (app_name, model_name))
            return redirect("/king_admin/%s/%s/" % (app_name, model_name))
    return render(request, "king_admin/table_add.html", locals())
Ejemplo n.º 2
0
def gbacc_modify(request, user_id):  #用户密码修改
    admin_obj = base_admin.site.registered_sites['crm']['userprofile']  #表类
    model_form = kingforms.CreateModelForm(
        request, admin_obj=admin_obj)  #modelform 生成表单 加验证
    obj = admin_obj.model.objects.get(id=user_id)  #类表的对象
    errors = {}  #错误提示
    if request.method == 'POST':
        _password0 = request.POST.get('password0')
        user = authenticate(username=obj.email, password=_password0)  #调用用户认证模块
        print('obj.email', obj.email)
        print('验证比对数据库', user)
        _password1 = request.POST.get('password1')
        _password2 = request.POST.get('password2')
        if user:
            if _password1 == _password2:
                if len(_password1) > 5:
                    obj.set_password(_password1)  #继承Django方法 #加密
                    obj.save()
                    return redirect('/gbacc/gbacc_login/')
                else:
                    errors['password_too_short'] = '密码必须不少于6字符'
            else:
                errors['invalid_password'] = '******'
        else:
            errors['original_password'] = '******'
    return render(request, 'gbacc_specific/gbacc_modify.html', locals())


# ————————41PerfectCRM实现全局账号密码修改————————
# gbacc_views.py
Ejemplo n.º 3
0
def modify(request, user_id):  #用户密码修改
    '''密码修改'''
    admin_obj = base_admin.site.registered_sites['crm']['userprofile']  #表类
    model_form = kingforms.CreateModelForm(
        request, admin_obj=admin_obj)  #modelform 生成表单 加验证
    obj = admin_obj.model.objects.get(id=user_id)  #类表的对象
    errors = {}  #错误提示
    if request.method == 'POST':
        ret = {}
        _password1 = request.POST.get('password1')
        _password2 = request.POST.get('password2')
        if _password1 == _password2:
            if len(_password1) > 8:
                obj.set_password(_password1)
                obj.save()
                ret = '密码修改成功!'
                return redirect('/accounts/login/')
                #return HttpResponse(json.dumps(ret))

            else:
                errors['password_too_short'] = 'must not less than 8 letters'
        else:
            errors['invalid_password'] = '******'  #密码不一致

    return render(request, 'modify.html', locals())
Ejemplo n.º 4
0
def table_change(request, app_name, model_name, obj_id):
    admin_obj = base_admin.site.registered_sites[app_name][model_name]  #表对象
    model_form = forms.CreateModelForm(
        request, admin_obj=admin_obj)  #modelform 生成表单 加验证
    obj = admin_obj.model.objects.get(id=obj_id)  #根据ID获取数据记录
    if request.method == "GET":  #如果是 GET 表示 是添加记录
        obj_form = model_form(instance=obj)  #数据传入表单
    elif request.method == "POST":  #如果是 POST 表示 是修改后的数据
        obj_form = model_form(instance=obj, data=request.POST)  #更新数据
        if obj_form.is_valid():
            obj_form.save()
            messages.info(request, '保存成功!', extra_tags='', fail_silently=False)

    return render(request, "king_admin/table_change.html", locals())
Ejemplo n.º 5
0
def password_reset(request, app_name, model_name, obj_id):
    admin_obj = site.registered_sites[app_name][model_name]  #表类
    model_form = forms.CreateModelForm(
        request, admin_obj=admin_obj)  #modelform 生成表单 加验证
    obj = admin_obj.model.objects.get(id=obj_id)  #类表的对象
    errors = {}  #错误提示
    if request.method == 'POST':
        _password1 = request.POST.get('password1')  #获取页面输入的值
        _password2 = request.POST.get('password2')  #获取页面输入的值
        if _password1 == _password2:
            if len(_password1) > 5:
                obj.set_password(_password1)  #继承Django方法 #加密
                obj.save()  #保存
                return redirect(
                    request.path.rstrip('password/') + ('/change/'))  #替换URL名
            else:
                errors['password_too_short'] = '必须不少于6字符'
        else:
            errors['invalid_password'] = '******'  #密码不一致
    return render(request, "king_admin/password_reset.html", locals())
Ejemplo n.º 6
0
def table_change(request, app_name, model_name, obj_id):
    admin_obj = site.registered_sites[app_name][model_name]  #获取表对象
    #kingadmin/forms.py里def CreateModelForm(request,admin_obj):
    model_form = forms.CreateModelForm(
        request, admin_obj=admin_obj)  ##modelform 生成表单 加验证
    # obj_form = model_form()  # 表单
    obj = admin_obj.model.objects.get(id=obj_id)  #根据ID获取数据记录

    # ————————20PerfectCRM实现King_admin数据修改美化————————
    # #面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可能不同。
    # obj_form = model_form(instance=obj)  # 数据传入表单

    if request.method == "GET":
        obj_form = model_form(instance=obj)
    elif request.method == "POST":
        obj_form = model_form(instance=obj, data=request.POST)
        if obj_form.is_valid():
            obj_form.save()
    # ————————20PerfectCRM实现King_admin数据修改美化————————

    return render(request, "king_admin/table_change.html", locals())
Ejemplo n.º 7
0
def password_reset(request, app_name, model_name, obj_id):
    '''密码修改'''
    admin_obj = base_admin.site.registered_sites[app_name][model_name]  #表类
    model_form = forms.CreateModelForm(
        request, admin_obj=admin_obj)  #modelform 生成表单 加验证
    obj = admin_obj.model.objects.get(id=obj_id)  #类表的对象
    errors = {}  #错误提示
    if request.method == 'POST':
        _password1 = request.POST.get('password1')
        _password2 = request.POST.get('password2')
        if _password1 == _password2:
            if len(_password1) > 8:
                obj.set_password(_password1)
                obj.save()
                return redirect(request.path.rstrip('password/'))
            else:
                errors['password_too_short'] = 'must not less than 8 letters'
        else:
            errors['invalid_password'] = '******'  #密码不一致

    return render(request, "king_admin/password_reset.html",
                  locals())  #locals 返回一个包含当前范围的局部变量字典。
Ejemplo n.º 8
0
def table_add(request, app_name, model_name):
    admin_obj = base_admin.site.registered_sites[app_name][model_name]  #表对象
    admin_obj.is_add_form = True  #表示为新增表单
    model_form = forms.CreateModelForm(request, admin_obj=admin_obj)  #生成 表单
    if request.method == "GET":
        print('get--->add', model_form)
        obj_form = model_form()  #跳转过来的为空

    elif request.method == "POST":
        obj_form = model_form(data=request.POST)  #添加数据
        if obj_form.is_valid():
            try:
                obj_form.save()  #表单验证通过保存
            except Exception as e:
                return redirect("/king_admin/%s/%s/" %
                                (app_name, model_name))  #转到之前的页面
        if not obj_form.errors:
            return redirect("/king_admin/%s/%s/" %
                            (app_name, model_name))  #转到之前的页面

    return render(request, "king_admin/table_add.html",
                  locals())  #locals 返回一个包含当前范围的局部变量字典。