def test_user_update_user_form_name_is_not_valid_MAX(self):
     form_data = {'name': self.name_invalid_MAX,
                  'date_of_birth': self.date_of_birth_invalid,
                  'phone': self.phone_valid,
                  'sex': self.sex_valid,
                  }
     form = UpdateUserForm(data=form_data, instance=self.user)
     self.assertFalse(form.is_valid())
示例#2
0
def get_index_base_context(request):
    u = request.user
    info_form = UpdateUserForm()
    info_form.initial = {'user': u, 'first_name': u.first_name, 'last_name': u.last_name, 'email': u.email}

    password_form = UpdatePasswordForm(username=request.user.username)

    c = {'username': u.username, INFO_FORM: info_form, PASSWORD_FORM: password_form}
    return c
 def test_user_update_user_form_valid(self):
     form_data = {'name': self.name_valid,
                  'date_of_birth': self.date_of_birth_valid,
                  'phone': self.phone_valid,
                  'sex': self.sex_valid,
                  'password': self.password_valid
                  }
     form = UpdateUserForm(data=form_data, instance=self.user)
     self.assertTrue(form.is_valid())
示例#4
0
def update(request):
    if request.POST:
        form = UpdateUserForm(request.POST)

        if form.is_valid():
            current_user = request.user

            #current_user.profile_pic = form.cleaned_data['profile_pic']
            current_user.first_name = form.cleaned_data['first_name']
            current_user.last_name = form.cleaned_data['last_name']
            current_user.email = form.cleaned_data['email']
            current_user.save()
        else:
            c = get_index_base_context(request)
            c[INFO_FORM] = form
            return render(request, 'accounts/manage.html', c)

    return HttpResponseRedirect('/user/')
示例#5
0
def edit_user_info(request):
    msg = None
    msg_type = None
    user = request.user
    if request.method == 'POST':
        user_form = UpdateUserForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST, instance=user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            password_match = check_password(request.POST['password'],
                                            user.password)
            if password_match:
                user = user_form.save()
                profile_form.save(user)
                msg = 'Changes successfully saved'
                msg_type = 'SUCCESS'
            else:
                msg = 'Password is incorrect'
                msg_type = 'ERROR'
    else:
        user_form = UpdateUserForm(instance=user)
        profile_form = ProfileForm(instance=user.profile)

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'password_form': PasswordForm(),
        'msg': msg,
        'msg_type': msg_type,
    }

    return render(request, 'user/edit_user.html', context=context)
示例#6
0
def index(request):
    if request.method == 'GET':
        email = base64.b64decode(request.GET['email'])
        token = request.GET['token']
        #检测用户登录
        user = checkLogin(email,token)
        if not user:
            data = {"status" : "error",
                    "msg" : "User not login"
                    }
            return HttpResponse(json.dumps(data), content_type="application/json")
        data = {"status" :  "success",
                "msg" :  '',
                "data" :  {
                    "email" : user.email,
                    "username" :  user.username,
                    "qq" : user.qq,
                    "addDate" :  user.addDate.strftime('%Y-%m-%d')
                    }
                }
        resume = Resume.objects.filter(userEmail__exact = email).first()
        if resume:
            data['data'].update({
                "content" : resume.content,
                "display" : resume.display,
                "contentDate" : resume.addDate.strftime('%Y-%m-%d %H:%m')
                })
        return HttpResponse(json.dumps(data), content_type="application/json")

    elif request.method == 'PUT':
        rst = json.loads(request.body.decode("utf-8"))
        rst['email'] = base64.b64decode(rst['email'])
        uf = UpdateUserForm(rst)
        if uf.is_valid():
            email = uf.cleaned_data['email']
            token = uf.cleaned_data['token']
            #检测用户登录
            user = checkLogin(email,token)
            if not user:
                data = {"status" : "error",
                        "msg" : "User not login"
                        }
                return HttpResponse(json.dumps(data), content_type="application.json")
            user.username = uf.cleaned_data['username']
            user.qq = uf.cleaned_data['qq']
            user.save()
            resume = Resume.objects.filter(userEmail__exact = email).first()
            if not resume:
                resume = Resume()
                resume.userEmail = email
            resume.content = uf.cleaned_data['content']
            resume.display = uf.cleaned_data['display']
            resume.save()

            data = {"status" : "success",
                    "msg" :  ''
                    }
            return HttpResponse(json.dumps(data), content_type="application/json")
        else:
            data = {"status" : "error",
                    "msg" : 'Form error'
                    }
            return HttpResponse(json.dumps(data), content_type="application/json")