示例#1
0
def edit_userpage(request):
    user = request.user
    print 'outside'
    if user.is_authenticated:
        print 'is authed'
        username = user.username
        try:
            print 'try'
            profile = UserProfile.objects.get(user_id=user.id)
            print profile
            picture = profile.profile_image.url
            interests = profile.interests
            accomodation = profile.accomodation
            about = profile.about
            twitter = profile.twitter
            facebook = str(profile.facebook)
            telegram = profile.telegram
        except Exception as err:
            print err
            interests = 'interests'
            picture = 'static_dev/img/default_profile_picture.jpg'
            accomodation = 'accomodation'
            about = 'about'
            twitter = '@username'
            facebook = 'user name'
            telegram = '@username'
        if request.method == 'POST':
            print user.id
            profileID = UserProfile.objects.get(user_id=user.id)
            print profileID
            profile_form = UpdateProfile(request.POST,
                                         request.FILES,
                                         instance=profileID)
            if profile_form.is_valid():
                instance = profile_form.save(commit=False)
                print 'instance %s' % profile_form
                print 'FILES: ', request.FILES
                if 'image' in request.FILES:
                    instance.profile_image = request.FILES['image']
                instance.save()
                return HttpResponseRedirect('/userpage/')
            else:
                print profile_form.errors

        context = {
            'username': username,
            'picture': picture,
            'interests': interests,
            'accomodation': accomodation,
            'about': about,
            'twitter': twitter,
            'facebok': str(facebook),
            'telegram': telegram,
        }
        return render(request, 'users/edit_userpage.html', context)
    else:
        return HttpResponseRedirect('/')
示例#2
0
def update_profile(request):
    args = {}

    if request.method == 'POST':
        form = UpdateProfile(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return render(request, 'forms/hello.html')
    else:
        form = UpdateProfile()

    args['form'] = form
    return render(request, 'forms/update_profile.html', args)
示例#3
0
def update_profile(request):
    args = {}

    if request.method == 'POST':
        form = UpdateProfile(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return render(request, 'forms/hello.html')
    else:
        form = UpdateProfile()

    args['form'] = form
    return render(request, 'forms/update_profile.html', args)