Esempio n. 1
0
def save_new_author_profile(request):
    if request.method == 'POST':
        if request.user.is_authenticated():
            if not user_has_author(request.user):
                author_form = EditAuthorForm(request.POST)
                if author_form.is_valid():
                    author = author_form.save()
                    author.user = request.user
                    author.save()
                    return HttpResponseRedirect('/wc_admin/')
                else:
                    error_message = 'The form was not valid. The data was not saved.'
                    return render(request, 'blog/error.html', {'error_message': error_message, 'form': author_form})
    error_message = 'Something went wrong.'
    return render(request, 'blog/error.html', {'error_message': error_message})
Esempio n. 2
0
def save_profile(request):
    if request.user.is_authenticated:
        if user_has_author(request.user):
            author_profile = Author.objects.filter(user=request.user)[0]
            author_form = EditAuthorForm(request.POST, instance=author_profile)
            user_form = UpdateProfileForm(request.POST, instance=request.user)
            if author_form.is_valid():
                author_form.save()
            else:
                error_message = 'The form was not valid. The data was not saved.'
                return render(request, 'blog/error.html', {'error_message': error_message, 'form': author_form})
            if user_form.is_valid():
                user_form.save()
            else:
                error_message = 'The form was not valid. The data was not saved.'
                return render(request, 'blog/error.html', {'error_message': error_message, 'form': user_form})
            if 'password' in request.POST:
                if request.POST.get('password') != '':
                    request.user.set_password(request.POST.get('password'))
                    request.user.save()
            return HttpResponseRedirect('/wc_admin/')
    error_message = 'This page does not exist. So how are you here??'
    return render(request, 'blog/error.html', {'error_message': error_message})