# Path: commerce/forms.py
# class RegisterForm(ModelForm):
#     first_name = forms.CharField(label='Votre prénom', required=True)
#     last_name = forms.CharField(label='Votre nom', required=True)
#     email = forms.EmailField(label='Votre adresse e-mail', required=True)
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'username', 'password', 'email']
# 
# class RegisterFormUpdate(ModelForm):
#     first_name = forms.CharField(label='Votre prénom', required=True)
#     last_name = forms.CharField(label='Votre nom', required=True)
#     email = forms.EmailField(label='Votre adresse e-mail', required=True)
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'email']
# 
# class AddAddress(ModelForm):
#     class Meta:
#         model = Address
#         fields = ['gender', 'first_name', 'last_name', 'company', 'address', 'additional_address',
#                   'postcode', 'city', 'phone', 'mobilephone', 'fax', 'workphone']


from commerce.models import *
from commerce.forms import RegisterForm, RegisterFormUpdate, AddAddress
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
import stripe
import datetime
    if 'shipping_address' in request.session and 'invoicing_address' in request.session:
        shipping_address = request.session['shipping_address']
        invoicing_address = request.session['invoicing_address']
    else:
        shipping_address = 0
        invoicing_address = 0

    if request.GET.get('next', False):
        return redirect(request.GET['next'])
    else:
        return render(request, 'shipping.html', {'addresses': addresses_list,
                                                 'shipping_address': shipping_address,
                                                 'invoicing_address': invoicing_address})


@login_required(login_url='/sign-in')
def add_address(request):
    if request.method == 'POST':
        add_address_form = AddAddress(request.POST)

        if add_address_form.is_valid():
            client = Client.objects.get(user_id=request.user.id)
            address = add_address_form.save(commit=False)
            address.client_id = client.id
            address.save()
            if request.GET.get('next', False):
                return redirect(request.GET['next'])
            else:
                redirect('commerce:addresses')
    else:

# Path: commerce/forms.py
# class RegisterForm(ModelForm):
#     first_name = forms.CharField(label='Votre prénom', required=True)
#     last_name = forms.CharField(label='Votre nom', required=True)
#     email = forms.EmailField(label='Votre adresse e-mail', required=True)
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'username', 'password', 'email']
# 
# class RegisterFormUpdate(ModelForm):
#     first_name = forms.CharField(label='Votre prénom', required=True)
#     last_name = forms.CharField(label='Votre nom', required=True)
#     email = forms.EmailField(label='Votre adresse e-mail', required=True)
# 
#     class Meta:
#         model = User
#         fields = ['first_name', 'last_name', 'email']
# 
# class AddAddress(ModelForm):
#     class Meta:
#         model = Address
#         fields = ['gender', 'first_name', 'last_name', 'company', 'address', 'additional_address',
#                   'postcode', 'city', 'phone', 'mobilephone', 'fax', 'workphone']


# Path: commerce/views.py
from commerce.models import *
from commerce.forms import RegisterForm, RegisterFormUpdate, AddAddress
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
import stripe
import datetime

    if 'shipping_address' in request.session and 'invoicing_address' in request.session:
        shipping_address = request.session['shipping_address']
        invoicing_address = request.session['invoicing_address']
    else:
        shipping_address = 0
        invoicing_address = 0

    if request.GET.get('next', False):
        return redirect(request.GET['next'])
    else:
        return render(request, 'shipping.html', {'addresses': addresses_list,
                                                 'shipping_address': shipping_address,
                                                 'invoicing_address': invoicing_address})


@login_required(login_url='/sign-in')
def add_address(request):
    if request.method == 'POST':
        add_address_form = AddAddress(request.POST)

        if add_address_form.is_valid():
            client = Client.objects.get(user_id=request.user.id)
            address = add_address_form.save(commit=False)
            address.client_id = client.id
            address.save()
            if request.GET.get('next', False):
                return redirect(request.GET['next'])
            else:
                redirect('commerce:addresses')
    else:

        add_address_form = AddAddress()