not finished AJAX request for currencies

This commit is contained in:
Ivan Hörler 2018-01-14 19:57:48 +01:00
parent e765a999c6
commit 19af243c4f
5 changed files with 34 additions and 10 deletions

View File

@ -4,4 +4,7 @@ from currencies.views import currencies, CurrencyUpdate
urlpatterns = [ urlpatterns = [
url(r'^currencies/$', currencies), url(r'^currencies/$', currencies),
url(r'^ajax/CurrencyUpdate/$',
CurrencyUpdate,
name='CurrencyUpdate'),
] ]

View File

@ -7,17 +7,18 @@ from currencies.models import (ExchangeRate,
ExchangeRate_name) ExchangeRate_name)
from currencies import exchange_rates from currencies import exchange_rates
from currencies.forms import CurrencyForm from currencies.forms import CurrencyForm
from django.http import JsonResponse
def CurrencyUpdate(request): def CurrencyUpdate(request):
if request.method == 'POST': assert False
currency_form = CurrencyForm currency = request.GET.get('CurrencyUpdate', None)
assert False data = {
else: 'currency': ExchangeRate_name.objects.filter(
currency_form = CurrencyForm name=currency)
assert False }
return render(request, return JsonResponse(data)
{'currency_form': currency_form})
def currencies(request): def currencies(request):
# this function fetches the data from exchange_rates.py # this function fetches the data from exchange_rates.py

View File

@ -0,0 +1,15 @@
$("#id_currency").change(function () {
var currency = $(this).val();
$.ajax({
url: '/ajax/CurrencyUpdate/',
data: {
'currency': currency
},
dataType: 'json',
success: function (data) {
if (data.is_taken) {
alert("es pop auf! --dies kommt von: static/js/app.js--.");
}
}
});
});

View File

@ -11,6 +11,10 @@ urlpatterns = [
views.articles_in_category, views.articles_in_category,
name='category'), name='category'),
url('^', include('django.contrib.auth.urls')), url('^', include('django.contrib.auth.urls')),
url(r'^profile/$', views.profile, name='profile'), url(r'^profile/$',
url(r'^registration/$', views.registration, name='registration'), views.profile,
name='profile'),
url(r'^registration/$',
views.registration,
name='registration'),
] ]

View File

@ -11,6 +11,7 @@ from webshop.models import (Article,
Picture) Picture)
from webshop.forms import RegistrationForm from webshop.forms import RegistrationForm
# Create your views here. # Create your views here.