def dehydrate(self, bundle): bundle.data['distance'] = calculate_distance(bundle.request.user.id, bundle.obj.id) bundle.data['mutual_friends'] = \ len(Friend.objects.mutual_friends(bundle.request.user.id, bundle.obj.id)) bundle.data['age'] = calculate_age(bundle.data['date_of_birth']) # TODO chane user_id to url from user_id bundle.data['twitter_provider'], bundle.data['linkedin_provider'], \ bundle.data['twitter_username'], bundle.data['linkedin_first_name'] = \ social_extra_data(bundle.request.user.id) if bundle.obj.id != bundle.request.user.id: bundle.data['match_score'] = MatchEngine.objects. \ count_common_goals_and_offers(bundle.obj.id, bundle.request.user.id) else: bundle.data['match_score'] = 0 bundle.data['position'] = get_current_position(bundle.obj) bundle.data['lives_in'] = get_lives_in(bundle.obj) bundle.data['religious_views'] = get_religious_views( bundle.request.user.id) bundle.data['political_views'] = get_political_views( bundle.request.user.id) bundle.data['image'] = FacebookPhoto.objects.profile_photo( bundle.obj.id) return bundle
def dehydrate(self, bundle): raw_data = {} user_id = bundle.obj.id # if bundle.obj.raw_data: # raw_data = json.loads(bundle.obj.raw_data) bundle.data['position'] = get_current_position(bundle.obj) bundle.data['lives_in'] = get_lives_in(bundle.obj) bundle.data.update(raw_data) bundle.data['goals_count'] = Goal.objects.filter( user_id=user_id).count() bundle.data['offers_count'] = Offer.objects.\ filter(user_id=user_id).count() bundle.data['interest_count'] = Interest.objects.\ filter(user=user_id).count() return bundle
def __init__(self, current_user_id, user_object, include_top_interests=True): self.user = self.get_user_info(user_object) self.current_user_id = current_user_id self.goals = self.highlight(user_object, 'goals') self.offers = self.highlight(user_object, 'offers') self.interests = self.highlight(user_object, 'interests') self.likes = self.likes_images(user_object) self.id = self.user.id self.user_id = self.user.id self.username = self.user.username self.first_name = self.user.first_name self.last_name = self.user.last_name self.facebook_id = self.user.facebook_id self.image = self.get_profile_image(user_object) or \ '/media/{}'.format(self.user.image) self.age = calculate_age(self.user.date_of_birth) self.gender = self.user.gender or 'm,f' self.about = self.user.about_me self.photos = [] self.distance = calculate_distance_es(current_user_id, user_object) self.seen = self.get_seen(current_user_id, user_object) # Scores self.score = self.match_score(current_user_id, self.user_id) self.es_score = user_object.get('_score', 0) self.mutual_likes_count = self.fb_likes_match_score( current_user_id, self.user_id) self.total_likes_count = self.total_fb_likes_count(self.user_id) self.friends_score = self.get_friends_score(current_user_id, user_object) self.top_interests = \ self.get_top_interests(user_object) if include_top_interests else [] self.last_login = self.user.last_login self.keywords = None # self.get_keywords(user_object) self.position = get_current_position(self.user) self.lives_in = get_lives_in(self.user) self.linkedin_provider = self.get_linkedin_data() self.twitter_username, self.twitter_provider = self.get_twitter_data() self.connected = self.is_connected(current_user_id, self.user_id)
def __init__(self, current_user_id, user_id): self.user = FacebookCustomUserActive.objects.get(pk=user_id) self.current_user_id = current_user_id self.id = self.user.id self.user_id = self.user.id self.username = self.user.username self.score = 0 self.first_name = self.user.first_name self.last_name = self.user.last_name self.facebook_id = self.user.facebook_id self.image = FacebookPhoto.objects.profile_photo( user_id) or '/media/{}'.format(self.user.image) self.age = calculate_age(self.user.date_of_birth) self.gender = self.user.gender or 'm,f' self.about = self.user.about_me self.last_login = self.user.last_login self.position = get_current_position(self.user) self.lives_in = get_lives_in(self.user) self.linkedin_provider = self.get_linkedin_data() self.twitter_username, self.twitter_provider = self.get_twitter_data() self.connected = self.is_connected(current_user_id, user_id) self.top_interests = self.get_top_interests( self.get_user_object(user_id))
def dehydrate_distance(self, bundle): if bundle.data['distance']: bundle.data['distance'] = [intcomma(bundle.data['distance'][0]), bundle.data['distance'][1]] bundle.data['position'] = get_current_position(bundle.data['id']) return bundle.data['distance']
def test_empty_position(self): position = get_current_position(self.user2) self.assertIsNone(position.get('job')) self.assertIsNone(position.get('company'))
def test_simple_facebook_position(self): position = get_current_position(self.user1) self.assertEqual(position.get('job'), u'Software Engineer') self.assertEqual(position.get('company'), u'Wargaming.net')
def test_simple_linkedin_position(self): position = get_current_position(self.user) self.assertEqual(position.get('job'), u'Software Engineer') self.assertEqual(position.get('company'), u'Toptal')