def saveWFPData(request, wfp_form, year, agency_id): wfp = WFPData( year = year, activity = wfp_form.cleaned_data['activity'], allocation = request.POST.get('allocation'), agency = Agency.objects.get(id=agency_id), jan = wfp_form.cleaned_data['jan'], feb = wfp_form.cleaned_data['feb'], mar = wfp_form.cleaned_data['mar'], apr = wfp_form.cleaned_data['apr'], may = wfp_form.cleaned_data['may'], jun = wfp_form.cleaned_data['jun'], jul = wfp_form.cleaned_data['jul'], aug = wfp_form.cleaned_data['aug'], sept = wfp_form.cleaned_data['sept'], oct = wfp_form.cleaned_data['oct'], nov = wfp_form.cleaned_data['nov'], dec = wfp_form.cleaned_data['dec'] ) wfp.total = wfp.jan + wfp.feb + wfp.mar + wfp.apr + wfp.may + wfp.jun + wfp.jul + wfp.aug + wfp.sept + wfp.oct + wfp.nov + wfp.dec wfp.save() #save performance indicator perf_indics = request.POST.getlist('pis[]') for pi in perf_indics: pi_info = pi.split(';') perf_target = PerformanceTarget(wfp_activity=wfp, indicator=pi_info[0], q1=pi_info[1], q2=pi_info[2], q3=pi_info[3], q4=pi_info[4] ) perf_target.save()
def addPerfTarget(request): try: wfp_id = request.GET.get('id_wfp') wfp = WFPData.objects.get(id=wfp_id) perf_target = PerformanceTarget(wfp_activity = wfp, indicator = request.GET.get('pi'), jan = request.GET.get('jan', 0), feb = request.GET.get('feb', 0), mar = request.GET.get('mar', 0), apr = request.GET.get('apr', 0), may = request.GET.get('may', 0), jun = request.GET.get('jun', 0), jul = request.GET.get('jul', 0), aug = request.GET.get('aug', 0), sept = request.GET.get('sept', 0), oct = request.GET.get('oct', 0), nov = request.GET.get('nov', 0), dec = request.GET.get('dec', 0) ) perf_target.save() return HttpResponse('Added') except WFPData.DoesNotExist: return HttpResponse('Error')
def addEditPerfTarget(request): try: action = request.GET.get('action') print action if action == 'add': wfp_id = request.GET.get('id_wfp') wfp = WFPData.objects.get(id=wfp_id) perf_target = PerformanceTarget(wfp_activity = wfp, indicator = request.GET.get('indicator'), jan = request.GET.get('jan', 0), feb = request.GET.get('feb', 0), mar = request.GET.get('mar', 0), apr = request.GET.get('apr', 0), may = request.GET.get('may', 0), jun = request.GET.get('jun', 0), jul = request.GET.get('jul', 0), aug = request.GET.get('aug', 0), sept = request.GET.get('sept', 0), oct = request.GET.get('oct', 0), nov = request.GET.get('nov', 0), dec = request.GET.get('dec', 0) ) perf_target.save() json_response = json.dumps({'action' : 'add', 'id' : perf_target.id, 'wfp_id' : perf_target.wfp_activity.id, 'indicator' : perf_target.indicator, 'jan' : perf_target.jan, 'feb' : perf_target.feb, 'mar' : perf_target.mar, 'apr' : perf_target.apr, 'may' : perf_target.may, 'jun' : perf_target.jun, 'jul' : perf_target.jul, 'aug' : perf_target.aug, 'sept' : perf_target.sept, 'oct' : perf_target.oct, 'nov' : perf_target.nov, 'dec' : perf_target.dec}) return HttpResponse(json_response, content_type = "application/json") else:#edit id = request.GET['id_ppt'] perf_target = PerformanceTarget.objects.get(id = id) perf_target.indicator = request.GET['indicator'] perf_target.jan = request.GET['jan'] perf_target.feb = request.GET['feb'] perf_target.mar = request.GET['mar'] perf_target.apr = request.GET['apr'] perf_target.may = request.GET['may'] perf_target.jun = request.GET['jun'] perf_target.jul = request.GET['jul'] perf_target.aug = request.GET['aug'] perf_target.sept = request.GET['sept'] perf_target.oct = request.GET['oct'] perf_target.nov = request.GET['nov'] perf_target.dec = request.GET['dec'] perf_target.save() json_response = json.dumps({'action' : 'edit', 'id' : perf_target.id, 'wfp_id' : perf_target.wfp_activity.id, 'indicator' : perf_target.indicator, 'jan' : perf_target.jan, 'feb' : perf_target.feb, 'mar' : perf_target.mar, 'apr' : perf_target.apr, 'may' : perf_target.may, 'jun' : perf_target.jun, 'jul' : perf_target.jul, 'aug' : perf_target.aug, 'sept' : perf_target.sept, 'oct' : perf_target.oct, 'nov' : perf_target.nov, 'dec' : perf_target.dec}) return HttpResponse(json_response, content_type = "application/json") except WFPData.DoesNotExist: return HttpResponse('Error')