Beispiel #1
0
def accounts(request):
    profile = request.user.get_profile()
    past_name = profile.name
    now_date = datetime.datetime.now()
    check_date = now_date - datetime.timedelta(days=30)
    if profile.name_last_update:
        if profile.name_last_update <= check_date:
            update = True
        else:
            update = False
    else:
        update = True
    if request.method == 'GET':
        form = ProfileForm(instance=profile)
        return render(request,'accounts.html',locals())
    form = ProfileForm(request.POST,instance=profile)
    if form.is_valid():
        profile_new = form.save(commit=False)
        if request.POST.has_key('name'):
            if request.POST['name'] != past_name:
                profile_new.name = request.POST['name'].strip()
                profile_new.name_last_update = now_date
                update = False
        profile_new.save()
        messages.success(request,"个人资料更新成功")
        return render(request,'accounts.html',{"form":form,"update":update})
    else:
        return render(request,'accounts.html',{"form":form,"update":update})    
Beispiel #2
0
def new_profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST)

        if form.is_valid():
            create_profile(request, form)
    else:
        form = ProfileForm()
    return render(request, 'accounts/profile_new.html', {
            'form': form,
        })
Beispiel #3
0
def new_profile(request):
    if request.method == 'POST':
        form = ProfileForm(request.POST)

        if form.is_valid():
            create_profile(request, form)
    else:
        form = ProfileForm()
    return render(request, 'accounts/profile_new.html', {
        'form': form,
    })
Beispiel #4
0
def settings(request):
    user = request.user
    if request.method == 'GET':
        form = ProfileForm(instance=user)
        return render(request,'settings.html',locals())
    form = ProfileForm(request.POST,instance=user)
    if form.is_valid():
        form.save(commit=True)
        messages.success(request,"设置已更新")
        return render(request,'settings.html',{"form":form})
    else:
        return render(request,'settings.html',{"form":form})
Beispiel #5
0
def accounts(request):
    user = request.user
    profile = user.get_profile()
    if request.method == 'GET':
        form = ProfileForm(instance=profile)
        return render(request,'accounts.html',locals())
    form = ProfileForm(request.POST,instance=profile)
    if form.is_valid():
        form.save()
        return render(request,'accounts.html',locals())
    else:
        return render(request,'accounts.html',locals())    
Beispiel #6
0
def settings(request):
    user = request.user
    if request.method == 'GET':
        form = ProfileForm(instance=user)
        return render(request, 'settings.html', locals())
    form = ProfileForm(request.POST, instance=user)
    if form.is_valid():
        form.save(commit=True)
        messages.success(request, "设置已更新")
        return render(request, 'settings.html', {"form": form})
    else:
        return render(request, 'settings.html', {"form": form})
Beispiel #7
0
def update_profile(request):
    """ This allows a user to update his or her profile. """
    profile_kwargs = {
            'instance': request.user.profile,
            'prefix': 'profile',
            }
    email_kwargs = {
            'instance': request.user,
            'prefix': 'email',
            }

    if request.method == 'POST':
        if profile_kwargs['prefix'] in request.POST:
            profile_form = ProfileForm(request.POST, request.FILES,
                    **profile_kwargs)
            if profile_form.is_valid():
                profile_form.save()
                messages.success(request, "Your profile has been successfully "
                        "updated")
                return redirect("accounts:edit_profile")
            email_form = EmailForm(**email_kwargs)

        elif email_kwargs['prefix'] in request.POST:
            email_form = EmailForm(request.POST, **email_kwargs)
            if email_form.is_valid():
                email_form.save()
                messages.success(request, "Your email address has been "
                        "successfully updated.")
                return redirect("accounts:edit_profile")
            profile_form = ProfileForm(**profile_kwargs)

    else:
        profile_form = ProfileForm(**profile_kwargs)
        email_form = EmailForm(**email_kwargs)

    return render_response(request, "accounts/edit-profile.html", {
        'profile_form': profile_form,
        'email_form': email_form,
        })
Beispiel #8
0
def profile(request, *args, **kwargs):
    profilepage = True
    
    # Create the basic forms which will be rendered in get requests
    user = request.user
    try:
        userprofile = UserProfile.objects.get(user = user)
        #profileform = ProfileForm(instance=userprofile, instance_user=user)
    except:
        userprofile = UserProfile(user = user)
    profileform = ProfileForm(instance=userprofile)
    
    if request.method == 'POST':
        postdata = request.POST.copy()
        if 'profileform' in postdata: # SIGNUP FORM
            profileform = ProfileForm(postdata, instance=userprofile)
            if profileform.is_valid():
                # If the form is valid, save the user using the inbuilt function
                profileform.save()
                messages.success(request,'<strong>Done!</strong> Your account information was successfully saved !',extra_tags='alert-success')
                return HttpResponseRedirect(reverse('profile'))
            else:   
                print "form errors"
                print profileform.errors
        if 'passwordform' in postdata: # SIGNUP FORM
            if postdata['password'] == postdata['confirm_password']:
                user.set_password(postdata['password'])
                user.save()
                print postdata['password']
            else:
                print postdata['password'], postdata['confirm_password']
                passwordform_errors = True
                show_passwordform = True
    if 'show_passwordform' in request.session:
        show_passwordform = request.session['show_passwordform']
        del request.session['show_passwordform']
            
    return render_to_response('pages/profile.html', locals(), context_instance= global_context(request))