cleanup code and refacture visual usability

This commit is contained in:
Ivan Hörler 2018-02-28 08:13:13 +01:00
parent 1e577f4520
commit db1fb337ba
3 changed files with 41 additions and 30 deletions

View File

@ -5,12 +5,12 @@
{% block content %} {% block content %}
</br> </br>
<p><b>Username: </b>{{ request.user.username }}</p> <p><b>Username: </b>{{ request.user.username }}</p>
<p><b>Salutation: </b>{{ person.salutation }}</p> <p><b>Name: </b>
<p><b>Firstname: </b>{{ request.user.first_name }}</p> {{ person.salutation }}
<p><b>Lastname: </b>{{ request.user.last_name }}</p> {{ request.user.first_name }}
{{ request.user.last_name }}</p>
<p><b>Street: </b>{{ person.street_name }} {{ person.street_number }}</p>
<p><b>City: </b>{{ person.city }}</p> <p><b>City: </b>{{ person.city }}</p>
<p><b>Street: </b>{{ person.street_name }}</p>
<p><b>Streetnumber: </b>{{ person.street_number }}</p>
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}

View File

@ -2,10 +2,20 @@
{% load customfilters %} {% load customfilters %}
{% block section_title %}Order{% endblock %} {% block section_title %}Order{% endblock %}
{% block content %} {% block content %}
<h1> Your order was submitted. </h1> {% if order %}
<h3> Thank you for Purchase. </h3> <h4>Your order was submitted on:
<h3>List of Items in your Shopping Cart:</h3> {{ order.date }}, current Status is:
{% if order_position_list %} {{ order.status }}.
</h4>
{% else %}
<p class="alert alert-danger">
<strong>
Orderdetails are not avalable.
<strong>
</p>
{% endif %}
<h3>List of Items in your Order:</h3>
{% if order_position_list_zip %}
<table class="table price-table"> <table class="table price-table">
<tr class="table_header"> <tr class="table_header">
<th scope="col">POS.</th> <th scope="col">POS.</th>
@ -16,7 +26,7 @@
<th scope="col" class="price-label">PRICE p.pce.</th> <th scope="col" class="price-label">PRICE p.pce.</th>
<th scope="col" class="price-label">POSITION PRICE</th> <th scope="col" class="price-label">POSITION PRICE</th>
</tr> </tr>
{% for order_position in order_position_list %} {% for order_position, price in order_position_list_zip %}
<tr class="table_content"> <tr class="table_content">
<td scope="col">{{ order_position.id }}</td> <td scope="col">{{ order_position.id }}</td>
<td scope="col">{{ order_position.article.id }}</td> <td scope="col">{{ order_position.article.id }}</td>
@ -32,7 +42,7 @@
{{ currency_name }} {{ currency_name }}
</td> </td>
<td scope="col" class="price-value"> <td scope="col" class="price-value">
{{ order_position.position_price }} {{ currency_name }} {{ price }} {{ currency_name }}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -45,6 +55,7 @@
</td> </td>
</tr> </tr>
</table> </table>
<h3> Thank you for Purchase. </h3>
{% else %} {% else %}
<p class="alert alert-danger"> <p class="alert alert-danger">
<strong> <strong>

View File

@ -173,30 +173,30 @@ def profile(request):
if orders: if orders:
orders_list = list(orders) orders_list = list(orders)
for idx1, order in enumerate(orders_list): for idx1, order in enumerate(orders_list):
print(order.id)
# get all items in the Order: # get all items in the Order:
order_positions = OrderPosition.objects.filter(order=order) order_positions = OrderPosition.objects.filter(order=order)
if (order_positions.count()) > 0: if (order_positions.count()) > 0:
order_positions_count = order_positions.count()
order_position_list = list(order_positions) order_position_list = list(order_positions)
for idx2, order_position in enumerate(order_position_list): for idx2, order_position in enumerate(order_position_list):
# get currencyname to display: # get currencyname to display:
if order.exchange_rate is not None: if order.exchange_rate is not None:
print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id)
# get price of position in order and append to a list: # get price of position in order and append to a list:
rate = ExchangeRate.objects.get(id=order.exchange_rate.id) rate = ExchangeRate.objects.get(
id=order.exchange_rate.id)
order_position.price_in_chf = round( order_position.price_in_chf = round(
rate.exchange_rate_to_chf * order_position.price_in_chf, rate.exchange_rate_to_chf *
order_position.price_in_chf,
2) 2)
currency_name = order.exchange_rate currency_name = order.exchange_rate
else: else:
currency_name = 'CHF' currency_name = 'CHF'
totalprice_list.append(order_position.price_in_chf) totalprice_list.append(order_position.price_in_chf)
order_position_list[idx2] = order_position order_position_list[idx2] = order_position
total = sum(totalprice_list) total = sum(totalprice_list)
currency_list.append(currency_name) currency_list.append(currency_name)
total_list.append(total) total_list.append(total)
order_positions_count = order_positions.count() order_positions_count_list.append(order_positions_count)
order_positions_count_list.append(order_positions_count)
orders_list[idx1] = order orders_list[idx1] = order
order_list_zip = zip(orders_list, order_list_zip = zip(orders_list,
order_positions_count_list, order_positions_count_list,
@ -266,17 +266,14 @@ def cart(request):
if request.method == 'POST': if request.method == 'POST':
# here we react to a currency dropdown change: # here we react to a currency dropdown change:
if 'currencies' in request.POST: if 'currencies' in request.POST:
print('currencies')
currencies_form = CurrenciesForm(request.POST) currencies_form = CurrenciesForm(request.POST)
if currencies_form.is_valid(): if currencies_form.is_valid():
cf = currencies_form.cleaned_data cf = currencies_form.cleaned_data
if cf['currencies']: if cf['currencies']:
print('currencies cf:', cf)
selection = cf['currencies'] selection = cf['currencies']
request.session['currency'] = selection.id request.session['currency'] = selection.id
currency_name = ExchangeRate_name.objects.get( currency_name = ExchangeRate_name.objects.get(
id=selection.id) id=selection.id)
print('currencies currency_name:', currency_name)
else: else:
request.session['currency'] = None request.session['currency'] = None
@ -441,8 +438,9 @@ def checkout(request):
def order(request, order_id): def order(request, order_id):
price_list = []
totalprice_list = [] totalprice_list = []
order_position_list = [] order_position_list_zip = []
cart = ShoppingCart.objects.get(user=request.user) cart = ShoppingCart.objects.get(user=request.user)
if cart: if cart:
# get all items in the cart of this customer: # get all items in the cart of this customer:
@ -465,22 +463,24 @@ def order(request, order_id):
for idx, order_position in enumerate(order_positions): for idx, order_position in enumerate(order_positions):
# get currencyname to display: # get currencyname to display:
if order.exchange_rate is not None: if order.exchange_rate is not None:
print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id)
# get price of position in order and append to a list: # get price of position in order and append to a list:
rate = ExchangeRate.objects.get(id=order.exchange_rate.id) rate = ExchangeRate.objects.get(id=order.exchange_rate.id)
order_position.price = round( price = round(
rate.exchange_rate_to_chf * order_position.price_in_chf, rate.exchange_rate_to_chf * order_position.price_in_chf,
2) 2)
currency_name = order.exchange_rate currency_name = order.exchange_rate
else: else:
currency_name = 'CHF' currency_name = 'CHF'
order_position.price = order_position.price_in_chf price = order_position.price_in_chf
order_position.position_price = order_position.price * Decimal.from_float(order_position.amount) position_price = price * Decimal.from_float(order_position.amount)
order_position_list[idx] = order_position order_position_list[idx] = order_position
totalprice_list.append(order_position.price) price_list.append(price)
totalprice_list.append(position_price)
total = sum(totalprice_list) total = sum(totalprice_list)
order_position_list_zip = zip(order_position_list, price_list)
return render(request, 'webshop/order.html', { return render(request, 'webshop/order.html', {
'order_position_list': order_position_list, 'order': order,
'order_position_list_zip': order_position_list_zip,
'total': total,
'currency_name': currency_name, 'currency_name': currency_name,
'total': total
}) })