Пример #1
0
def usersetting(request):
    up = request.user.userprofile
    u = request.user
    if request.method == 'POST':
        uf = UserForm(request.POST, instance=u)
        upf = UserProfileForm(request.POST, instance=up)
        if  uf.is_valid() and upf.is_valid():
#             u.first_name = uf.cleaned_data['first_name']
#             u.last_name = uf.cleaned_data['last_name']
#             up.kana_first_name = upf.cleaned_data['kana_first_name']
#             up.kana_last_name = upf.cleaned_data['kana_last_name']
            print request.POST['grade']
            up.degree = request.POST['grade']
            
            imageform = ImageUploadForm(request.POST, request.FILES)
            print 'checking pics', request.FILES
            if imageform.is_valid():
                print 'saving pics'
                up.facephoto = imageform.cleaned_data['image']
            else:
                print imageform.errors
            up.save()
            u.save()
            msg='saved!'
            #return render(request, 'login/tmp_setting2.html', {'uf': uf, 'upf': upf, 'msg': msg})
            return redirect('/')
        else:
            msg =  'INVAID'
            return render(request, 'login/tmp_setting2.html', {'uf': uf, 'upf': upf, 'msg': msg})
    uf = UserForm(instance=u)
    upf = UserProfileForm(instance=up)
    return render(request, 'login/tmp_setting2.html', {'u': u,'uf': uf, 'upf': upf})
Пример #2
0
def new_socialuser(request):
    u = request.user
    up = UserProfile(user=u)
    if request.method == 'POST':
        uf = UserForm(request.POST, instance=u)
        upf = UserProfileForm(request.POST, instance=up)
        if  uf.is_valid() and upf.is_valid():
            upf.save()
            uf.save()
            f = Follower(user=u)
            f.save()
            lp = LikePub(user=u)
            lp.save()
            lv = LikeVideo(user=u)
            lv.save()
            mp = MyProject(user=u)
            mp.save()
            return redirect('/u/')
        return HttpResponse('Error happened!')
    else:
        uf = UserForm(instance=u)
        upf = UserProfileForm()
        return render(request, 'login/tmp_setting2.html', {'uf': uf, 'upf': upf, 'agreement':'yes'})