예제 #1
0
파일: views.py 프로젝트: hungerr/tour
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('/')
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
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