Пример #1
0
def userinfo(request):
    if request.user.is_authenticated():
        username = request.user.username
    user = User.objects.get(username=username)
    try:
        profile = models.Profile.objects.get(user=user)
    except:
        profile = models.Profile(user=user)

    if request.method == 'POST':
        profile_form = forms.ProfileForm(request.POST, instance=profile)
        if profile_form.is_valid():
            messages.add_message(request, messages.INFO, "data store")
            profile_form.save()
            return HttpResponseRedirect('/userinfo')
        else:
            messages.add_message(request, messages.INFO, "modified data")
    else:
        profile_form = forms.ProfileForm()

    template = get_template('userinfo.html')
    request_context = RequestContext(request)
    request_context.push(locals())
    html = template.render(request_context)
    return HttpResponse(html)
Пример #2
0
def profile(request):
    user = request.user
    form = forms.ProfileForm(request.POST or None, instance=user)
    if form.is_valid():
        form.save()
        messages.add_message(request, messages.SUCCESS, 'ユーザ情報を更新しました。')
    return render(request, 'profile.html', {'form': form})
Пример #3
0
def userinfo(request):

    #if("username" in request.session):
    if(request.user.is_authenticated()):
        username = request.user.username
        print("username is {0}".format(username))
    else:
        return redirect("/")
    from django.contrib.auth.models import User as authUser
    user = authUser.objects.get(username=username)
    #user = User.objects.get(name=username)
    try:
        #userinfo1 = auth.get_user_model().objects.get(username=username)#User.objects.get(name=username)
        #user = auth.get_user_model().objects.get(username=username)
        #userinfo1 = MyUser.objects.get(user=user)
        profile = MyUser.objects.get(user=user)
    except:
        profile = MyUser(user=user)
        print("userinfo is exception")
        pass
    if(request.method == 'POST'):
        profile_form = forms.ProfileForm(request.POST, instance=profile)
        if(profile_form.is_valid()):
            messages.add_message(request, messages.INFO, "个人资料更新成功!")
            profile_form.save()
            return HttpResponseRedirect('/userinfo/')
        else:
            messages.add_message(request, messages.INFO, "请确定每个字段都填写完成")
    else:
        profile_form = forms.ProfileForm()
    mymsg = messages.get_messages(request)
    template = get_template("userinfo.html")
    c = csrf(request)
    c.update(locals())
    html = template.render(c)
    return HttpResponse(html)