Example #1
0
def myself_edit(request):
    user = User.objects.get(username=request.user.username)
    userprofile = UserProfile.objects.get(user=user)
    userinfo = UserInfo.objects.get(user=user)

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        userprofile_form = UserProfileForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() * userprofile_form.is_valid() * userinfo_form.is_valid():
            user_cd = user_form.cleaned_data
            userprofile_cd = userprofile_form.cleaned_data
            userinfo_cd = userinfo_form.cleaned_data
            user.email = user_cd['email']
            userprofile.birth = userprofile_cd['birth']
            userprofile.phone = userprofile_cd['phone']
            userinfo.school = userinfo_cd['school']
            userinfo.company = userinfo_cd['company']
            userinfo.profession = userinfo_cd['profession']
            userinfo.address = userinfo_cd['address']
            userinfo.about_me = userinfo_cd['about_me']
            user.save()
            userprofile.save()
            userinfo.save()
        return HttpResponseRedirect('/account/my-information/')
    else:
        user_form = UserForm(instance=request.user)
        userprofile_form = UserProfileForm(initial={'birth': userprofile.birth, 'phone': userprofile.phone})
        userinfo_form = UserInfoForm(initial={'school': userinfo.school, 'company': userinfo.company, 'profession': userinfo.profession, 'address': userinfo.address, 'about_me': userinfo.about_me})
        return render(request, 'account/myself_edit.html', {'user_form': user_form, 'userprofile_form': userprofile_form, 'userinfo_form': userinfo_form})
Example #2
0
def myself_edit(request):
    userprofile = UserProfile.objects.get(user=request.user) if \
        hasattr(request.user, 'userprofile') else UserProfile.objects.create(user=request.user)

    userinfo = UserInfo.objects.get(user=request.user) if hasattr(request.user, "userinfo") \
        else UserInfo.objects.create(user=request.user)

    if request.method == "POST":
        user_form = UserForm(request.POST)
        userprofile_form = UserProfileForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() * userprofile_form.is_valid(
        ) * userinfo_form.is_valid():
            user_cd = user_form.cleaned_data
            userinfo_cd = userinfo_form.cleaned_data
            userprofile_cd = userprofile_form.cleaned_data
            request.user.email = user_cd["email"]
            userprofile.birth = userprofile_cd["birth"]
            userprofile.phone = userprofile_cd["phone"]
            userinfo.school = userinfo_cd["school"]
            userinfo.company = userinfo_cd["company"]
            userinfo.profession = userinfo_cd["profession"]
            userinfo.address = userinfo_cd["address"]
            userinfo.aboutme = userinfo_cd["aboutme"]
            request.user.save()
            userprofile.save()
            userinfo.save()
        return HttpResponseRedirect('/account/my-information/')
    else:
        user_form = UserForm(instance=request.user)
        userprofile_form = UserProfileForm(initial={
            "birth": userprofile.birth,
            "phone": userprofile.phone
        })
        userinfo_form = UserInfoForm(
            initial={
                "school": userinfo.school,
                "company": userinfo.company,
                "profession": userinfo.profession,
                "address": userinfo.address,
                "aboutme": userinfo.aboutme
            })
        return render(
            request, "account/myself_edit.html", {
                "user_form": user_form,
                "userprofile_form": userprofile_form,
                "userinfo_form": userinfo_form
            })
Example #3
0
def myself_edit(request):
    user = User.objects.get(username=request.user.username)
    userprofile = UserProfile.objects.get(user=request.user)
    userinfo = UserInfo.objects.get(user=request.user)

    if request.method == "POST":
        user_form = UserForm(request.POST)
        userprofile_form = UserProfileForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() and userprofile_form.is_valid(
        ) and userinfo_form.is_valid():
            user_cd = user_form.cleaned_data
            userprofile_cd = userprofile_form.cleaned_data
            userinfo_cd = userinfo_form.cleaned_data
            print(user_cd["email"])
            user.email = user_cd["email"]
            userprofile.birth = userprofile_cd['birth']
            userprofile.phone = userprofile_cd['phone']
            userinfo.school = userinfo_cd['school']
            userinfo.company = userinfo_cd['company']
            userinfo.profession = userinfo_cd['profession']
            userinfo.address = userinfo_cd['address']
            userinfo.aboutme = userinfo_cd['aboutme']
            user.save()
            userprofile.save()
            userinfo.save()
        return HttpResponseRedirect('/account/my-information')
    else:
        user_form = UserForm(instance=request.user)
        userprofile_form = UserProfileForm(initial={
            "birth": userprofile.birth,
            "phone": userprofile.phone
        })
        userinfo_form = UserInfoForm(
            initial={
                "school": userinfo.school,
                "company": userinfo.company,
                "profession": userinfo.profession,
                "address": userinfo.address,
                "aboutme": userinfo.aboutme
            })
        return render(
            request, "account/myself_edit.html", {
                "user_form": user_form,
                "userprofile_form": userprofile_form,
                "userinfo_form": userinfo_form
            })
Example #4
0
def user_info_edit(request):
    user = User.objects.get(username=request.user.username)
    userinfo = UserInfo.objects.get(user=user)

    if request.method == "POST":
        userinfo_form = UserInfoForm(request.POST)

        if userinfo_form.is_valid():
            userinfo_cd = userinfo_form.cleaned_data
            userinfo.phone = userinfo_cd['phone']
            userinfo.email = userinfo_cd['email']
            userinfo.save()
        return HttpResponseRedirect(reverse('account:my_information'))
    else:
        userinfo_form = UserInfoForm(initial={"phone": userinfo.phone, "email": userinfo.email})
        return render(request, "account/userinfo_edit.html",
                      {"user": user, "userinfo": userinfo, "userinfo_form": userinfo_form})
Example #5
0
def user(request):
    if request.method == "POST":
        user_form = RegistrationForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() * userinfo_form.is_valid():
            new_user = user_form.save(commit=False)
            new_user.set_password(user_form.cleaned_data['password'])
            new_user.save()
            new_profile = userinfo_form.save(commit=False)
            new_profile.user = new_user
            new_profile.save()
            UserInfo.objects.create(user=new_user)
            return HttpResponse("successfully")
        else:
            return HttpResponse("抱歉,注册失败")
    else:
        role_list = Role.objects.all()
        user_list = UserInfo.objects.all()
        user_form = RegistrationForm()
        userinfo_form = UserInfoForm()
        return render(
            request, "system/user.html", {
                "user_list": user_list,
                "form": user_form,
                "userinfo": userinfo_form,
                "role_list": role_list
            })
Example #6
0
def edit_myinfo(request):
    user = User.objects.get(username=request.user.username)
    userinfo = UserInfo.objects.get(user=request.user)

    if request.method == "POST":
        user_form = UserForm(request.POST)
        userinfo_form = UserInfoForm(request.POST)
        if user_form.is_valid() * userinfo_form.is_valid():
            user_cd = user_form.cleaned_data
            userinfo_cd = userinfo_form.cleaned_data
            user.email = user_cd['email']
            userinfo.phone = userinfo_cd['phone']
            userinfo.birth = userinfo_cd['birth']
            userinfo.school = userinfo_cd['school']
            userinfo.company = userinfo_cd['company']
            userinfo.profession = userinfo_cd['profession']
            userinfo.address = userinfo_cd['address']
            userinfo.aboutme = userinfo_cd['aboutme']
            user.save()
            userinfo.save()
        return HttpResponseRedirect('/account/myinfo/')
    else:
        user_form = UserForm(instance=request.user)
        userinfo_form = UserInfoForm(
            initial={
                "phone": userinfo.phone,
                "birth": userinfo.birth,
                "school": userinfo.school,
                "company": userinfo.company,
                "profession": userinfo.profession,
                "address": userinfo.address,
                "aboutme": userinfo.aboutme
            })

        return render(
            request, "account/edit_myinfo.html", {
                "user_form": user_form,
                "userinfo_form": userinfo_form,
                "userinfo": userinfo
            })
Example #7
0
def register(request):

    REGISTERED = False

    if request.method == 'POST':

        user_info = UserInfoForm(request.POST)

        if user_info.is_valid():

            user = user_info.save(commit=False)
            user.set_password(user.password)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            mail_subject = 'Activate your account.'
            message = render_to_string(
                'login/acc_active_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            to_email = user_info.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()

            REGISTERED = True
            return render(request, 'login/registration_done.html')
        else:
            print(user_info.errors)
    else:

        user_info = UserInfoForm()

    return render(request, 'login/register.html', {
        'user_info': user_info,
        'registered': REGISTERED
    })
Example #8
0
def uc_data(request):
    """
    用户中心-个人资料
    """
    menu = 'data'
    unread = get_unread_list(request.user)
    if request.method == 'POST':
        form = UserInfoForm(request.POST, instance=request.user)
        if form.is_valid():
            # form.save(update_fields=['nick_name','email','gender','bio','signature'])
            f = form.save(commit=False)
            f.save(update_fields=[
                'nick_name', 'email', 'gender', 'bio', 'signature'
            ])
    else:
        form = UserInfoForm(instance=request.user)

    return render_to_response('account/data.html', {
        'config': config,
        'menu': menu,
        'unread': unread,
        'form': form
    },
                              context_instance=RequestContext(request))