diff --git a/shop/forms.py b/shop/forms.py
index 69c22d03..acd0e605 100644
--- a/shop/forms.py
+++ b/shop/forms.py
@@ -2,8 +2,8 @@ from django import forms
from .models import Order
-class PaymentMethodForm(forms.ModelForm):
+class CheckoutForm(forms.ModelForm):
class Meta:
model = Order
- fields = ['payment_method']
+ fields = None
diff --git a/shop/models.py b/shop/models.py
index b4c03f29..ac341672 100644
--- a/shop/models.py
+++ b/shop/models.py
@@ -47,7 +47,7 @@ class Order(CreatedUpdatedModel):
payment_method = models.CharField(
max_length=50,
choices=PAYMENT_METHODS,
- default=CREDIT_CARD
+ default=BLOCKCHAIN
)
diff --git a/shop/templates/checkout.html b/shop/templates/checkout.html
new file mode 100644
index 00000000..7ff501bc
--- /dev/null
+++ b/shop/templates/checkout.html
@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 %}
+
+{% block content %}
+
+
+
+{% endblock %}
diff --git a/shop/templates/shop/epay_form.html b/shop/templates/epay_form.html
similarity index 100%
rename from shop/templates/shop/epay_form.html
rename to shop/templates/epay_form.html
diff --git a/shop/templates/shop/order_detail.html b/shop/templates/order_detail.html
similarity index 61%
rename from shop/templates/shop/order_detail.html
rename to shop/templates/order_detail.html
index 135a460d..384462be 100644
--- a/shop/templates/shop/order_detail.html
+++ b/shop/templates/order_detail.html
@@ -2,6 +2,6 @@
{% block content %}
- {{ ticket }}
+details for order {{ order.id }}
{% endblock %}
diff --git a/shop/templates/product_detail.html b/shop/templates/product_detail.html
new file mode 100644
index 00000000..6331daeb
--- /dev/null
+++ b/shop/templates/product_detail.html
@@ -0,0 +1,7 @@
+{% extends 'base.html' %}
+
+{% block content %}
+
+details for product {{ product.id }}
+
+{% endblock %}
diff --git a/shop/templates/shop/checkout.html b/shop/templates/shop/checkout.html
deleted file mode 100644
index f56d9e73..00000000
--- a/shop/templates/shop/checkout.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{% extends 'base.html' %}
-
-{% load bootstrap3 %}
-
-{% block content %}
-
-
-
-{% endblock %}
diff --git a/shop/templates/shop/index.html b/shop/templates/shop/index.html
deleted file mode 100644
index 9ff362e3..00000000
--- a/shop/templates/shop/index.html
+++ /dev/null
@@ -1,76 +0,0 @@
-{% extends 'base.html' %}
-
-{% block content %}
-
-Tickets
-
-
-Here you can see the different ticket types, their prices and availability.
-
-
-
-
-
-
- Description
- |
- Price
- |
- Availability
- |
- Buy
-
- |
-
-{% for product in tickets %}
-
-
-
- {{ product.name }}
- |
- {{ product.price }} DKK
- |
- {{ product.available_in.lower }}
- {% if product.available_in.upper %}
- - {{ product.available_in.upper }}
- {% endif %}
- |
- {% if product.is_available %}
-
- Order
-
- {% else %}
- N/A
- {% endif %}
-
-{% endfor %}
-
- |
-
-{% comment %}
-{% if user.is_authenticated %}
-
- Your tickets
-
- {% for ticket in user.tickets.all %}
-
-
- {{ ticket.ticket_type.name }}
- |
- {% if ticket.paid %} Paid {% else %} Not paid {% endif %}
- {% empty %}
- |
-
- You don't have a ticket! Why don't buy one and join the fun?
- {% endfor %}
- |
-
- Order tickets
-
-{% else %}
- Sign up or
- login to buy tickets.
-{% endif %}
-{% endcomment %}
-
-{% endblock %}
diff --git a/shop/templates/shop_index.html b/shop/templates/shop_index.html
new file mode 100644
index 00000000..fb4a9d19
--- /dev/null
+++ b/shop/templates/shop_index.html
@@ -0,0 +1,45 @@
+{% extends 'base.html' %}
+
+{% block content %}
+
+Shop
+
+
+Here you can see the different products and prices.
+
+
+
+
+
+ Description |
+ Price |
+ Availability |
+ Buy |
+
+
+
+
+{% for product in product_list %}
+
+ {{ product.name }} |
+ {{ product.price }} DKK |
+ {{ product.available_in.lower }}
+ {% if product.available_in.upper %}
+ - {{ product.available_in.upper }}
+ {% endif %}
+ |
+
+ {% if product.is_available %}
+
+ Add to order
+
+ {% else %}
+ N/A
+ {% endif %}
+ |
+
+
+{% endfor %}
+
+
+{% endblock %}
diff --git a/shop/views.py b/shop/views.py
index 79cbdea1..cbf0ea38 100644
--- a/shop/views.py
+++ b/shop/views.py
@@ -1,52 +1,42 @@
import hashlib
from django.http import HttpResponseRedirect, Http404
-from django.views.generic import CreateView, TemplateView, DetailView, View, FormView
+from django.views.generic import CreateView, TemplateView, ListView, DetailView, View, FormView
from django.core.urlresolvers import reverse_lazy
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
+from django.contrib import messages
from .models import Order, Product, EpayCallback, EpayPayment
-from .forms import PaymentMethodForm
+from .forms import CheckoutForm
-class ShopIndexView(TemplateView):
- template_name = "shop/index.html"
-
- def get_context_data(self, **kwargs):
- context = super(ShopIndexView, self).get_context_data(**kwargs)
- context['tickets'] = Product.objects.filter(category__name='Tickets')
- return context
+class ShopIndexView(ListView):
+ model = Product
+ template_name = "shop_index.html"
class ProductDetailView(LoginRequiredMixin, DetailView):
model = Product
- template_name = 'product/detail.html'
+ template_name = 'product_detail.html'
context_object_name = 'product'
-class CheckoutView(LoginRequiredMixin, DetailView):
- """
- Shows a summary of all products contained in an order,
- total price, VAT, and a button to go to the payment
- """
- model = Order
- template_name = 'shop/order_detail.html'
+class OrderDetailView(LoginRequiredMixin, DetailView):
+ model = Product
+ template_name = 'order_detail.html'
context_object_name = 'order'
- def get(self, request, *args, **kwargs):
- if self.get_object().user != request.user:
- raise Http404("Order not found")
- return self.render_to_response(self.get_context_data())
-
-class PaymentView(LoginRequiredMixin, FormView):
+class CheckoutView(LoginRequiredMixin, FormView):
"""
- Select payment method and goto payment
+ Shows a summary of all products contained in an order,
+ total price, VAT info, and a button to finalize order and go to payment
"""
- template_name = 'shop/payment.html'
- form_class = PaymentMethodForm
+ model = Order
+ template_name = 'checkout.html'
+ context_object_name = 'order'
def get(self, request, *args, **kwargs):
if self.get_object().user != request.user:
@@ -62,15 +52,39 @@ class PaymentView(LoginRequiredMixin, FormView):
return self.render_to_response(self.get_context_data())
- def get_context_data(self, **kwargs):
- order = Order.objects.get(pk=kwargs.get('order_id'))
- context = super(CheckoutView, self).get_context_data(**kwargs)
- context['order'] = order
- return context
+ def form_valid(self, form):
+ ### mark order as finalizedredirect user to payment
+ form.instance.finalized=True
+
+ ### set payment_method based on submit button used
+ if 'credit_card' in form.data:
+ form.instance.payment_method=='credit_card'
+ elif 'blockchain' in form.data:
+ form.instance.payment_method=='blockchain'
+ elif 'bank_transfer' in form.data:
+ form.instance.payment_method=='bank_transfer'
+ else:
+ ### unknown submit button
+ messages.error(request, 'Unknown submit button :(')
+ return reverse('shop:checkout', kwargs={'orderid': self.get_object.id})
+
+ return super(CheckoutView, self).form_valid(form)
+
+ def get_success_url(self):
+ if self.get_object.payment_method == 'credit_card':
+ return reverse('shop:epay_form', kwargs={'orderid': self.get_object.id})
+ elif self.get_object.payment_method == 'blockchain':
+ return reverse('shop:coinify_pay', kwargs={'orderid': self.get_object.id})
+ elif self.get_object.payment_method == 'bank_transfer':
+ return reverse('shop:bank_transfer', kwargs={'orderid': self.get_object.id})
+ else:
+ ### unknown payment method
+ messages.error(request, 'Unknown payment method :(')
+ return reverse('shop:checkout', kwargs={'orderid': self.get_object.id})
-class CoinifyView(TemplateView):
- template_name = 'shop/coinify_form.html'
+class CoinifyRedirectView(TemplateView):
+ template_name = 'coinify_redirect.html'
def get_context_data(self, **kwargs):
order = Order.objects.get(pk=kwargs.get('order_id'))