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 %}
</br>
<p><b>Username: </b>{{ request.user.username }}</p>
<p><b>Salutation: </b>{{ person.salutation }}</p>
<p><b>Firstname: </b>{{ request.user.first_name }}</p>
<p><b>Lastname: </b>{{ request.user.last_name }}</p>
<p><b>Name: </b>
{{ person.salutation }}
{{ 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>Street: </b>{{ person.street_name }}</p>
<p><b>Streetnumber: </b>{{ person.street_number }}</p>
<form method="post">
{% csrf_token %}
{{ form.as_p }}

View File

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

View File

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