def handle_offline_add(request): if request.method == 'POST': print request.POST model_name = request.POST.get('model_name') s_no = request.POST.get('s_no') processor = request.POST.get('processor') hdd = request.POST.get('hdd') ram = request.POST.get('ram') os = request.POST.get('os') working = 0 hdd_change_date = datetime.now() ram_change_date = datetime.now() flag = 0 if model_name=="" or s_no=="" or processor=="" or hdd=="" or ram=="" or os=="": flag=1 orderby = Poll.objects.order_by('id') if orderby: for poll in orderby: if s_no==poll.s_no and s_no: flag=1 print "alreadyinuse" return render(request, 'manager/inuse.html', locals()) p = Poll(uid='', asset_code = '', asset_category = '', region = '', unit = '', location = '', floor = '', username = '', empcode = '', designation = '', department = '', machinename = '', role = '', model_name = model_name, s_no = s_no, processor = processor, hdd = hdd, ram = ram, os = os, warr_amc = '', warr_vend = '', warr_start_date = '', warr_exp_date = '', company = '', po_details = '', working = working, ram_change_date = ram_change_date, hdd_change_date = hdd_change_date) if flag == 0: p.save(); print 'saving form' return HttpResponseRedirect("/manager/view_offline_stock/") # else: # return render(request, 'manager/notadded.html', locals()) else: form = PollForm() return render(request, 'manager/addofflinestock.html', locals())
def post_config(request): if request.method == 'POST': json_data = simplejson.loads(request.raw_post_data) print json_data try: flag = 0 client_data = dict(json_data['client_data']) machinename = client_data['machinename'] s_no = client_data['s_no'] processor = client_data['processor'] ram = client_data['ram'] hdd = client_data['hdd'] os = client_data['os'] ram_change_date = datetime.now() hdd_change_date = datetime.now() orderby = Poll.objects.order_by('id') if orderby: for poll in orderby: if poll.s_no==s_no: poll.working = 1 poll.machinename = machinename poll.processor = processor if poll.ram != ram: poll.ram_change_date = ram_change_date if poll.hdd != hdd: poll.hdd_change_date = hdd_change_date poll.ram = ram poll.hdd = hdd poll.os = os poll.save() flag=1 break working = 1 p = Poll(uid='', asset_code = '', asset_category = '', region = '', unit = '', location = '', floor = '', username = '', empcode = '', designation = '', department = '', machinename = machinename, role = '', model_name = '', s_no = s_no, processor = processor, hdd = hdd, ram = ram, os = os, warr_amc = '', warr_vend = '', warr_start_date = '', warr_exp_date = '', company = '', po_details = '', working = working, ram_change_date=ram_change_date, hdd_change_date=hdd_change_date) if flag==0: p.save() except KeyError: return HttpResponseServerError("Malformed Data, missing key") return HttpResponse(client_data, content_type="application/json", status=200) else: return HttpResponse("Only JSON post accepted", status=404)
def handle_add(request): if request.method == 'POST': print request.POST uid = request.POST.get('uid') asset_code = request.POST.get('asset_code') asset_category = request.POST.get('asset_category') region = request.POST.get('region') unit = request.POST.get('unit') location = request.POST.get('location') floor = request.POST.get('floor') username = request.POST.get('username') empcode = request.POST.get('empcode') designation = request.POST.get('designation') department = request.POST.get('department') machinename = request.POST.get('machinename') role = request.POST.get('role') model_name = request.POST.get('model_name') s_no = request.POST.get('s_no') processor = request.POST.get('processor') hdd = request.POST.get('hdd') ram = request.POST.get('ram') os = request.POST.get('os') warr_amc = request.POST.get('warr_amc') warr_vend = request.POST.get('warr_vend') warr_start_date = request.POST.get('warr_start_date') warr_exp_date = request.POST.get('warr_exp_date') company = request.POST.get('company') po_details = request.POST.get('po_details') ram_change_date = datetime.now() hdd_change_date = datetime.now() working = 1 # if uid & asset_code && asset_category && region && unit && location && floor && username && empcode &&designation && department && machinename && role && model_name && s_no && processor && hdd && ram && os && warr_amc && warr_vend && warr_start_date && warr_exp_date && company && po_details : flag=0 if department=="" or role=="" or model_name=="" or asset_category=="" : flag=1 orderby = Poll.objects.order_by('id') if orderby: for poll in orderby: if s_no==poll.s_no and s_no: flag=1 print "alreadyinuse" return render(request, 'manager/inuse.html', locals()) print uid p = Poll(uid=uid, asset_code = asset_code, asset_category = asset_category, region = region, unit = unit, location = location, floor = floor, username = username, empcode = empcode, designation = designation, department = department, machinename = machinename, role = role, model_name = model_name, s_no = s_no, processor = processor, hdd = hdd, ram = ram, os = os, warr_amc = warr_amc, warr_vend = warr_vend, warr_start_date = warr_start_date, warr_exp_date = warr_exp_date, company = company, po_details = po_details, working = working, ram_change_date = ram_change_date, hdd_change_date = hdd_change_date) if flag==0: p.save() print 'saving form' return HttpResponseRedirect("/manager/view/") # else: # return render(request, 'manager/notadded.html', locals()) else: form = PollForm() return render(request, 'manager/add2.html', locals())