def POST(self): disdir = os.path.join(os.getcwd(),'files') x= web.input(datafile={}) # asmt = x.asmt.lower() # year = x.year # std = x.std # section = x.section # sub = x.subject # max = int(x.max) a = ('year','section','assessment','percent') if 'datafile' in x: filename = x.datafile.filename f = open(os.path.join(disdir,filename),'w') f.write(x.datafile.file.read()) f.close() book = xlrd.open_workbook(os.path.join(disdir,filename)) sheet = book.sheet_by_index(0) # print sheet for rownum in range(sheet.nrows): # if rownum == 0: continue row = sheet.row_values(rownum) if row[0].lower() == 'year': year = row[0].lower() continue if row[0].lower() == 'standard': std = row[0].lower() continue if row[0].lower() == 'section': section = row[0].lower() continue if row[0].lower() == 'assessment': asmt = row[0].lower() continue if row[0].lower() == 'percent': per = row[0].lower() continue if row[0].lower() == 'marks': continue if row[0].lower() == 'sl': continue name = row[1] adnum = row[2] english = float(row[3]) seclang = float(row[4]) maths = float(row[5]) science = float(row[6]) social = float(row[7]) studentid = model.getStudentId(year,std,section,adnum,name) fields = model.asmts[asmt]['fields'] forten = conv.toten(mark,max) grade = conv.grade(conv.tocent(mark,max)) per = conv.getContri(asmt,forten) data = [mark,max,grade,per] markid = model.getMarkId(studentid,sub,year,std,section) model.updateMark(markid,fields,data) raise web.seeother('/upload')
def POST(self): q = web.input() markid = int(q.markid) marks = model.getMarksByMarkId(markid) ret = {} ret = {'fields':{},'id':0, 'status': False} render = web.template.render('templates/', base=None,globals={'context':session}) if 'fa1_m' in q: fa1_m = float(q.fa1_m) forten = conv.toten(fa1_m,marks['fa1_o']) grade = conv.grade(conv.tocent(fa1_m,marks['fa1_o'])) per = conv.getContri('fa1',forten) fields = model.asmts['fa1']['fields'] data= [fa1_m,marks['fa1_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'fa1_m':fa1_m,'fa1_g':grade,'fa1_p': per} ret['id'] = markid ret['status'] = True if 'fa2_m' in q: fa2_m = float(q.fa2_m) forten = conv.toten(fa2_m,marks['fa2_o']) grade = conv.grade(forten) per = conv.getContri('fa2',forten) fields = model.asmts['fa2']['fields'] data = [fa2_m,marks['fa2_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'fa2_m':fa2_m,'fa2_g':grade,'fa2_p': per} ret['id'] = markid ret['status'] = True if 'sa1_m' in q: sa1_m = float(q.sa1_m) forten = conv.toten(sa1_m,marks['sa1_o']) grade = conv.grade(forten) per = conv.getContri('sa1_m',forten) fields = model.asmts['sa1']['fields'] data= [sa1_m,marks['sa1_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'sa1_m':sa1_m,'sa1_g':grade,'sa1_p': per} ret['id'] = markid ret['status'] = True if 'fa3_m' in q: fa3_m = float(q.fa3_m) forten = conv.toten(fa3_m,marks['fa3_o']) grade = conv.grade(forten) per = conv.getContri('fa3_m',forten) fields = model.asmts['fa3']['fields'] data= [fa3_m,marks['fa3_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'fa3_m':fa3_m,'fa3_g':grade,'fa3_p': per} ret['id'] = markid ret['status'] = True if 'fa4_m' in q: fa4_m = float(q.fa4_m) forten = conv.toten(fa4_m,marks['fa4_o']) grade = conv.grade(forten) per = conv.getContri('fa4_m',forten) fields = model.asmts['fa4']['fields'] data=[fa4_m,marks['fa4_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'fa4_m':fa4_m,'fa4_g':grade,'fa3_p': per} ret['id'] = markid ret['status'] = True if 'sa2_m' in q: sa2_m = float(q.sa2_m) forten = conv.toten(sa2_m,marks['sa2_o']) grade = conv.grade(forten) per = conv.getContri('sa2_m',forten) fields = model.asmts['sa2']['fields'] data= [sa2_m,marks['sa2_o'],grade,per] model.updateMark(markid,fields,data) ret['fields'] = {'sa2_m':fa4_m,'sa2_g':grade,'sa23_p': per} ret['id'] = markid ret['status'] = True web.header("Content-Type","text/json;charset=utf-8") return render.savemark(simplejson.dumps(ret))