Exemplo n.º 1
0
def get_storefront_most_popular(request_profile,
                                pre_fetch=True,
                                ordering=None):
    """
    Get Most Popular Listings for storefront
    """
    username = request_profile.user.username
    # Get most popular listings via a weighted average
    most_popular_listings_raw = models.Listing.objects.for_user_organization_minus_security_markings(
        username).filter(approval_status=models.Listing.APPROVED,
                         is_enabled=True,
                         is_deleted=False).order_by('-avg_rate',
                                                    '-total_reviews')

    most_popular_listings = pipeline.Pipeline(
        recommend_utils.ListIterator(
            [listing for listing in most_popular_listings_raw]), [
                pipes.ListingPostSecurityMarkingCheckPipe(username),
                pipes.LimitPipe(36)
            ]).to_list()

    sorted_most_popular_listings = custom_sort_listings(
        most_popular_listings, ordering)

    return sorted_most_popular_listings
Exemplo n.º 2
0
def get_storefront_recent(request_profile, pre_fetch=True):
    """
    Get Recent Listings for storefront
    """
    username = request_profile.user.username
    # Get Recent Listings
    recent_listings_raw = models.Listing.objects.for_user_organization_minus_security_markings(
        username).order_by('-approved_date').filter(
        approval_status=models.Listing.APPROVED,
        is_enabled=True,
        is_deleted=False)

    recent_listings = pipeline.Pipeline(recommend_utils.ListIterator([listing for listing in recent_listings_raw]),
                                        [pipes.ListingPostSecurityMarkingCheckPipe(username),
                                         pipes.LimitPipe(24)]).to_list()
    return recent_listings
Exemplo n.º 3
0
def get_storefront_featured(request_profile, pre_fetch=True):
    """
    Get Featured Listings for storefront
    """
    username = request_profile.user.username
    # Get Featured Listings
    featured_listings_raw = models.Listing.objects.for_user_organization_minus_security_markings(
        username).filter(
        is_featured=True,
        approval_status=models.Listing.APPROVED,
        is_enabled=True,
        is_deleted=False).order_by(F('featured_date').desc(nulls_last=True))

    featured_listings = pipeline.Pipeline(recommend_utils.ListIterator([listing for listing in featured_listings_raw]),
                                          [pipes.ListingPostSecurityMarkingCheckPipe(username)]).to_list()
    return featured_listings
Exemplo n.º 4
0
    def _get_recommended_listings(self):
        profile_username = self.profile_instance.user.username

        # Post security_marking check - lazy loading
        pipeline_list = [
            pipes.ListingPostSecurityMarkingCheckPipe(profile_username),
            pipes.LimitPipe(10)
        ]

        if self.randomize_recommended:
            pipeline_list.insert(0, pipes.JitterPipe())

        recommended_listings_iterator = recommend_utils.ListIterator(
            self.recommended_listings_raw)
        self.recommended_listings = pipeline.Pipeline(
            recommended_listings_iterator, pipeline_list).to_list()
        self.recommended_listings_ids = [
            listing.id for listing in self.recommended_listings
        ]
Exemplo n.º 5
0
def get_storefront_featured(username, pre_fetch=True):
    """
    Get Featured Listings for storefront
    """
    # Get Featured Listings
    featured_listings_raw = models.Listing.objects.for_user_organization_minus_security_markings(
        username).filter(is_featured=True,
                         approval_status=models.Listing.APPROVED,
                         is_enabled=True,
                         is_deleted=False)

    if pre_fetch:
        featured_listings_raw = listing_serializers.ListingSerializer.setup_eager_loading(
            featured_listings_raw)

    featured_listings = pipeline.Pipeline(
        recommend_utils.ListIterator(
            [listing for listing in featured_listings_raw]),
        [pipes.ListingPostSecurityMarkingCheckPipe(username)]).to_list()
    return featured_listings
Exemplo n.º 6
0
def get_storefront_most_popular(username, pre_fetch=True):
    """
    Get Most Popular Listings for storefront
    """
    # Get most popular listings via a weighted average
    most_popular_listings_raw = models.Listing.objects.for_user_organization_minus_security_markings(
        username).filter(approval_status=models.Listing.APPROVED,
                         is_enabled=True,
                         is_deleted=False).order_by('-avg_rate',
                                                    '-total_reviews')

    if pre_fetch:
        most_popular_listings_raw = listing_serializers.ListingSerializer.setup_eager_loading(
            most_popular_listings_raw)

    most_popular_listings = pipeline.Pipeline(
        recommend_utils.ListIterator(
            [listing for listing in most_popular_listings_raw]), [
                pipes.ListingPostSecurityMarkingCheckPipe(username),
                pipes.LimitPipe(36)
            ]).to_list()
    return most_popular_listings
Exemplo n.º 7
0
def get_storefront_recommended(username, pre_fetch=True):
    """
    Get Recommended Listings for storefront
    """
    extra_data = {}

    profile = models.Profile.objects.get(user__username=username)

    if not profile.is_beta_user():
        return [], extra_data

    # Retrieve List of Recommended Apps for profile:
    listing_ids_list, recommended_entry_data = get_recommendation_listing_ids(
        profile)
    extra_data['recommended_entry_data'] = recommended_entry_data

    # Retrieve Profile Bookmarks and remove bookmarked from recommendation list
    bookmarked_apps_list = set([
        application_library_entry.listing.id for application_library_entry in
        models.ApplicationLibraryEntry.objects.for_user(username)
    ])

    listing_ids_list_temp = []

    for current_listing_id in listing_ids_list:
        if current_listing_id not in bookmarked_apps_list:
            listing_ids_list_temp.append(current_listing_id)

    listing_ids_list = listing_ids_list_temp

    # Send new recommendation list minus bookmarked apps to User Interface
    recommended_listings_queryset = models.Listing.objects.for_user_organization_minus_security_markings(
        username).filter(pk__in=listing_ids_list,
                         approval_status=models.Listing.APPROVED,
                         is_enabled=True,
                         is_deleted=False).all()

    if pre_fetch:
        recommended_listings_queryset = listing_serializers.ListingSerializer.setup_eager_loading(
            recommended_listings_queryset)

    # Fix Order of Recommendations
    id_recommended_object_mapper = {}
    for recommendation_entry in recommended_listings_queryset:
        id_recommended_object_mapper[
            recommendation_entry.id] = recommendation_entry

    # recommended_listings_raw = [id_recommended_object_mapper[listing_id] for listing_id in listing_ids_list]

    recommended_listings_raw = []

    for listing_id in listing_ids_list:
        if listing_id in id_recommended_object_mapper:
            recommended_listings_raw.append(
                id_recommended_object_mapper[listing_id])

    # Post security_marking check - lazy loading
    recommended_listings = pipeline.Pipeline(
        recommend_utils.ListIterator([
            recommendations_listing
            for recommendations_listing in recommended_listings_raw
        ]), [
            pipes.JitterPipe(),
            pipes.ListingPostSecurityMarkingCheckPipe(username),
            pipes.LimitPipe(10)
        ]).to_list()

    return recommended_listings, extra_data