def delete_user(idnumber): this_user = getuser(idnumber) if this_user == None: return False else: this_user.delete() return True
def create_user(info_dict): this_user = getuser(info_dict['idnumber']) if this_user == None: new_user = Basic_info(idnumber=info_dict['idnumber'], name=info_dict['name'], department=info_dict['department'], identifies=info_dict['identifies'], sex=info_dict['sex'], validdate=info_dict['validdate']) new_user.save() return True else: return False
def update_validdate(idnumber, new_end_date): this_user = getuser(idnumber) if this_user == None: return False else: old_start_date = this_user.validdate[0:8] new_validdate = old_start_date + '-' + new_end_date this_user.validdate = new_validdate this_user.save() return True
def regainmoney(request): response = '' request.encoding='utf-8' info_dict = request.GET if 'idnumber' in info_dict: this_user = getuser(int(info_dict['idnumber'])) if this_user == None: response = 'F' else: user_money = this_user.money response = 'S ' + str(user_money) else: response = 'F' return HttpResponse("<p>" + response + "</p>")
def refreshcard(request): response = '' request.encoding='utf-8' info_dict = request.GET if 'newdate' in info_dict and 'idnumber' in info_dict: flag = update_validdate(int(info_dict['idnumber']), info_dict['newdate']) if flag: this_user = getuser(int(info_dict['idnumber'])) old_start_date = this_user.validdate response = 'S ' + old_start_date else: response = 'F' else: response = 'F' return HttpResponse("<p>" + response + "</p>")
def consumemoney(request): response = '' request.encoding='utf-8' info_dict = request.GET if 'idnumber' in info_dict and 'charge' in info_dict: this_user = getuser(int(info_dict['idnumber'])) if this_user == None: response = 'F' else: new_money = this_user.money - int(info_dict['charge']) if new_money < 0: response = 'F' print('没钱了!!!') else: this_user.money = new_money this_user.save() response = 'Success' else: response = 'F' return HttpResponse("<p>" + response + "</p>")
def renewcard(request): response = '' request.encoding='utf-8' info_dict = request.GET if 'idnumber' in info_dict: this_user = getuser(int(info_dict['idnumber'])) if this_user == None: response = 'F' else: new_dict = {} new_dict['name'] = this_user.name new_dict['sex'] = this_user.sex new_dict['identifies'] = this_user.identifies new_dict['department'] = this_user.department new_dict['idnumber'] = this_user.idnumber new_dict['validdate'] = this_user.validdate string_to_send = json.dumps(new_dict) response = 'S ' + string_to_send else: response = 'F' return HttpResponse("<p>" + response + "</p>")
def create_from_sql(idnumber): this_user = getuser(idnumber) if this_user == None: return False else: write_name(this_user.name) #BLOCK5 write_sex(int(this_user.sex)) write_type(int(this_user.identifies)) write_department(this_user.department) #BLOCK6 write_ID(this_user.idnumber) write_block(ser, key, BLOCK5, 5) write_block(ser, key, BLOCK6, 6) b5 = read_block(ser, key, 5) b6 = read_block(ser, key, 6) operate_end(ser) print(check_info(b5, 5)) print(check_info(b6, 6)) return True