def OnButtonOkButton(self, event): try: #Consistency name = self.get_name() if len(name) == 0: raise error_x("Please inform name.") wn1 = self.get_wn1() wn2 = self.get_wn2() wncount = self.get_wncount() # I don't check wncount ... TODO ... mysql error if non-numerical shit comments = self.get_comments() d = { "name": name, "wn1": wn1, "wn2": wn2, "wncount": wncount, "comments": comments } if self.mode == "edit": t_domain.update(d, self.get_id()) else: t_domain.insert(d) self.result = wx.ID_OK self.Close() except error_x, e: output(e.message, OUTPUT_ERROR, True)
def POST(self): input = web.input(letter_id=None) if input.letter_id == None: return output(110) try: input.letter_id = int(input.letter_id) except: return output(111) db = getDb() result = db.select('letter_detail', var={'id': input.letter_id}, where='letter_id = $id', what='content,add_time') if len(result) == 0: return output(450) try: db.update('letter', vars={'id': input.letter_id}, where="letter_id=$id", have_read='1') except: return output(700) return output(200, { 'content': result[0].content, "add_time": result[0].add_time })
def confirm(self): index1 = self.choiceExperiment.GetSelection() index2 = self.choiceDomain.GetSelection() index3 = self.choiceDeact.GetSelection() try: idexperiment = self.get_idexperiment() if not idexperiment: raise error_x("Please select an experiment.") iddomain = self.get_iddomain() if not iddomain: raise error_x("Please select a domain.") iddeact = self.get_iddeact() if not iddeact: raise error_x("Please select an activation scheme.") session.idexperiment = self.get_idexperiment() session.iddomain = self.get_iddomain() session.iddeact = self.get_iddeact() t_setup.update({ "def_idexperiment": self.get_idexperiment(), "def_iddomain": self.get_iddomain(), "def_iddeact": self.get_iddeact() }) self.Close() except error_x, e: output(e.message, OUTPUT_ERROR, True)
def POST(self): input = web.input(access_token = '' , user_id = '' , food_list = None , address_id = '') try: input.user_id = int(input.user_id) except: #TODO:user_id is not an integer return output(700) db = getDb() user_id = db.select('token' , vars={'access_token':input.access_token , 'user_id' : input.user_id} , where = "access_token=$access_token and user_id=$user_id") if len(user_id) == 0: return output(420) #todo 权限不足 user_id = user_id[0].user_id campus_id =db.select('user' , vars = {'user_id':user_id} , where = "user_id=$user_id")[0].campus_id t = db.transaction() try: new_order_id = db.insert('orders' , address_id = input.address_id ,campus_id = campus_id , status ="submitted" , user_id = user_id ) food_list = json.loads(input.food_list) for i in food_list: db.insert('ordered_food', order_id = new_order_id, food_id = i['food_id'] , number = i['food_num']) except: t.rollback() return output(700) else : t.commit() return output(200)
def POST(self): input = web.input(access_token = None, user_id = None) if input.access_token == None or input.user_id == None: return output(110) try: input.user_id = int(input.user_id) except: return output(111) db = getDb() if len(db.select('token', vars = {'token':input.access_token, 'id':input.user_id}, where = "access_token=$token and user_id=$id")) == 0: return output(410) campus_id = db.select('user', vars = {'id':input.user_id}, where = "user_id=$id", what = "campus_id")[0].campus_id results = db.select('region', vars = {'id':campus_id}, where = "campus_id=$id", what = "region_id, region_name") region_list = [] for i in results: region_list.append({'id':i.region_id, 'name':i.region_name}) return output(200, region_list)
def POST(self): input = web.input(access_token = None, user_id = None) if input.access_token == None or input.user_id == None: return output(110) try: input.user_id = int(input.user_id) except: return output(111) db = getDb() results = db.select('token', vars = {'token':input.access_token, 'id':input.user_id}, where = 'access_token=$token and user_id=$id') if len(results) == 0: return output(410) message_list = [] results = db.select('messages', vars = {'id':input.user_id}, where = "receiver_id=$id", what = "sender_id,content,add_time") for message in results: message_list.append({'sender_id':message.sender_id, 'content':message.content, 'add_time':str(message.add_time)}) try: db.delete('messages', vars = {'id':input.user_id}, where = "receiver_id=$id") except: return output(700) return output(200, message_list)
def getUserInfo(): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] == 0: return output(410) db = getDb() results = db.select('userinfo', vars={'id': session['user_id']}, where="user_id=$id") if len(results) == 0: return output(423) userinfo = results[0] return output( 200, { 'name': userinfo.name, 'school_id': userinfo.school_id, 'major_id': userinfo.major_id, 'nickname': userinfo.nickname, 'sid': userinfo.sid, 'email': userinfo.email, 'qq': userinfo.qq, 'phone': userinfo.phone, 'is_male': True if userinfo.gender == 'male' else False, 'birthday': userinfo.birthday })
def OnButtonOkButton(self, event): try: self.result = wx.ID_OK self.Close() except error_x, e: output(e.message, OUTPUT_ERROR, True)
def POST(self): input = web.input(email = None) if input.email == None: return output(110) db = getDb() results = db.select('user', vars = {'login_name' : input.email}, where = "login_name=$email and type!='2'", what = "user_id") if len(results) == 0: return output(422) user_id = results[0].user_id verify_code = str(random.randint(000000, 999999)) status = send_mail(input.email,"密码找回确认","\n您的验证码为"+verify_code+"\n该验证码在30分钟内有效") if status == -1: return output(421) t = db.transaction() try: results = db.select('verify', vars = {'id':user_id}, where = "user_id=$id") if len(results) == 0: db.insert('verify', user_id = user_id, verify_code = str(verify_code), add_time = int(time.mktime(time.localtime()))) else: db.update('verify', vars = {'id':user_id}, where = "user_id=$id", verify_code = str(verify_code), add_time = int(time.mktime(time.localtime()))) t.commit() except: t.rollback() return output(700) return output(200, {'verify_code_md5' : encrypt(verify_code)})
def import_file__(self, flag_simulate): colony_code = os.path.basename(self.file_name) self.parse_colony_code(colony_code) output("Colony code: '%s'." % self.colony_code) import csv o_reader = csv.reader(self.file_handle) self.lineno = 0 for s_y_s in o_reader: wncount = len(s_y_s) if self.lineno == 0: output("Wavenumber count: %s" % wncount) self.assure_good_wncount(wncount) if not flag_simulate: self.create_spectrum() y_values = [float(s) for s in s_y_s] if not flag_simulate: for s_y in y_values: t_series.insert(self.idspectrum, self.idexperiment, s_y) self.count_series += 1 self.lineno += 1
def POST(self): # 传入 access_token,user_id,post_id input = web.input(access_token=None, post_id=None, user_id=None) if (input.access_token == None or input.post_id == None or input.user_id == None): return output(110) # 判断参数类型 try: input.user_id = int(input.user_id) input.post_id = int(input.post_id) except: return output(117) db = getDb() owner_id = db.select('token', vars={'access_token': input.access_token,'user_id':input.user_id}, where="access_token=$access_token and user_id=$user_id", what='user_id') if len(owner_id) == 0: return output(412) # if_have = db.select('post', vars={'user_id': input.user_id, 'post_id': input.post_id}, # where="user_id=$user_id and post_id=$post_id") # # todo 已点赞,再次点赞则返回啥? # if len(if_have) != 0: # return output(233) try: db.insert('favor', post_id=input.post_id, user_id=input.user_id) except: return output(700) return output(200)
def getUserInfo(): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] == 0: return output(410) db = getDb() results = db.select('userinfo', vars = {'id':session['user_id']}, where = "user_id=$id") if len(results) == 0: return output(423) userinfo = results[0] school_id = userinfo.school_id major_id = userinfo.major_id userinfo = {'name':userinfo.name, 'id_type':userinfo.id_type, 'id_number':userinfo.id_number, 'education_degree':userinfo.education_degree, 'citizenship':userinfo.citizenship, 'nationality':userinfo.nationality, 'characters':userinfo.characters, 'address':userinfo.address, 'address_detail':userinfo.address_detail, 'phone':userinfo.phone, 'grade':userinfo.grade, 'political_face':userinfo.political_face, 'school_id':userinfo.school_id, 'major_id':userinfo.major_id, 'sid':userinfo.sid, 'email':userinfo.email, 'birthday':userinfo.birthday, 'nickname':userinfo.nickname, 'is_male': True if userinfo.gender == 'male' else False} userinfo['school_name'] = db.select('school', vars = {'id':school_id}, where = "school_id=$id", what = 'school_name')[0].school_name userinfo['major_name'] = db.select('major', vars = {'id':major_id}, where = "major_id=$id", what = 'major_name')[0].major_name return output(200, userinfo)
def POST(self): input = web.input(recruit_id = None) if input.recruit_id == None: return output(110) try: input.recruit_id = int(input.recruit_id) except: return output(111) db = getDb() results = db.select('recruit', vars = {'id':input.recruit_id}, where = "recruit_id=$id") if len(results) == 0: return output(468) results = results[0] info = {'recruit_id':results.recruit_id, 'title':results.recruit_title, 'team_id':results.team_id, 'recruit_num':results.recruit_count, 'add_time':results.add_time, 'content':results.content} info['team_name'] = db.select('team', vars = {'id':info['team_id']}, where = "team_id=$id", what = "team_name")[0].team_name return output(200, info)
def POST(self): input = web.input(place_name=None, start_time=None, end_time=None) if input.place_name == None or input.start_time == None or input.end_time == None: return output(110) session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] not in (2, 3, 4): return output(410) db = getDb() team_name = db.select('team', vars={'id': session['team_id']}, where="team_id=$id", what="team_name")[0].team_name try: db.insert('room_apply', team_name=team_name, user_id=session['user_id'], place_name=input.place_name, begin_time=input.start_time, end_time=input.end_time, status='ongoing', add_time=int(time.mktime(time.localtime()))) return output(200) except: return output(700)
def getAdmin_list(): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] != 0: return output(410) db = getDb() getUser_id = db.select("user",vars ={"type":'1'}, where = "type=$type", what = "user_id,login_name") admin_second_list =[] for i in getUser_id: getUser_info =db.select("userinfo",vars={"user_id":i.user_id}, order = "school_id desc", where = "user_id=$user_id", what = "phone,name,school_id,major_id") results=getUser_info[0] getSchool_info =db.select("school",vars={"school_id":results.school_id}, where ="school_id=$school_id", what ="school_name") getMajor_info =db.select("major",vars={"major_id":results.major_id}, where ="major_id=$major_id", what = "major_name") admin_second_list.append({"user_id":i.user_id, 'login_name':i.login_name, "name":results.name, "school_name":getSchool_info[0].school_name, "major_name":getMajor_info[0].major_name, 'phone':results.phone}) return output(200,admin_second_list)
def POST(self): input = web.input(post_id = None) if input.post_id == None: return output(110) try: input.post_id = int(input.post_id) except: return output(111) db = getDb() result = db.select('post' , vars = {'post_id':input.post_id} ,where = "post_id=$post_id") if len(result)==0: return output(466) post = result[0] try: nickname = db.select('userinfo' ,vars = {'user_id':post.user_id} ,where = "user_id=$user_id" )[0].nickname except: nickname = "NULL" data = {'post_id':post.post_id , 'title':post.title , 'user_id':post.user_id ,'nickname':nickname , 'content':post.content , 'add_time':post.add_time} return output(200, data)
def POST(self): input = web.input(email = None) if input.email == None: return output(110) db = getDb() results = db.select('user', vars = {'login_name' : input.email}, where = "login_name=$login_name and type!='2'", what = "user_id") if len(results) == 0: return output(422) user_id = results[0].user_id verify_code = str(random.randint(000000, 999999)) status = send_mail(input.email,"密码找回确认","\n您的验证码为"+verify_code+"\n该验证码在30分钟内有效") if status == -1: return output(421) t = db.transaction() try: results = db.select('verify', vars = {'id':user_id}, where = "user_id=$id") if len(results) == 0: db.insert('verify', user_id = user_id, verify_code = str(verify_code), add_time = int(time.mktime(time.localtime()))) else: db.update('verify', vars = {'id':user_id}, where = "user_id=$id", verify_code = str(verify_code), add_time = int(time.mktime(time.localtime()))) t.commit() except: t.rollback() return output(700) return output(200, {'verify_code_md5' : encrypt(verify_code)})
def POST(self): input = web.input(accesstoken='') # 参数不足 if input.access_token == '': return output(118) db = getDb() results = db.select('campus_token', vars={'token': input.access_token}, where='access_token=$token', what="campus_id",order="campus_id desc") if len(results) > 0: try: # 获取camupus id campus_id = results[0].campus_id # 查询batch_segment表,获取数据并排序 results = db.select('batch_segment', vars={'campus_id': campus_id}, where='campus_id=$campus_id', order="begin_hour,begin_min,begin_second,end_hour,end_min,end_second asc") data = [] for i in results: data.append(GetTimeStr.getTimeStr(i.begin_hour, i.begin_min, i.end_hour, i.end_min)) # data = sorted(data) data1 = [] indext = 1 for i in data: data1.append({"batch_number": indext, "bacth_string": i}) indext = indext + 1 return output(200, data1) except: return output(700) else: # 权限不足,不允许删 return output(420)
def POST(self): input = web.input(user_id=None) if input.user_id == None: return output(110) try: input.user_id = int(input.user_id) except: return output(111) db = getDb() user_id = input.user_id info = {} user = db.select('user', vars={'id': user_id}, where="user_id=$id")[0] info['mobile'] = user.mobile info['sex'] = user.sex if user.default_address_id == None: info['default_address_id'] = 0 else: info['default_address_id'] = user.default_address_id if user.campus_id != None: results = db.select('campus', vars={'id': user.campus_id}, where="campus_id=$id")[0] info['campus_name'] = results.campus_name info['school_name'] = db.select('school', vars={'id': results.school_id}, where="school_id=$id", what='school_name')[0].school_name else: info['campus_name'] = None info['school_name'] = None info['img_url'] = None info['birthday'] = None info['nickname'] = None info['description'] = None info['location'] = None info['province_id'] = None info['province_name'] = None info['profession'] = None userinfo = db.select('userinfo', vars={'user_id': user_id}, where="user_id=$user_id") for i in userinfo: if i.type == 'province_id': info['province_id'] = int(i.information) else: info[i.type] = i.information if info['province_id'] != None: info['province_name'] = db.select('province', vars={'id': info['province_id']}, where="province_id=$id")[0].province_name del info['province_id'] return output(200, info)
def delete(self): row = self.get_row() if row <> None: act_domain.delete(row[0]) self.read_data() self.fill_grid() else: output("Nothing to delete.", OUTPUT_ERROR)
def OnButtonSpectraButton(self, event): row = self.get_row() if row <> None: act_main.spectrum(row[0]) self.read_data() self.fill_grid() else: output("No colony.", OUTPUT_ERROR)
def OnButtonTraysButton(self, event): row = self.get_row() if row <> None: act_main.tray(row[0]) self.read_data() self.fill_grid() else: output("No experiment.", OUTPUT_ERROR)
def OnButtonSlidesButton(self, event): row = self.get_row() if row <> None: act_main.slide(row[0]) self.read_data() self.fill_grid() else: output("No tray.", OUTPUT_ERROR)
def edit(self): row = self.get_row() if row <> None: act_domain.edit(row[0]) self.read_data() self.fill_grid() else: output("No data to edit.", OUTPUT_ERROR)
def OnButtonColoniesButton(self, event): row = self.get_row() if row <> None: act_main.colony(row[0]) self.read_data() self.fill_grid() else: output("No slide.", OUTPUT_ERROR)
def show_summary(): tables = get_table_names() max_len = max(map(len, tables)) output("Row count for database tables") for table_name in tables: output(table_name.ljust(max_len)+(" %5d" % get_row_count(table_name)))
def POST(self): input = web.input(img_file = {}) if input.img_file == {}: return output(110) try: return output(200, {'content':base64.b64encode(input.img_file.file.read())}) except: return output(700)
def OnButtonOkButton(self, event): index = self.choiceExperiment.GetSelection() try: if index == wx.NOT_FOUND: raise error_x("Please select an experiment.") session.idexperiment = self.data[index][0] except error_x, e: output(e.message, OUTPUT_ERROR, True)
def POST(self): input=web.input(name = None, section_id = None) session=web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type']!=0: return output(410) if input.section_id==None or input.name == None: return output(110) try: input.section_id=int(input.section_id) except: output(111) if len(input.name.strip())>20: return output(112) db=getDb() result=db.select('section',vars={'section_id':input.section_id},where='section_id=$section_id') if len(result)==0: return output(465) try: db.update('section',vars={'section_id':input.section_id}, where='section_id=$section_id', section_name = input.name) return output(200) except: return output(700)
def __init__(self,params,out_path_orig,pymc_import=False,multinest_import=False): params.out_save_plots = True if params.gen_type == 'transmission' or params.fit_transmission: if os.path.isdir(os.path.join(out_path_orig, 'stage_0')): params.out_path = os.path.join(out_path_orig, 'stage_0') else: params.out_path = out_path_orig dataob = data(params) atmosphereob = atmosphere(dataob) forwardmodelob = transmission(atmosphereob) fittingob = fitting(forwardmodelob) if params.mcmc_run and pymc_import: fittingob.MCMC = True if params.nest_run and multinest_import: fittingob.NEST = True outputob = output(fittingob) if params.verbose or params.out_save_plots: outputob.plot_all(save2pdf=params.out_save_plots, param_labels=fittingob.fit_params_texlabels) outputob.save_ascii_spectra() if params.gen_type == 'emission' or params.fit_emission: folders = ['stage_0', 'stage_1'] for f in folders: dir = os.path.join(out_path_orig, f) if os.path.isdir(dir): params.out_path = dir dataob = data(params) if f is 'stage_1': Cov_array = np.loadtxt(os.path.join(out_path_orig, 'stage_0/tp_covariance.dat')) atmosphereob = atmosphere(dataob, tp_profile_type='hybrid', covariance=Cov_array) else: atmosphereob = atmosphere(dataob) forwardmodelob = emission(atmosphereob) fittingob = fitting(forwardmodelob) if params.mcmc_run and pymc_import: fittingob.MCMC = True if params.nest_run and multinest_import: fittingob.NEST = True outputob = output(fittingob) if params.verbose or params.out_save_plots: outputob.plot_all(save2pdf=params.out_save_plots, params_names=fittingob.fit_params_names[:fittingob.fit_X_nparams], params_labels=fittingob.fit_params_texlabels[:fittingob.fit_X_nparams]) outputob.save_ascii_spectra() # save and plot TP profile (plotting only if save2pdf=True) outputob.save_TP_profile(save2pdf=True) #saving TP profile #deleting objectes dataob = None; atmosphereob = None; forwardmodelob = None; fittingob = None; outputob = None del dataob; del atmosphereob; del forwardmodelob; del fittingob; del outputob;
def POST(self): input = web.input(name=None, section_id=None) session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] != 0: return output(410) if input.section_id == None or input.name == None: return output(110) try: input.section_id = int(input.section_id) except: output(111) if len(input.name.strip()) > 20: return output(112) db = getDb() result = db.select('section', vars={'section_id': input.section_id}, where='section_id=$section_id') if len(result) == 0: return output(465) try: db.update('section', vars={'section_id': input.section_id}, where='section_id=$section_id', section_name=input.name) return output(200) except: return output(700)
def POST(self): input = web.input(access_token = None, user_id = None, address_id = None) if input.access_token == None or input.user_id == None: return output(110) try: input.user_id = int(input.user_id) if input.address_id != None: input.address_id = int(input.address_id) except: return output(111) db = getDb() # 查询address_token是否存在 results = db.select('token', vars = {'token': input.access_token, 'id' : input.user_id}, where = 'access_token=$token and user_id=$id') if len(results) != 1: return output(410) if input.address_id == None: results = db.select('address', vars = {'id' : input.user_id}, where = "user_id=$id") else: results = db.select('address', vars = {'aid' : input.address_id, 'id' : input.user_id}, where = "address_id=$aid and user_id=$id") if len(results) == 0: return output(465) addressList = [] for i in results: addressList.append({'address_id' : i.address_id, 'phone' : i.phone, 'consignee' : i.consignee, 'further_detail' : i.further_detail, 'region_id' : i.region_id}) for i in addressList: region_id = i['region_id'] del i['region_id'] results = db.select('region', vars = {'id' : region_id}, where = "region_id=$id")[0] i['region_name'] = results.region_name results = db.select('campus', vars = {'id' : results.campus_id}, where = 'campus_id=$id')[0] i['campus_name'] = results.campus_name results = db.select('school', vars = {'id' : results.school_id}, where = 'school_id=$id')[0] i['school_name'] = results.school_name return output(200, addressList)
def POST(self): if not web.ctx.session.has_key('user_id'): return output(411) input = web.input(post_id = None ) if input.post_id == None: return output(110) try: input.post_id = int(input.post_id) except: return output(111) db = getDb() result = db.select('post' , vars = {'post_id':input.post_id} , where = "post_id=$post_id") if len(result) == 0: return output(466) #判断用户的type 能否执行操作 type = web.ctx.session['user_type'] #管理员 if type == 0 or type == 1: t = db.transaction() try: db.delete('post' , vars = {'post_id':input.post_id} , where = "post_id=$post_id" ) db.delete('reply' , vars = {'post_id':input.post_id} , where = "post_id=$post_id" ) except: t.rollback() return output(700) raise else: t.commit() return output(200) #其他权限 else : user_id = result[0].user_id #非本人 if web.ctx.session['user_id'] != user_id: return output(410) t = db.transaction() try: db.delete('post' , vars = {'post_id':input.post_id} , where = "post_id=$post_id" ) db.delete('reply' , vars = {'post_id':input.post_id} , where = "post_id=$post_id" ) except: t.rollback() return output(700) raise else: t.commit() return output(200)
def POST(self): # 传入 access_token,user_id,post_id,content input = web.input(access_token = None, user_id = None, content = None, img_file = {}) if input.access_token == None or input.user_id == None or input.content==None: return output(110) #验证用户的token 和 user_id 是否对应 #强制转化类型 try : input.user_id = int(input.user_id) except: return output(111) db = getDb() #再判断token 和 user_id 是否对应 result = db.select('token' , vars={'access_token':input.access_token , 'user_id':input.user_id} , where = "user_id=$user_id and access_token=$access_token") if len(result) == 0: return output(410) img_url = None thumbnail_img_url = None t = db.transaction() try: post_id = db.insert('post' , user_id = input.user_id , content = input.content, add_time = None) if input.img_file != {}: suffix = '.jpg' original_filename = "original image of post_id %d" % (post_id,) original_filename = base64.b64encode(original_filename) + suffix thumbnail_filename = "thumbnail image of post_id %d" % (post_id,) thumbnail_filename = base64.b64encode(thumbnail_filename) + suffix original_image = Image.open(StringIO.StringIO(input.img_file.file.read())) width, height = original_image.size thumbnail_image = original_image.crop(getCropBox(width, height)) thumbnail_image.thumbnail((200, 200)) thumbnail_image.save('/var/campus_couple_img/static/' + thumbnail_filename, 'jpeg') original_image.save('/var/campus_couple_img/static/' + original_filename, 'jpeg') img_url = consts.domain_name + '/static/' + original_filename thumbnail_img_url = consts.domain_name + '/static/' + thumbnail_filename if img_url != None and thumbnail_img_url != None: db.update('post', vars = {'id':post_id}, where = "post_id=$id", img_url = img_url, thumbnail_img_url = thumbnail_img_url) t.commit() except: t.rollback() return output(700) return output(200)
def main_functions(): inputData = input() m1 = inputData.get('m1') m2 = inputData.get('m2') L1 = inputData.get('L1') L2 = inputData.get('L2') theta1 = inputData.get('theta1') theta2 = inputData.get('theta2') g = inputData.get('g') t = inputData.get('t') temp = ODE(theta1, theta2, m1, m2, L1, L2, g, t) output(temp[0], temp[1], temp[2]) plot(temp[0], temp[1], temp[2])
def shorthand_decrypting(output_txt): path_from_picture = filedialog.askopenfilename() if os.path.exists(path_from_picture): changed = Image.open(path_from_picture) width = changed.size[0] height = changed.size[1] pixels = changed.load() numbers = getting_mes_size(pixels) decrypted_mes = decrypting(numbers, width, height, pixels) output(output_txt, decrypted_mes)
def GET(self): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] == 0: return output(410) user_id = session['user_id'] db =getDb() result = db.select('userinfo',var ={'user_id':user_id}, where = 'user_id=$user_id', what = 'name') res = result[0] return output(200,{'name':res.name})
def POST(self): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] == 0: return output(410) user_id = session['user_id'] db =getDb() result = db.select('userinfo',var ={'user_id':user_id}, where = 'user_id=$user_id', what = 'name,email,address,qq,phone,gender') res = result[0] return output(200,{'name':res.name,'email':res.email,'address':res.address, 'qq':res.qq,'phone':res.phone,'gender':res.gender})
def POST(self): input = web.input(activity_id = None) if input.activity_id == None: return output(110) try: input.activity_id = int(input.activity_id) except: return output(111) session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] not in (2, 3, 4): return output(410) db = getDb() if len(db.select('userinfo', vars = {'id':session['user_id']}, where = "user_id=$id")) == 0: return output(423) if len(db.select('notice', vars = {'id' : input.activity_id}, where = "notice_id=$id and type='activity'")) == 0: return output(460) try: if len(db.select('apply', vars = {'user_id':session['user_id'], 'activity_id':input.activity_id}, where = "user_id=$user_id and activity_id=$activity_id")) == 0: db.insert('apply' , activity_id = input.activity_id, user_id = session['user_id'], add_time = int(time.mktime(time.localtime()))) except: return output(700) return output(200)
def POST(self): input =web.input(name=None,email = None,address = None,qq=None,phone =None,is_male=None) if input.name==None or input.addresss==None or input.is_male==None: return output(110) try: input.is_male =int(input.is_male) if input.is_male not in (0,1): return output(112) except: return output(111) session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] == 0: return output(410) if input.qq!=None: if not re.compile(r'^[1-9][0-9]+$').match(input.qq) or len(input.qq)>11: return output(112) '''if input.birthday!=None: if not re.compile(r'^[0-9]{4}-(0[1-9])|(1[0-2])-((0[1-9])|([1-2][0-9])|(3[0-1]))$').match(input.birthday): return output(112) date =re.split('-',input.birthday) try: year =int(date[0]) month=int(date[1]) day =int(date[2]) if day ==0: return output(112) except: return output(111) if month in (1,3,5,7,8,10,12): if day>31: return output(112) if month in(4,6,9,11): if day>30: return output(112) if month==2: if year%400==0 or (year%4==0 and year%100!=0): if day>29: return output(112) else: if day>28: return output(112) ''' if input.is_male==1: sex = "male" else: sex = "female" db=getDb() user_id=session['user_id'] try: db.update("userinfo",vars ={"user_id":user_id}, where = "user_id=$user_id", name=input.name,email = input.email, address=input.address, qq=input.qq,phone=input.phone,gender=sex) except: return output(700) return output(200)
def getRequestList(): session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] not in (2, 3): return output(410) team_id = session['team_id'] where = ( "recruit.recruit_id=request.recruit_id and recruit.team_id=$id and " + "request.status='ongoing'") what = ( "request.recruit_id as recruit_id, request.user_id as user_id, " + "request.add_time as add_time, request.status as status," + 'request.request_id as request_id') db = getDb() results = db.select('recruit,request', vars={'id': team_id}, where=where, what=what, order='add_time desc') request_list = [] for i in results: if i.status == 'ongoing': status = 0 elif i.status == 'approved': status = 1 else: status = 2 request_list.append({ 'request_id': i.request_id, 'recruit_id': i.recruit_id, 'user_id': i.user_id, 'status': status, 'add_time': i.add_time }) for i in request_list: userinfo = db.select('userinfo', vars={'id': i['user_id']}, where="user_id=$id", what="name, phone, qq")[0] title = db.select('recruit', vars={'id': i['recruit_id']}, where="recruit_id=$id", what='recruit_title')[0].recruit_title i['title'] = title i['name'] = userinfo.name i['qq'] = userinfo.qq i['phone'] = userinfo.phone return output(200, request_list)
def POST(self): input = web.input(user_id = None) if input.user_id == None: return output(110) try: input.user_id = int(input.user_id) except: return output(111) session = web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type'] != 0: return output(410) db = getDb() myvars = {'id':input.user_id} results = db.select("user",vars=myvars,where = "user_id=$id",what = "type") if len(results) == 0: return output(463) if results[0].type != '1': return output(470) t = db.transaction() try: db.delete('user', vars = myvars, where = "user_id=$id") db.delete("userinfo",vars =myvars,where ="user_id=$id") t.commit() except: t.rollback() return output(700) return output(200)
def POST(self): input = web.input(title=None, recruit_num=None, content=None) #缺少必填参数 if input.title == None or input.recruit_num == None or input.content == None: return output(110) try: recruit_num = int(input.recruit_num) except: return output(111) if recruit_num < 0: return output(112) input.title = input.title.strip() if len(input.title) == 0: return output(112) session = web.ctx.session if not session.has_key('user_id'): return output(411) #负责人的权限才可以 if session['user_type'] not in (2, 3): return output(410) db = getDb() try: db.insert('recruit', recruit_title=input.title, team_id=session['team_id'], recruit_count=recruit_num, content=input.content, add_time=int(time.mktime(time.localtime()))) return output(200) except: return output(700)
def POST(self): input = web.input(is_refresh=0, notice_count=10, last_notice_id=None) try: input.is_refresh = int(input.is_refresh) input.notice_count = int(input.notice_count) if input.last_notice_id != None: input.last_notice_id = int(input.last_notice_id) except: #返回类型错误 状态码 return output(111) if input.is_refresh == 0 and input.last_notice_id == None: #返回缺少必填参数 状态码 return output(110) if input.notice_count <= 0: #返回参数值非法 状态码 return output(112) db = getDb() if input.is_refresh != 0: results = db.select( 'notice', vars={'count': input.notice_count}, where="type='activity'", limit="0, $count", order="add_time desc", what="notice_id, title, add_time", ) else: results = db.select('notice', vars={ 'count': input.notice_count, 'last_id': input.last_notice_id }, where="type='activity' and notice_id<$last_id", limit="0, $count", order="add_time desc,notice_id desc", what="notice_id, title, add_time") notice_list = [] for i in results: notice_list.append({ 'notice_id': i.notice_id, 'title': i.title, 'add_time': i.add_time }) return output(200, notice_list)
def POST(self): # ,传入loginname,password,返回登陆正确的随机单一token值 input = web.input(login_name="", password="") # 是否缺少必要参数 if input.login_name == "" or input.password == "": # TODO: return output(110) # TODO: # 用户名是否合法 # 密码是否合法 if len(input.login_name) > 20 or len(input.password) > 33: # TODO: return output(111) # 用户名是否唯一存在 db = getDb() results = db.select( "campus", vars={"login_name": input.login_name}, where="login_name=$login_name", what="campus_id,passwd" ) # TODO: if len(results) != 1: return output(460) # TODO: # 密码是否正确 results = results[0] if results.passwd != encrypt(input.password): return output(430) # 记下campus_id campus_id_now = results.campus_id # 密码正确,增权限access_token token = db.select("campus_token", vars={"id": results.campus_id}, where="campus_id=$id") if len(token) > 0: # 如果存在token,那就更新token的时间 token = token[0] try: db.update("campus_token", vars={"id": token.campus_id}, where="campus_id=$id", activate_time=None) return output(200, token.access_token) except: return output(700) else: try: while True: # 防止不同用户的token相同 token = encrypt(str(random.randint(100000, 1000000)) + str(time.time()) + input.login_name) results = db.select("campus_token", vars={"token": token}, where="access_token=$token") if len(results) == 0: break db.insert("campus_token", access_token=token, campus_id=campus_id_now, activate_time=None) token1 = [] token1.append({"access_token": token}) return output(200, token1) except: return output(700)
def getPlaceList(): db = getDb() results = db.select('place') place_list = [] for i in results: place_list.append({'id':i.place_id, 'name':i.place_name}) return output(200, place_list)
def getSchoolList(): db = getDb() results = db.select('school') school_list = [] for i in results: school_list.append({'school_id':i.school_id, 'school_name':i.school_name}) return output(200, school_list)
def getFoodList(): db = getDb() results = db.select('goods', order = "good_id desc") school_list = [] for i in results: school_list.append({'good_id':i.good_id, 'good_name':i.good_name, 'price':i.price}) return output(200, school_list)
def getLayoutList(): db = getDb() layout_list = [] results = db.select('layout_one') for i in results: if i.type == 'increment': type = 0 else: type = 1 layout_list.append({'layout_one_id':i.id, 'name':i.name, 'type':type}) for i in layout_list: where = "parent_id=$id and (type='flow' or type='all')" vars = {'id':i['layout_one_id']} results = db.select('layout_two', where = where, vars = vars) sub_list = [] for j in results: if j.type == 'all': type = 0 elif j.type == 'payment': type = 1 else: type = 2 sub_list.append({'layout_two_id':j.id, 'name':j.name, 'type':type}) i['sub_list'] = sub_list return output(200, layout_list)
def getTeamList(): db = getDb() results = db.select('team') team_list = [] for i in results: team_list.append({'team_id':i.team_id, 'team_name':i.team_name}) return output(200, team_list)
def POST(self): # 传入access_token如果正确,那就删掉该token,如果错误,则返回权限不足 input = web.input(access_token="") # 参数不足 if input.access_token == "": return output(110) db = getDb() results = db.select("campus_token", vars={"token": input.access_token}, where="access_token=$token") if len(results) > 0: try: db.delete("campus_token", vars={"token": input.access_token}, where="access_token=$token") return output(200) except: return output(700) else: # 权限不足,不允许删 return output(410)
def POST(self): input = web.input(team_id = None, page_num = None, page_size = None) if input.page_num == None or input.page_size == None: return output(110) try: input.page_num = int(input.page_num) input.page_size = int(input.page_size) if input.team_id != None: input.team_id = int(input.team_id) except: return output(111) if input.page_num <= 0 or input.page_size <= 0: return output(112) session = web.ctx.session if session.has_key('user_type') and (session['user_type'] in (2, 3)): if input.team_id == None: input.team_id = session['team_id'] db = getDb() order = 'add_time desc,recruit_id desc' vars = {'start':(input.page_num - 1) * input.page_size, 'count': input.page_size} limit = "$start,$count" if input.team_id == None: count = db.select('recruit', vars = vars, what = "count(*) as num")[0].num results = db.select('recruit', vars = vars, order = order, limit = limit) else: vars['id'] = input.team_id count = db.select('recruit', vars = vars, where = "team_id=$id", what = "count(*) as num")[0].num results = db.select('recruit', vars = vars, where = 'team_id=$id', order = order, limit = limit) recruit_list = [] for i in results: recruit_list.append({'recruit_id':i.recruit_id, 'title':i.recruit_title, 'team_id':i.team_id, 'recruit_num':i.recruit_count, 'add_time':i.add_time, 'content':i.content}) for i in recruit_list: i['team_name'] = db.select('team', vars = {'id':i['team_id']}, where = "team_id=$id", what = "team_name")[0].team_name return output(200, {'recruit_count': count, 'page_num': input.page_num, 'page_size': input.page_size, 'recruit_list': recruit_list})
def POST(self): # 返回类型:json 、 json[“data”]: null 、 json[“status”]:状态码 input = web.input(mobile=None) if input.mobile == None: return output(110) # status_code["satus_code"]=200 表示用户手机号单独唯一存在。 status_code = Judge.verifyUsernameIsExistAndIsleague(input.mobile) if (status_code["status_code"] != 200): return output(status_code["status_code"]) # 否则返回错误 try: #status_code_message = sendVerifyCode(input.mobile) return output(200) # 处理正确与否,返回。 except: return output(700) # 发送短信失败
def OnButtonLoadButton(self, event): index = self.choiceClassifier.GetSelection() if index < 0: output("No classifier selected!", OUTPUT_ERROR) else: self.idjudge = self.data_cl[index][0] self.judge_class_name = self.data_cl[index][2] self.make_judge() self.textCtrlScores.SetValue(self.judge.get_explanation1()) if self.flag_first_load: self.init_grid() self.flag_first_load = False else: self.read_data() self.fill_grid()
def getSectionList(): session=web.ctx.session if not session.has_key('user_id'): return output(411) if session['user_type']!=0: return output(410) db=getDb() results = db.select('section') sectionList=[] for i in results: sectionList.append({'section_id':i.section_id,'section_name':i.section_name,'view_count':i.view_count}) for i in sectionList: count = db.select('post', vars = {'id':i['section_id']}, where = "section_id=$id", what = 'count(*) as num')[0].num i['post_count'] = count return output(200,sectionList)