Ejemplo n.º 1
0
def update_profile(request):
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST,
                                   instance=request.user.userprofile)
        if profile_form.is_valid():
            profile_form.save()
            messages.success(request,
                             ('Your profile was successfully updated!'))
            return redirect('home:profile')
        else:
            messages.error(request, ('Please correct the error below.'))
    else:
        profile_form = ProfileForm(instance=request.user.userprofile)
    return render(request, 'home/profile.html', {'profile_form': profile_form})
Ejemplo n.º 2
0
def update_profile(request):
    if request.method == "POST":
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return HttpResponseRedirect('/')
        else:
            messages.error(request, _('Please correct the error below.'))
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    return render(request, 'home/profile.html', {
        'user_form': user_form,
        'profile_form': profile_form
    })
Ejemplo n.º 3
0
def signup(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = ProfileForm(request.POST)
        print('40 = ', profile_form.errors.as_data())
        print('41 = ', user_form.errors.as_data())
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            print('test')
            return render(request, 'home/home.html')
    else:
        user_form = UserForm()
        profile_form = ProfileForm
    context = {'user_form': user_form, 'profile_form': profile_form}
    template = 'home/signup.html'
    return render(request, template, context)
Ejemplo n.º 4
0
def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = ProfileForm(request.POST, instance=request.user.profile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your profile was succesfully updated!')
            return redirect('/profile/')
        else:
            messages.error(request, 'Please correct the error bellow')
    else:
        user_form = UserForm(instance=request.user)
        profile_form = ProfileForm(instance=request.user.profile)
    context = {
        'user_form': user_form,
        'profile_form': profile_form
    }
    return render(request, 'home/update_profile.html', context)

    
Ejemplo n.º 5
0
def checkout_success(request, order_id):
    save_info = request.session.get('save_info')
    order_id = get_object_or_404(Order, order_number=order_id)
    order_items = OrderItem.objects.filter(order=order_id)
    extra_title = "- Order placed!"

    if request.user.is_authenticated:
        profile = UserProfile.objects.get(user_id=request.user)
        # Attach the user's profile to the order
        order_id.user_id = profile
        order_id.save()
        del request.session['bag']
        # Save the user's info, if the checkbox is ticked in checkout
        if save_info:
            profile_data = {
                'default_phone_number': order_id.phone_number,
                'default_country': order_id.country,
                'default_postcode': order_id.postcode,
                'default_town_or_city': order_id.town_or_city,
                'default_street_address1': order_id.street_address1,
                'default_street_address2': order_id.street_address2,
                'default_county': order_id.county,
            }
            user_profile_form = ProfileForm(profile_data, instance=profile)
            if user_profile_form.is_valid():
                user_profile_form.save()

    try:
        del request.session['bag']
    except KeyError:
        pass

    context = {
        "order": order_id,
        "order_items": order_items,
        'extra_title': extra_title
    }

    return render(request, 'checkout_success.html', context)
Ejemplo n.º 6
0
def saveInfo(request):
    if request.user.is_authenticated:
        profile = get_object_or_404(Profile, user=request.user)
        if request.method == "POST":
            try:
                form = ProfileForm(request.POST)
                print(request.POST)
                if form.is_valid():
                    profile.delete()
                    newprofile = form.save(commit=False)
                    newprofile.user = request.user
                    if request.POST.getlist(
                            'dost') or request.POST.getlist('osob') != []:
                        newprofile.dopinfo = True
                    newprofile.save()
                    if request.POST.getlist(
                            'dost') or request.POST.getlist('osob') != []:
                        for d in request.POST.getlist('dost'):
                            newdost = DostizhDocument()
                            newdost.type = d
                            newdost.profile = newprofile
                            newdost.save()

                        for d in request.POST.getlist('osob'):
                            newdost = OsobDocument()
                            newdost.type = d
                            newdost.profile = newprofile
                            newdost.save()

                else:
                    print(form.errors)
            except:
                return render(
                    request, 'error.html',
                    {'content': "Произошла ошибка при сохранении данных"})

        return redirect('index')

    else:
        return redirect('log')