From 3a8a5ea1dad9a2532b510986799983c2b57310cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 28 Feb 2018 21:05:27 +0100 Subject: [PATCH] refactor and clean --- django/didgeridoo/currencies/forms.py | 2 +- .../templates/currencies/index.html | 78 +++---------------- .../currencies/templatetags/customfilters.py | 12 --- django/didgeridoo/currencies/views.py | 25 ++---- .../templates/webshop/article_details.html | 4 +- .../webshop/templates/webshop/index.html | 1 - 6 files changed, 20 insertions(+), 102 deletions(-) delete mode 100644 django/didgeridoo/currencies/templatetags/customfilters.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 0464a86..29e2cc2 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -1,5 +1,5 @@ from django import forms -from currencies.models import ExchangeRate_name +from currencies.models import ExchangeRate, ExchangeRate_name class CurrenciesForm(forms.Form): diff --git a/django/didgeridoo/currencies/templates/currencies/index.html b/django/didgeridoo/currencies/templates/currencies/index.html index acd63fb..4c9ef7b 100644 --- a/django/didgeridoo/currencies/templates/currencies/index.html +++ b/django/didgeridoo/currencies/templates/currencies/index.html @@ -1,88 +1,28 @@ {% extends "webshop/base.html" %} {% block section_title %}Currencies in CHF{% endblock %} {% block content %} -
{{ message }}
-

Frühere Daten:

-

US Dollars:

- {% if currency_USD_list %} +

Currency List:

+ {% if ordered_currency_list %} + - {% for currency in currency_USD_list %} + {% for currency in ordered_currency_list %} - + + {% endfor %}
DATENAME RATE
{{ currency.date.date }}{{ currency.date }}{{ currency.name }} {{ currency.exchange_rate_to_chf }}
+

{{ message }}

{% else %} +

- currency_USD_list missing. + currency_list missing.

{% endif %} -
-

EURO:

- {% if currency_EUR_list %} - - - - - - {% for currency in currency_EUR_list %} - - - - - {% endfor %} -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_EUR_list missing. -

- {% endif %} -
-

Japanese Yenn:

- {% if currency_JPY_list %} - - - - - - {% for currency in currency_JPY_list %} - - - - - {% endfor %} - -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_JPY_list missing. -

- {% endif %} -
-

Great Britain Pounds:

- {% if currency_GBP_list %} - - - - - - {% for currency in currency_GBP_list %} - - - - - {% endfor %} - -
DATERATE
{{ currency.date.date }}{{ currency.exchange_rate_to_chf }}
- {% else %} -

- currency_GBP_list missing. -

- {% endif %} {% endblock %} diff --git a/django/didgeridoo/currencies/templatetags/customfilters.py b/django/didgeridoo/currencies/templatetags/customfilters.py deleted file mode 100644 index a30e2ab..0000000 --- a/django/didgeridoo/currencies/templatetags/customfilters.py +++ /dev/null @@ -1,12 +0,0 @@ -from django import template - - -register = template.Library() - - -@register.filter() -def boldcoffee(value): - # currency_of_customer = request.session['currency'] - return '%s !!gefiltert!!' % value - - # excample filter: {{ article.price_in_chf|boldcoffee }} diff --git a/django/didgeridoo/currencies/views.py b/django/didgeridoo/currencies/views.py index 62de99a..4a5ac1f 100644 --- a/django/didgeridoo/currencies/views.py +++ b/django/didgeridoo/currencies/views.py @@ -42,7 +42,7 @@ def currencies(request): message_offline = """ Are you offline? - useing stored currencies. This does not efect you, but your purchase prices will be - recalculated as soon as you submit your Order. + recalculated as soon as you submit your Order.
""" try: raw_data = exchange_rates.get_exchange_rate(rss_tree, ns) @@ -148,32 +148,21 @@ def currencies(request): elif datetime.datetime.today().isoweekday() == 6: message = """Die Abfrage wurde ohne ergebniss beendet. Es ist Samstag, die SNB publiziert nur an Arbeitstagen - neue Kurse... + neue Kurse...
""" elif datetime.datetime.today().isoweekday() == 7: message = """Die Abfrage wurde ohne ergebniss beendet. Es ist Sonntag, die SNB publiziert nur an Arbeitstagen - neue Kurse... + neue Kurse...
""" else: - message = """Die Abfrage wurde ohne ergebniss beendet. + message = """Die Abfrage wurde ohne ergebniss beendet.
""" # know we can query our data for presentaton: - currency_list = ExchangeRate.objects.all() - currency_USD_list = ExchangeRate.objects.filter( - name__name='USD').order_by('date__date') - currency_EUR_list = ExchangeRate.objects.filter( - name__name='EUR').order_by('date__date') - currency_JPY_list = ExchangeRate.objects.filter( - name__name='JPY').order_by('date__date') - currency_GBP_list = ExchangeRate.objects.filter( - name__name='GBP').order_by('date__date') + ordered_currency_list = ExchangeRate.objects.order_by('name', 'date') + # and publish it on template: return render(request, 'currencies/index.html', - {'currency_list': currency_list, - 'currency_USD_list': currency_USD_list, - 'currency_EUR_list': currency_EUR_list, - 'currency_JPY_list': currency_JPY_list, - 'currency_GBP_list': currency_GBP_list, + {'ordered_currency_list': ordered_currency_list, 'message': message}) diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index f611601..0c409da 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -15,7 +15,9 @@

{% else %} -

please login to fill your basket...

+

+ please login to fill your basket... +

{% endif %} {% for picture in picture_list %}

diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index f04590a..4c2dfd7 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,5 +1,4 @@ {% extends "webshop/base.html" %} -{% load customfilters %} {% block section_title %}Articles{% endblock %} {% block content %}