コード例 #1
0
ファイル: friends.py プロジェクト: harshgoyal1/demo_Azure
 def post(self):
     logger.log_python_api_post(FriendsResource.api_url)
     friend_id = request.json['friend_id']
     query = Friend.select().where(Friend.user == current_user.id,
                                   Friend.friend == friend_id)
     if not query.exists():
         data = {'user': current_user.id, 'friend': friend_id}
         Friend.create(**data)
     return friend_id, 201
コード例 #2
0
    def get(self):
        logger.log_python_api_get(SuggestedProfilesResource.api_url)
        current_user_profile = Profile.get(id=current_user.id)
        skills_list = safe_split_strip_remove_empty(
            current_user_profile.skills)
        location_part_list = safe_split_strip_remove_empty(
            current_user_profile.location)
        position_title_list = [p.title for p in current_user_profile.positions]

        clauses = [Profile.id != current_user.id]

        or_clauses = []
        for skill in skills_list:
            or_clauses.append(Profile.skills.contains(skill))
        for location_part in location_part_list:
            or_clauses.append(Profile.location.contains(location_part))
        if any(position_title_list):
            subquery = Position.select(Param('1')).where(
                Position.profile == Profile.id,
                Position.title << position_title_list)
            or_clauses.append(Clause(SQL('EXISTS'), subquery))
        if any(or_clauses):
            clauses.append(reduce(operator.or_, or_clauses))

        friends = Friend.select(
            Friend.friend).where(Friend.user == current_user.id).execute()
        clauses.append(~(Profile.id << [f.friend.id for f in friends]))

        profiles = Profile.select().where(reduce(
            operator.and_, clauses)).order_by(fn.Rand()).limit(100)
        for profile in profiles:
            profile.score = 0
            for skill in skills_list:
                if profile.skills and skill in profile.skills:
                    profile.score += 10
            for part in location_part_list:
                if profile.location and part in profile.location:
                    profile.score += 10
            if any(position_title_list):
                profile.position_fetch = profile.positions.execute()
                for position_title in position_title_list:
                    if any(position.title == position_title
                           for position in profile.position_fetch):
                        profile.score += 10

        suggested_profiles = sorted(profiles,
                                    key=lambda profile: -profile.score)[:2]

        return list(map(lambda p: self.profile_to_dict(p), suggested_profiles))
コード例 #3
0
ファイル: friends.py プロジェクト: harshgoyal1/demo_Azure
 def get(self):
     logger.log_python_api_get(FriendsResource.api_url)
     friends = Friend.select(
         Friend.friend).where(Friend.user == current_user.id)
     return list(map(lambda f: f.friend.id, friends))