def register(request): if request.method == 'GET': return render_to_response('register.html',{"register":True},context_instance=RequestContext(request)) if request.method == 'POST': nick = request.POST.get('nick','').strip() email = request.POST.get('email','').strip() password = request.POST.get('password','').strip() error = {} if not nick: error['nick'] = '昵称未填写,酷炫的名字在旅行中能更快结伴哦' if not email: error['email'] = '邮箱未填写,常用邮箱全面掌握行程动态' if email and '@' not in email: error['email'] = '邮箱格式不正确' if len(password)<8: error['password'] = '******' if error: return render_to_response('register.html',{'registererror':error,"register":True},context_instance=RequestContext(request)) if Visitor.objects.filter(name=nick).exists(): error['nick'] = '已经被使用' return render_to_response('register.html',{'registererror':error,"register":True},context_instance=RequestContext(request)) if Visitor.objects.filter(email=email).exists(): error['email'] = '已经被使用' return render_to_response('register.html',{'registererror':error,"register":True},context_instance=RequestContext(request)) visitor = Visitor(name=nick,email=email) visitor.set_password(password) visitor.save() return redirect('/')
def create_visitor(ip_address, session_key): """ Create the visitor given an ip_address """ g = GeoIP() country = g.country_name(ip_address) visitor = Visitor() visitor.generate_key(ip_address) visitor.save_country(country) visitor.mark_visit() visitor.last_session_key = session_key visitor.save() return visitor
def create_visitor(ip_address, session_key): """ Create the visitor given an ip_address """ visitor = Visitor() visitor.generate_key(ip_address) visitor.mark_visit() visitor.last_session_key = session_key visitor.save() return visitor
def test_unicode_on_saved_visitor(self): # Given: An instance of Visitor that has not been saved to the db session_key = 'hijklmnop' visitor = Visitor(visitor_key='abcdefg', last_session_key=session_key) visitor.save() self.assertNotEqual(visitor.id, None) # When: calling the __unicode__ method on visitor result = unicode(visitor) # Then: the expected result is a unicode type object self.assertTrue(isinstance(result, unicode)) # Then: the expected result is returned expected_result = u'#{id}/{session_key}'.format( id=visitor.id, session_key=session_key) self.assertEqual(result, expected_result)
def test_unicode_on_saved_visitor(self): # Given: An instance of Visitor that has not been saved to the db session_key = 'hijklmnop' visitor = Visitor( visitor_key = 'abcdefg', last_session_key = session_key ) visitor.save() self.assertNotEqual(visitor.id, None) # When: calling the __unicode__ method on visitor result = unicode(visitor) # Then: the expected result is a unicode type object self.assertTrue(isinstance(result, unicode)) # Then: the expected result is returned expected_result = u'#{id}/{session_key}'.format(id=visitor.id, session_key=session_key) self.assertEqual(result, expected_result)
def create_visitor(visitor_key, session_key): """ Create the visitor given an ip_address """ visitor = Visitor.objects.filter(visitor_key=visitor_key).last() if visitor: visitor.mark_visit() visitor.save() return visitor visitor = Visitor() visitor.visitor_key = visitor_key visitor.mark_visit() visitor.last_session_key = session_key visitor.save() return visitor