more work on shop
This commit is contained in:
parent
5b279ff493
commit
82ae2b8c23
|
@ -2,8 +2,8 @@ from django import forms
|
||||||
from .models import Order
|
from .models import Order
|
||||||
|
|
||||||
|
|
||||||
class PaymentMethodForm(forms.ModelForm):
|
class CheckoutForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
fields = ['payment_method']
|
fields = None
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Order(CreatedUpdatedModel):
|
||||||
payment_method = models.CharField(
|
payment_method = models.CharField(
|
||||||
max_length=50,
|
max_length=50,
|
||||||
choices=PAYMENT_METHODS,
|
choices=PAYMENT_METHODS,
|
||||||
default=CREDIT_CARD
|
default=BLOCKCHAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
14
shop/templates/checkout.html
Normal file
14
shop/templates/checkout.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% bootstrap_button "Pay with credit card" name="credit_card" button_type="submit" button_class="btn-primary" %}
|
||||||
|
{% bootstrap_button "Pay with blockchain" name="blockchain" button_type="submit" button_class="btn-primary" %}
|
||||||
|
{% bootstrap_button "Pay with bank transfer" name="bank_transfer" button_type="submit" button_class="btn-primary" %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{{ ticket }}
|
<b>details for order {{ order.id }}</b>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
7
shop/templates/product_detail.html
Normal file
7
shop/templates/product_detail.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<b>details for product {{ product.id }}</b>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -1,13 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% load bootstrap3 %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<form method="POST">
|
|
||||||
{% csrf_token %}
|
|
||||||
{% bootstrap_form form %}
|
|
||||||
{% bootstrap_button "Buy" button_type="submit" button_class="btn-primary" %}
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
|
@ -1,76 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<h2>Tickets</h2>
|
|
||||||
|
|
||||||
<p class="lead">
|
|
||||||
Here you can see the different ticket types, their prices and availability.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table class="table table-bordered table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
Description
|
|
||||||
<th>
|
|
||||||
Price
|
|
||||||
<th>
|
|
||||||
Availability
|
|
||||||
<th>
|
|
||||||
Buy
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
|
|
||||||
{% for product in tickets %}
|
|
||||||
|
|
||||||
<tr {% if not product.is_available %}style="color: lightgrey"{%endif%}>
|
|
||||||
<td>
|
|
||||||
{{ product.name }}
|
|
||||||
<td>
|
|
||||||
{{ product.price }} DKK
|
|
||||||
<td>
|
|
||||||
{{ product.available_in.lower }}
|
|
||||||
{% if product.available_in.upper %}
|
|
||||||
- {{ product.available_in.upper }}
|
|
||||||
{% endif %}
|
|
||||||
<td>
|
|
||||||
{% if product.is_available %}
|
|
||||||
<a href="">
|
|
||||||
Order
|
|
||||||
</a>
|
|
||||||
{% else %}
|
|
||||||
N/A
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
{% comment %}
|
|
||||||
{% if user.is_authenticated %}
|
|
||||||
<hr />
|
|
||||||
<h3>Your tickets</h3>
|
|
||||||
<table class="table table-hover">
|
|
||||||
{% for ticket in user.tickets.all %}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
{{ ticket.ticket_type.name }}
|
|
||||||
<td>
|
|
||||||
{% if ticket.paid %} Paid {% else %} Not paid {% endif %}
|
|
||||||
{% empty %}
|
|
||||||
<tr>
|
|
||||||
<td colspan=3>
|
|
||||||
You don't have a ticket! Why don't buy one and join the fun?
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<a href="{% url 'tickets:order' %}" class="btn btn-success">Order tickets</a>
|
|
||||||
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'account_signup' %}?next={% url 'tickets:index' %}">Sign up</a> or
|
|
||||||
<a href="{% url 'account_login' %}?next={% url 'tickets:index' %}">login</a> to buy tickets.
|
|
||||||
{% endif %}
|
|
||||||
{% endcomment %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
45
shop/templates/shop_index.html
Normal file
45
shop/templates/shop_index.html
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<h2>Shop</h2>
|
||||||
|
|
||||||
|
<p class="lead">
|
||||||
|
Here you can see the different products and prices.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table class="table table-bordered table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Availability</th>
|
||||||
|
<th>Buy</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{% for product in product_list %}
|
||||||
|
<tr {% if not product.is_available %}style="color: lightgrey"{%endif%}>
|
||||||
|
<td>{{ product.name }}</td>
|
||||||
|
<td>{{ product.price }} DKK</td>
|
||||||
|
<td>{{ product.available_in.lower }}
|
||||||
|
{% if product.available_in.upper %}
|
||||||
|
- {{ product.available_in.upper }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if product.is_available %}
|
||||||
|
<a href="">
|
||||||
|
Add to order
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
N/A
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -1,52 +1,42 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect, Http404
|
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.core.urlresolvers import reverse_lazy
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
from .models import Order, Product, EpayCallback, EpayPayment
|
from .models import Order, Product, EpayCallback, EpayPayment
|
||||||
from .forms import PaymentMethodForm
|
from .forms import CheckoutForm
|
||||||
|
|
||||||
|
|
||||||
class ShopIndexView(TemplateView):
|
class ShopIndexView(ListView):
|
||||||
template_name = "shop/index.html"
|
model = Product
|
||||||
|
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 ProductDetailView(LoginRequiredMixin, DetailView):
|
class ProductDetailView(LoginRequiredMixin, DetailView):
|
||||||
model = Product
|
model = Product
|
||||||
template_name = 'product/detail.html'
|
template_name = 'product_detail.html'
|
||||||
context_object_name = 'product'
|
context_object_name = 'product'
|
||||||
|
|
||||||
|
|
||||||
class CheckoutView(LoginRequiredMixin, DetailView):
|
class OrderDetailView(LoginRequiredMixin, DetailView):
|
||||||
"""
|
model = Product
|
||||||
Shows a summary of all products contained in an order,
|
template_name = 'order_detail.html'
|
||||||
total price, VAT, and a button to go to the payment
|
|
||||||
"""
|
|
||||||
model = Order
|
|
||||||
template_name = 'shop/order_detail.html'
|
|
||||||
context_object_name = 'order'
|
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 CheckoutView(LoginRequiredMixin, FormView):
|
||||||
class PaymentView(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'
|
model = Order
|
||||||
form_class = PaymentMethodForm
|
template_name = 'checkout.html'
|
||||||
|
context_object_name = 'order'
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if self.get_object().user != request.user:
|
if self.get_object().user != request.user:
|
||||||
|
@ -62,15 +52,39 @@ class PaymentView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
return self.render_to_response(self.get_context_data())
|
return self.render_to_response(self.get_context_data())
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def form_valid(self, form):
|
||||||
order = Order.objects.get(pk=kwargs.get('order_id'))
|
### mark order as finalizedredirect user to payment
|
||||||
context = super(CheckoutView, self).get_context_data(**kwargs)
|
form.instance.finalized=True
|
||||||
context['order'] = order
|
|
||||||
return context
|
### 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):
|
class CoinifyRedirectView(TemplateView):
|
||||||
template_name = 'shop/coinify_form.html'
|
template_name = 'coinify_redirect.html'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
order = Order.objects.get(pk=kwargs.get('order_id'))
|
order = Order.objects.get(pk=kwargs.get('order_id'))
|
||||||
|
|
Loading…
Reference in a new issue