Пример #1
0
def edit_profile(request, username):
    user = User.objects.get(username=username)
    # inters = Interest_Model.objects.filter(username=user)
    # interest_list=[]
    # for i in inters:
    #     interest_list.append(i.interest)
    if request.user.is_authenticated and request.user == user:
        if request.method == 'POST':
            user_form = EditProfileForm(request.POST, instance=request.user)
            #profile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.userprofile)
            if user_form.is_valid():
                user_form.save()
                #profile_form.save()
                # to_delete = Interest_Model.objects.filter(username=user)
                # if to_delete.exists():
                #     to_delete.delete()
                # interest_var = request.POST.get('interests')
                # interest_var = interest_var.lower().replace(","," ")
                # interest_var = interest_var.split()
                # for var in interest_var:
                #     a = User.objects.get(username=request.user.username)
                #     Interest_Model.objects.create(username=a, interest=var)
                messages.success(request,
                                 ('Your profile was successfully updated!'))
                return redirect(reverse('home:profile', args=[request.user]))
            else:
                messages.error(request, ('Please correct the error below.'))
        else:
            user_form = EditProfileForm(instance=request.user)
            #return redirect('home:dashboard')
            #profile_form = UserProfileForm(instance=request.user.userprofile)
        args = {'user_form': user_form}
        return render(request, 'home/edit_profile.html', args)
    else:
        return redirect('home:dashboard')
Пример #2
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect(reverse('home:view_profile'))

    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'home/edit_profile.html', args)
Пример #3
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST,
                               request.FILES,
                               instance=request.user.profile)
        if form.is_valid():
            form.save()
            messages.success(request, "Profile Updated")
            return redirect('home')
    else:
        if request.user.is_authenticated:
            form = EditProfileForm(instance=request.user.profile)
    # Display a blank or invalid form.
    context = {'form': form}
    return render(request, 'home/edit_profile.html', context)
Пример #4
0
def profileChange(request):
    """
    View for when a user is editing their profile information
    """
    if request.method == "POST":
        form = EditProfileForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            return redirect('/profile/')
        else:
            dict = {
                'form': form,
                'fail': True,
            }
            return render(request, 'home/profile.html', dict)
    else:
        form = EditProfileForm(instance=request.user)
        dict = {'form': form}
        return render(request, 'home/profile.html', dict)