def get_object_list(self, request): friends = Friend.objects.friends(request.user.id) results = [] for friend in friends: new_obj = ResourseObject() if friend.friend1.pk == request.user.id: position_friend = 'friend2' else: position_friend = 'friend1' new_obj.id = friend.id new_obj.friend_id = getattr(friend, position_friend).id new_obj.first_name = getattr(friend, position_friend).first_name new_obj.facebook_id = getattr(friend, position_friend).facebook_id new_obj.image = getattr(friend, position_friend).image new_obj.age = calculate_age( getattr(friend, position_friend).date_of_birth) new_obj.tag_line = 'tagline for my connection' new_obj.events = [model_to_dict(m) for m in Membership.objects.filter( user_id=getattr(friend, position_friend).id)] first_name = request.GET.get('first_name') if first_name: if first_name in new_obj.first_name.lower(): results.append(new_obj) else: continue else: results.append(new_obj) return results
def build_organizer(event): if event.organizer: return { 'name': event.organizer.facebook_name, 'image': get_attendee_photo(event.organizer), 'username': event.organizer.username, 'age': calculate_age(event.organizer.date_of_birth), 'gender': event.organizer.gender, 'about_me': event.organizer.about_me, 'link': 'https://persice.com/{}/'.format(event.organizer.username) } else: fb_event = FacebookEvent.objects.filter(facebook_id=event.eid).first() return { 'name': fb_event.owner_info.get('name'), 'image': None, 'link': 'https://www.facebook.com/{}/'.format( fb_event.owner_info.get('id')), 'username': None, 'age': None, 'gender': None, 'about_me': None }
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 __init__(self, current_user_id, user_id2): self.current_user_id = FacebookCustomUserActive.objects.get( pk=current_user_id) self.user = FacebookCustomUserActive.objects.get(pk=user_id2) self.goals = self._add(Goal, 'goal') self.offers = self._add(Offer, 'offer') self.interests = self._add(Interest, 'interest') self.likes = self._add(FacebookLike, 'name') self.id = self.user.id self.user_id = self.user.id self.first_name = self.user.first_name self.last_name = self.user.last_name self.shared_interest = ['dancing', 'cooking', '3D printing'] self.facebook_id = self.user.facebook_id self.image = 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.twitter_provider, self.linkedin_provider, self.twitter_username = \ social_extra_data(self.user.id) self.distance = calculate_distance(current_user_id, user_id2) self.score = MatchEngine.objects.count_common_goals_and_offers( current_user_id, user_id2) self.friends_score = len(Friend.objects.mutual_friends(current_user_id, user_id2)) + \ len(FacebookFriendUser.objects.mutual_friends(current_user_id, user_id2))
def persice_organizer(user): return { 'name': user.facebook_name, 'image': get_attendee_photo(user), 'username': user.username, 'age': calculate_age(user.date_of_birth), 'gender': user.gender, 'about_me': user.about_me, 'link': None }
def dehydrate(self, bundle): bundle.data['username'] = bundle.obj.user.username bundle.data['first_name'] = bundle.obj.user.first_name bundle.data['facebook_id'] = bundle.obj.user.facebook_id bundle.data['image'] = FacebookPhoto.objects.profile_photo( bundle.obj.user.id ) bundle.data['age'] = calculate_age(bundle.obj.user.date_of_birth) bundle.data['total_mutual_friends'] = 0 bundle.data['mutual_match_score'] = 0 bundle.data['tagline'] = 'tagline for my connection' bundle.data['is_connection'] = Friend.objects. \ checking_friendship(bundle.obj.user.id, bundle.request.user.id) 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 prepare_age(self, obj): return calculate_age(obj.date_of_birth)