# 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
            try:
                charge = stripe.Charge.create(
                    amount=total_cents,  # amount in cents, again
                    currency="eur",
                    card=token,
                    description='Charge for order ' + str(order.id)
                )
                order.status = Order.PAID
                order.stripe_charge_id = charge.id
                order.save()
                return redirect(reverse('commerce:confirmation'))
            except stripe.CardError, e:
                # The card has been declined
                pass
    return render(request, 'checkout.html', {'cart': cart,
                                             'grand_total': total,
                                             'grand_total_cents': total_cents,
                                             'user_email': request.user.email})


@login_required(login_url='/sign-in')
def confirmation(request):

    return render(request, 'confirmation.html')


@login_required(login_url='/sign-in')
def account(request):
    form = RegisterFormUpdate(instance=request.user)
    if request.method == 'POST':

# 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

            try:
                charge = stripe.Charge.create(
                    amount=total_cents,  # amount in cents, again
                    currency="eur",
                    card=token,
                    description='Charge for order ' + str(order.id)
                )
                order.status = Order.PAID
                order.stripe_charge_id = charge.id
                order.save()
                return redirect(reverse('commerce:confirmation'))
            except stripe.CardError, e:
                # The card has been declined
                pass
    return render(request, 'checkout.html', {'cart': cart,
                                             'grand_total': total,
                                             'grand_total_cents': total_cents,
                                             'user_email': request.user.email})


@login_required(login_url='/sign-in')
def confirmation(request):

    return render(request, 'confirmation.html')


@login_required(login_url='/sign-in')
def account(request):
    form = RegisterFormUpdate(instance=request.user)
    if request.method == 'POST':

        form = RegisterFormUpdate(request.POST)