From b53f52cac1d7103d3b53b1a8acc8eda4d2a0b102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 19 Jan 2018 15:40:55 +0100 Subject: [PATCH] a work in progress test of custom filters --- django/didgeridoo/currencies/forms.py | 4 ---- .../currencies/templatetags/customfilters.py | 11 +++++++++++ django/didgeridoo/static/js/app.js | 3 ++- .../didgeridoo/webshop/templates/webshop/index.html | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 django/didgeridoo/currencies/templatetags/customfilters.py diff --git a/django/didgeridoo/currencies/forms.py b/django/didgeridoo/currencies/forms.py index 38111bd..2dcee6a 100644 --- a/django/didgeridoo/currencies/forms.py +++ b/django/didgeridoo/currencies/forms.py @@ -9,7 +9,3 @@ class CurrencyForm(forms.Form): CURRENCY_CHOICES = [(t.name, t.name) for t in ExchangeRate_name.objects.all()] - - type = forms.ChoiceField(choices=CURRENCY_CHOICES, - widget=forms.Select(attrs={ - 'onchange': 'get_vehicle_color();'})) diff --git a/django/didgeridoo/currencies/templatetags/customfilters.py b/django/didgeridoo/currencies/templatetags/customfilters.py new file mode 100644 index 0000000..5831f92 --- /dev/null +++ b/django/didgeridoo/currencies/templatetags/customfilters.py @@ -0,0 +1,11 @@ +from django import template + + +register = template.Library() + + +@register.filter() +def boldcoffee(value): + return '%s !!gefiltert!!' % value + + # excample filter: {{ article.price_in_chf|boldcoffee }} diff --git a/django/didgeridoo/static/js/app.js b/django/didgeridoo/static/js/app.js index a9eeae3..fefddab 100644 --- a/django/didgeridoo/static/js/app.js +++ b/django/didgeridoo/static/js/app.js @@ -8,7 +8,8 @@ }, dataType: 'json', success: function (data) { - alert("es pop auf! --dies kommt von: static/js/app.js--."); + var foo = jQuery.parseJSON(data); + alert("es pop auf! --dies kommt von: static/js/app.js--." + foo.currency_update); } }); diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 71484e3..ec938cb 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,5 +1,5 @@ {% extends "webshop/base.html" %} - +{% load customfilters %} {% block section_title %}Articles{% endblock %} {% block content %} @@ -22,7 +22,7 @@ {{ article.category }} {{ article.stock }} - {{ article.price_in_chf }} + {{ article.price_in_chf|boldcoffee }} {% endfor %}