This commit is contained in:
Ivan Hörler 2018-02-28 01:22:27 +01:00
parent f8a6932bde
commit ab30417a80
6 changed files with 3 additions and 52 deletions

View File

@ -31,7 +31,7 @@ def parse_rss(urlsocket):
def pass_local_file():
rss_tree = ET.ElementTree(file='rss')
return(rss_tree)
def get_exchange_rate(rss_tree, ns):
# Pathvariables to XML Namespaces with
@ -111,5 +111,4 @@ def get_exchange_rate(rss_tree, ns):
'exchangerate': foreign_value_round}]
exchange_rates.append(data)
# Print the Dictionary:
print(exchange_rates)
return(exchange_rates)

View File

@ -1,7 +1,7 @@
{% extends "webshop/base.html" %}
{% block section_title %}Currencies in CHF{% endblock %}
{% block content %}
<h2> {{ message }} </h2>
<h5> {{ message }} </h5>
<h3> Frühere Daten: </h3>
<h4> US Dollars: </h4>
{% if currency_USD_list %}

View File

@ -1,9 +1,6 @@
from django.conf.urls import url
from currencies.views import currencies, currency_update
from currencies.views import currencies
urlpatterns = [
url(r'^currencies/$', currencies),
url(r'^ajax/currency_update/$',
currency_update,
name='currency_update'),
]

View File

@ -7,20 +7,6 @@ from currencies import exchange_rates
from django.http import JsonResponse
def currency_update(request):
# https://simpleisbetterthancomplex.com/tutorial/2016/08/29/how-to-work-with-ajax-request-with-django.html
if request.GET.get('currency_update', None) == 'CHF':
data = {}
else:
currency = request.GET.get('currency_update', None)
data = ExchangeRate.objects.filter(
name__name=currency).values(
'exchange_rate_to_chf').latest(
'date__date')
print('currency:', currency, 'data: ', data)
return JsonResponse(data)
def currencies(request):
"""this function fetches the data from swiss national bank

View File

@ -1,30 +0,0 @@
$("#id_currency_update").change(function () {
var currency_update = $(this).val();
$("#id_currency_update").val(currency_update);
$.ajax({
url: '/ajax/currency_update/',
data: {
'currency_update': currency_update
},
dataType: 'json',
success: function (data) {
var foo = jQuery.parseJSON(data);
alert("es pop auf! --dies kommt von: static/js/app.js--." + foo.currency_update);
}
});
});
//document.getElementById('id_currency_update').getElementsByTagName('currency_update')
//$("#id_currency_update").val('USD').selected = 'selected';
//https://stackoverflow.com/a/30489067/4061870
// var obj = document.getElementById("id_currency_update");
// for(i=0; i<obj.options.length; i++){
// if(obj.options[i].value == "USD"){
// obj.selectedIndex = i;
// }
// }
// var e document.getElementById("id_currency_update");
//e.value = currency_update;

View File

@ -93,7 +93,6 @@
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="{% static 'js/app.js' %}"></script>
<script>{% block javascript %}{% endblock %}</script>
</body>
</html>