اخي الكريم هذه الدالة فيها حل لمعادلات رياضية تستقبل ادخال من المستخدم لحل المعادلات... الان جميع البيانات الموجود في context تعرض في html بدون تحديث الصفحة بأستخدام Ajax .. ما عدى total و total1 لانهما لا يعتمدان على ادخال واحد من المستخدم بل تقوم بجمع الادخالات التي قام المستخدم بأدخالها ...
المشكلة التي واجهتني ان الادخالات فيها form و من الform استقبل البيانات و اعرضها بدون تحديث الصفحة
و total , total1 لا يعتمدان على form بل تعتمد على الجمع الادخالات
يعرض لي الحل في حال قمت بتحديث الصفحة فقط
def tab_1(request):
asphalt_singles = request.POST.get('asphalt_singles')
membrane = request.POST.get('Membrane')
sheathing = request.POST.get('Sheathing')
Roof_Trusses = request.POST.get('RoofTrusses')
poly_vapour_barrier = request.POST.get('Poly_Vapour_Barrier')
insulation = request.POST.get('Insulation')
me = request.POST.get('meemem')
drywall = request.POST.get('Drywweqwe')
# Floor
Partition_Allowance = request.POST.get('Partition_Allowance')
Tile_Flooring = request.POST.get('Tile_Flooring')
Sheathing1 = request.POST.get('Sheathing1')
Floor_Joist = request.POST.get('Floor_Joist')
ME2 = request.POST.get('MeeE2')
Drywall_Ceiling = request.POST.get('DrywallCeiling')
id_s = request.session["id"]
pk = Tall_Wall_Input_db.objects.get(id=id_s)
date = datetime.now()
try:
asphalt_singles1 = float(asphalt_singles) * 20.9
pk.asphalt_singles_input = float(asphalt_singles)
pk.date_time = date
pk.save()
return HttpResponse(asphalt_singles1)
except TypeError:
asphalt_singles1 = pk.asphalt_singles_input * 20.9
except ValueError:
asphalt_singles1 = pk.asphalt_singles_input * 20.9
try:
membrane1 = float(membrane) * 20.9
pk.membrane_input = float(membrane)
pk.date_time = date
pk.save()
return HttpResponse(membrane1)
except TypeError:
membrane1 = pk.membrane_input * 20.9
except ValueError:
membrane1 = pk.membrane_input * 20.9
try:
pk.sheathing_input = float(sheathing)
pk.date_time = date
pk.save()
except TypeError:
sheathingw1 = pk.sheathing_input
except ValueError:
sheathingw1 = pk.sheathing_input
try:
roof_trusses1 = float(Roof_Trusses) * 20.9
pk.roof_trusses_input = float(Roof_Trusses)
pk.date_time = date
pk.save()
return HttpResponse(roof_trusses1)
except TypeError:
roof_trusses1 = pk.roof_trusses_input * 20.9
except ValueError:
roof_trusses1 = pk.roof_trusses_input * 20.9
try:
poly_vapour_barrier1 = float(poly_vapour_barrier) * 20.9
pk.poly_vapour_barrier_input = float(poly_vapour_barrier)
pk.date_time = date
pk.save()
return HttpResponse(poly_vapour_barrier1)
except TypeError:
poly_vapour_barrier1 = pk.poly_vapour_barrier_input * 20.9
except ValueError:
poly_vapour_barrier1 = pk.poly_vapour_barrier_input * 20.9
try:
pk.insulation_input = float(insulation)
print(insulation)
pk.date_time = date
pk.save()
except TypeError:
insulation1 = 3 * 8 / 12
except ValueError:
insulation1 = 3 * 8 / 12
try:
me1 = float(me) * 20.9
pk.me_input = float(me)
pk.date_time = date
pk.save()
return HttpResponse(me1)
except TypeError:
me1 = pk.me_input * 20.9
except ValueError:
me1 = pk.me_input * 20.9
try:
drywall1 = float(drywall) * 20.9
pk.drywall_input = float(drywall)
pk.date_time = date
pk.save()
return HttpResponse(drywall1)
except TypeError:
drywall1 = pk.drywall_input * 20.9
except ValueError:
drywall1 = pk.drywall_input * 20.9
try:
total = pk.asphalt_singles_input + pk.membrane_input + pk.sheathing_input + pk.roof_trusses_input + pk.poly_vapour_barrier_input + pk.insulation_input + pk.me_input + pk.drywall_input
except TypeError:
total = 0
try:
total1 = float(asphalt_singles1) + float(membrane1) + 2.08 + float(roof_trusses1) + float(
poly_vapour_barrier1) + 2.0 + float(me1) + float(drywall1)
pk.total1 = total1
pk.total1 = total1
pk.save()
except TypeError as f:
total1 = 0
# input value Roof
asphalt_singles_input_value = pk.asphalt_singles_input
membrane_input_value = pk.membrane_input
sheathing_input_value = pk.sheathing_input
roof_trusses_input_value = pk.roof_trusses_input
poly_vapour_barrier_input_value = pk.poly_vapour_barrier_input
insulation_input_value = pk.insulation_input
me_input_value = pk.me_input
drywall_input_value = pk.drywall_input
# Floor
try:
Partition_Allowance1 = float(Partition_Allowance) * 20.9
pk.Partition_Allowance_input = float(Partition_Allowance)
pk.date_time = date
pk.save()
return HttpResponse(Partition_Allowance1)
except TypeError:
Partition_Allowance1 = pk.Partition_Allowance_input * 20.9
except ValueError:
Partition_Allowance1 = pk.Partition_Allowance_input * 20.9
try:
Tile_Flooring1 = float(Tile_Flooring) * 20.9
pk.Tile_Flooring_input = float(Tile_Flooring)
pk.date_time = date
pk.save()
return HttpResponse(Tile_Flooring1)
except TypeError:
Tile_Flooring1 = pk.Tile_Flooring_input * 20.9
except ValueError:
Tile_Flooring1 = pk.Tile_Flooring_input * 20.9
try:
s = float(Sheathing1) * 7
pk.Sheathing1_input = float(Sheathing1)
pk.date_time = date
pk.save()
except TypeError:
sheathing2 = pk.Sheathing1_input
except ValueError:
sheathing2 = pk.Sheathing1_input
try:
Floor_Joist1 = float(Floor_Joist) * 20.9
pk.Floor_Joist_input = float(Floor_Joist)
pk.date_time = date
pk.save()
return HttpResponse(Floor_Joist1)
except TypeError:
Floor_Joist1 = pk.Floor_Joist_input * 20.9
except ValueError:
Floor_Joist1 = pk.Floor_Joist_input * 20.9
try:
ME22 = float(ME2) * 20.9
pk.ME2_input = float(ME2)
pk.date_time = date
pk.save()
return HttpResponse(ME22)
except TypeError:
ME22 = pk.ME2_input * 20.9
except ValueError:
ME22 = pk.ME2_input * 20.9
try:
Drywall_Ceiling1 = float(Drywall_Ceiling) * 20.9
pk.Drywall_Ceiling_input = float(Drywall_Ceiling)
pk.date_time = date
pk.save()
return HttpResponse(Drywall_Ceiling1)
except TypeError:
Drywall_Ceiling1 = pk.Drywall_Ceiling_input * 20.9
except ValueError:
Drywall_Ceiling1 = pk.Drywall_Ceiling_input * 20.9
return HttpResponse(Drywall_Ceiling1)
try:
Total_Roof = pk.Partition_Allowance_input + pk.Tile_Flooring_input + pk.Sheathing1_input + pk.Floor_Joist_input + pk.ME2_input + pk.Drywall_Ceiling_input
except TypeError:
Total_Roof = 0
try:
s = 40 * (0.75 / 12)
Total_Roof1 = Partition_Allowance1 + Tile_Flooring1 + s + Floor_Joist1 + ME22 + Drywall_Ceiling1
pk.Total_Roof1 = Total_Roof1
pk.Total_Roof1 = Total_Roof1
print('Total_Roof1', Total_Roof1)
except TypeError:
Total_Roof1 = 0
# __________________________________________________________
Partition_Allowance_input_value = pk.Partition_Allowance_input
Tile_Flooring_input_value = pk.Tile_Flooring_input
Sheathing1_input_value = pk.Sheathing1_input
Floor_Joist_input_value = pk.Floor_Joist_input
ME2_input_value = pk.ME2_input
Drywall_Ceiling_input_value = pk.Drywall_Ceiling_input
context = {
# Roof
'asphalt_singles1': round(asphalt_singles1, 2),
'membrane': round(membrane1, 2),
'sheathing': round(40 * (0.625 / 12), 2),
'roof_trusses': round(roof_trusses1, 2),
'poly_vapour_barrier': round(poly_vapour_barrier1, 2),
'insulation': 3 * 8 / 12,
'me': round(me1, 2),
'drywall': round(drywall1, 2),
'total': round(total, 2),
'total1': round(total1, 2),
# In order to keep the value entered by the user
'asphalt_singles_input_value': round(asphalt_singles_input_value, 2),
'membrane_input_value': round(membrane_input_value, 2),
'sheathing_input_value': round(sheathing_input_value, 2),
'roof_trusses_input_value': round(roof_trusses_input_value, 2),
'poly_vapour_barrier_input_value': round(poly_vapour_barrier_input_value, 2),
'insulation_input_value': round(insulation_input_value, 2),
'me_input_value': round(me_input_value, 2),
'drywall_input_value': round(drywall_input_value, 2),
# Floor
'Partition_Allowance1': round(Partition_Allowance1, 2),
'Tile_Flooring1': round(Tile_Flooring1, 2),
'Sheathing2': round(40 * (0.75 / 12), 2),
'Floor_Joist1': round(Floor_Joist1, 2),
'ME22': round(ME22, 2),
'Drywall_Ceiling1': round(Drywall_Ceiling1, 2),
'Total_Roof': round(Total_Roof, 2),
'Total_Roof12': round(Total_Roof1, 2),
# In order to keep the value entered by the user
'Partition_Allowance_input_value': Partition_Allowance_input_value,
'Tile_Flooring_input_value': Tile_Flooring_input_value,
'Sheathing1_input_value': Sheathing1_input_value,
'Floor_Joist_input_value': Floor_Joist_input_value,
'ME2_input_value': ME2_input_value,
'Drywall_Ceiling_input_value': Drywall_Ceiling_input_value,
}
return render(request, 'db_math/tab1.html', context)