Exemple #1
0
def people(request, did):
    if not did:
        return HttpResponseRedirect("/")
    query = DUser.objects(uid=did)
    people = None
    if query:
        people = query[0]
    else:
        #TODO remove
        url = ApiOperation.apiGenerator('USER', did)
        api = Api(url=url, api_type='USER', api_id=did)
        processor = UserProcessor(api)
        result = processor.getUser()
        if result:
            people = result
        else:
            return HttpResponseRedirect("/")
        #TODO end
    if people.content and people.content.find('\n') != -1:
        people.content = people.content.split('\n')
    people.image_link = people.image_link.replace('icon/u', 'icon/ul')
    
    try:
        follower = UserProfile.objects.get(did=did).user
    except:
        error_message = "抱歉,该用户还没有注册本网站..."
        return render_to_response('error.html', {'error':error_message,
                'redirect_url':'/people/follow/'},
                context_instance=RequestContext(request))
        
    followed = len(FollowRelation.objects.filter(user=request.user, follower=follower)) > 0
    return render_to_response('people/people.html', 
            {'people': people, 'followed': followed},
            context_instance=RequestContext(request))
Exemple #2
0
 def test_getUserContacts(self):
     api = Api(url='http://api.douban.com/people/klb-3713/contacts?start-index=1&max-results=50', api_id='klb-3713', api_type='USER')
     process = UserProcessor(api)
     result = process.getUserContacts()
     self.assertIsNotNone(result)