def is_exist_in_request(method,key): '''判断指定键是否存在与指定的请求数据中 ''' if key in method: writelog('Func Name:is_exist_in_request;%s in %s.' % (key,method,)) return True return False
def insertState(self, url, state=""): if not state: state = self.getState(url) cur = self._conn.cursor() sql = "INSERT State(state, url) values(%s, %s)" try: if cur.execute(sql, (state, url)) == 1: self._conn.commit() return True return False except IntegrityError, e: from tools.log import writelog import traceback writelog(e) writelog(traceback.format_exc()) self._conn.rollback() return False
def user_reg_post(request): if all_in_request(request.POST,('fname','lname','appe','email','password','idcard','mphone',)): _first_name = request.POST['fname'] _last_name = request.POST['lname'] _password = request.POST['password'] _appellation = request.POST['appe'] _email = request.POST['email'] _id_no = request.POST['idcard'] _mobile_phone = request.POST['mphone'] # validate user's info if that exist has_exist_any = Users.objects.exist_any(_email,_id_no,_mobile_phone) if not has_exist_any: #make a md5 password _password = _makemd5(_password) #make md5 END #init a new user obj new_user = Users( first_name=_first_name, last_name=_last_name, password=_password, appellation=_appellation, email=_email, id_no=_id_no, mobile_phone=_mobile_phone) # init new user obj END try: # try to save new user obj new_user.save() #record session set_session(request,'user_id',new_user.id) #向客户端响应包含新用户姓氏,称谓以及ID的HTML代码 return render_to_response( 'user/reg_success.html',{ 'U_FIRST_NAME':new_user.first_name, 'U_APPELLATION':new_user.appellation, 'U_ID':new_user.id } ) except Exception: import sys ex = sys.exc_info()[2].tb_frame.f_back writelog('**Exception:%s on line %s' %(ex.f_code.co_name,ex.f_lineno,)) return render_error_page( err_action='我们在提交注册申请时', err_msg=( '服务器访问量太大,暂时无法响应您的请求。', ), other_options=[('回到打杂兔网站首页','/',),('挺稍后再尝试注册','/user/reg/',)] ) else: return render_error_page( err_action='我们在提交注册申请时', err_msg=( '您提交的电子邮箱已经被注册。', '您提交的身份证件号码已经被注册。', '您提交的手机号码已经被注册。', ), other_options=[('回到打杂兔网站首页','/',),('重新注册','/user/reg/',)] ) else: return render_error_page( '您在访问本页时', ('您没有使用正确的浏览方式访问本页。',), [('回到打杂兔网站首页','/',)])