Всем привет!
Столкнулся с каменной стеной)
Если отправляю форму обычным способом
def main_form(request):
priceHddruEnter()
priceHddru()
priceHddusd()
priceThecus()
use = Used.objects.all()
usehdd = Hdd.objects.all()
thecus = Thecus.objects.all()
if request.method == 'POST':
form = MainForm(request.POST)
if form.is_valid():
z = form.cleaned_data['thecus']
x = form.cleaned_data['use']
c = form.cleaned_data['hdd']
v = form.cleaned_data['G10']
n = form.cleaned_data['Sas_adapter']
m = form.cleaned_data['kol_hdd']
b = KursDollara.objects.get()
gtr = Card.objects.get()
sas = SasAdapter.objects.get()
if z.G10 == True and z.sas == False and v == True:
G = 'G'
elif z.G10 == True and z.sas == False and v == False:
G = 'A'
elif z.G10 == False:
G = 'N'
elif z.sas == True and n == True and v == False:
G = 'S'
elif z.sas == True and z.G10 == True and n == True and v == True:
G = 'H'
elif z.sas == True and z.G10 == True and n == False and v == False:
G = 'A'
elif z.sas == True and z.G10 == True and n == False and v == True:
G = 'G'
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + str(
c.volume_of_storage * m) + 'T'
if z.name == 'N4510UProR':
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + 'R' + '-' + str(c.volume_of_storage * m) + 'T'
elif z.name == 'N4510UProS':
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + 'S' + '-' + str(c.volume_of_storage * m) + 'T'
if z.name == 'N7710-G' or z.name == 'N8810U-G':
articul = str(z.articul) + str(z.mounting_type) + 'G' + str(x.ident) + '-' + str(c.volume_of_storage * m) + 'T'
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m)), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m)), 2)
if G == 'G' and z.name != 'N7710-G' and z.name != 'N8810U-G':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + gtr.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + gtr.price), 2)
elif G == 'S':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + sas.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + sas.price), 2)
elif G == 'H':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + gtr.price + sas.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + gtr.price + sas.price), 2)
return render(request, 'datasafe/index.html',
{'form': form, 'articul': articul, 'priceRU': priceru, 'priceUSD': priceusd, 'hdd': c,
'kolHDD': m, 'uses': use, 'usehdd': usehdd, 'thecus': thecus})
else:
form = MainForm()
return render(request, 'datasafe/index.html', {'form': form, 'uses': use, 'usehdd': usehdd, 'thecus': thecus})
то ответ приходит без ошибок и все прекрасно.
Делаю тоже самое аяксом
def main_form(request):
priceHddruEnter()
priceHddru()
priceHddusd()
priceThecus()
use = Used.objects.all()
usehdd = Hdd.objects.all()
thecus = Thecus.objects.all()
if request.method == 'POST' and request.is_ajax():
z = Thecus.objects.get(id=request.POST.get('thecus'))
x = Used.objects.get(id=request.POST.get('use'))
c = Hdd.objects.get(id=request.POST.get('hdd'))
v = request.POST.get('G10')
n = request.POST.get('Sas_adapter')
m = int(request.POST.get('kol_hdd'))
b = KursDollara.objects.get()
gtr = Card.objects.get()
sas = SasAdapter.objects.get()
if z.G10 == True and z.sas == False and v == True:
G = 'G'
elif z.G10 == True and z.sas == False and v == False:
G = 'A'
elif z.G10 == False:
G = 'N'
elif z.sas == True and n == True and v == False:
G = 'S'
elif z.sas == True and z.G10 == True and n == True and v == True:
G = 'H'
elif z.sas == True and z.G10 == True and n == False and v == False:
G = 'A'
elif z.sas == True and z.G10 == True and n == False and v == True:
G = 'G'
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + str(
c.volume_of_storage * m) + 'T'
if z.name == 'N4510UProR':
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + 'R' + '-' + str(c.volume_of_storage * m) + 'T'
elif z.name == 'N4510UProS':
articul = str(z.articul) + str(z.mounting_type) + G + str(x.ident) + '-' + 'S' + '-' + str(c.volume_of_storage * m) + 'T'
if z.name == 'N7710-G' or z.name == 'N8810U-G':
articul = str(z.articul) + str(z.mounting_type) + 'G' + str(x.ident) + '-' + str(c.volume_of_storage * m) + 'T'
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m)), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m)), 2)
if G == 'G' and z.name != 'N7710-G' and z.name != 'N8810U-G':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + gtr.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + gtr.price), 2)
elif G == 'S':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + sas.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + sas.price), 2)
elif G == 'H':
priceru = round((z.price + ((c.priceru + (c.priceru * 0.06)) * 1.5 * m) + gtr.price + sas.price), 2)
priceusd = round((z.price + ((c.priceusd + c.priceusd * 0.065) * b.kurs * 1.5 * m) + gtr.price + sas.price), 2)
return JsonResponse({'articul': articul, 'priceru': priceru, 'priceusd': priceusd, 'hddpresence1': c.presence1,
'hddpresence2': c.presence2, 'vibranohdd': m})
else:
form = MainForm()
return render(request, 'datasafe/index.html', {'form': form, 'uses': use, 'usehdd': usehdd, 'thecus': thecus})
и вылазиет ошибка local variable 'G' might be referenced before assignment