Esempio n. 1
0
def top_personalized_recommendations(request):
    user = request.user
    has_location = user.is_authenticated() and user.get_profile().has_location(
    )

    cinema_films = []
    tv_films = []

    today = get_today(request.timezone)
    a_day = datetime.timedelta(days=1)

    key = cache.Key("top_personalized_recommendations", today, request.user)

    films = cache.get(key)
    if films is None:
        cinemas = showtimes_helper.get_theaters(request)
        tvs = showtimes_helper.get_tv_channels(request)

        # How many days ahead we want to check
        PERSONALIZED_CINEMA_DAYS = settings.PERSONALIZED_CINEMA_DAYS
        PERSONALIZED_TV_DAYS = settings.PERSONALIZED_TV_DAYS
        # How many films we want to get
        PERS_CINEMA_NUMBER = settings.PERSONALIZED_CINEMA_FILMS_NUMBER
        PERS_TV_NUMBER = settings.PERSONALIZED_TV_FILMS_NUMBER

        # We get films sorted by personal taste of user
        if cinemas:
            cinema_films = showtimes_helper.collect_unique_films(
                today,
                cinemas,
                PERS_CINEMA_NUMBER,
                settings.PERSONALIZED_CINEMA_DAYS,
                user=user)

        if tvs:
            tv_films = showtimes_helper.collect_unique_films(
                today,
                tvs,
                PERS_TV_NUMBER,
                settings.PERSONALIZED_TV_DAYS,
                user=user)

        films = (cinema_films, tv_films)
        cache.set(key, films)

    (cinema_films, tv_films) = films

    display = (not has_location) | bool(tv_films) | bool(cinema_films)

    return {
        'display': display,
        'has_location': has_location,
        'tv_films': tv_films,
        'cinema_films': cinema_films,
    }
Esempio n. 2
0
def top_personalized_recommendations(request):
    user = request.user
    has_location = user.is_authenticated() and user.get_profile().has_location()
    
    cinema_films = []
    tv_films = []
    
    today = get_today(request.timezone)
    a_day = datetime.timedelta(days=1)

    key = cache.Key("top_personalized_recommendations", today, request.user)

    films = cache.get(key)
    if films is None:
        cinemas = showtimes_helper.get_theaters(request)
        tvs = showtimes_helper.get_tv_channels(request)

        # How many days ahead we want to check
        PERSONALIZED_CINEMA_DAYS = settings.PERSONALIZED_CINEMA_DAYS
        PERSONALIZED_TV_DAYS = settings.PERSONALIZED_TV_DAYS
        # How many films we want to get
        PERS_CINEMA_NUMBER = settings.PERSONALIZED_CINEMA_FILMS_NUMBER
        PERS_TV_NUMBER = settings.PERSONALIZED_TV_FILMS_NUMBER

        # We get films sorted by personal taste of user
        if cinemas:
            cinema_films = showtimes_helper.collect_unique_films(
                    today, cinemas, PERS_CINEMA_NUMBER, 
                    settings.PERSONALIZED_CINEMA_DAYS, user=user)

        if tvs:
            tv_films = showtimes_helper.collect_unique_films(
                    today, tvs, PERS_TV_NUMBER, 
                    settings.PERSONALIZED_TV_DAYS, user=user)
        
        films = (cinema_films, tv_films)
        cache.set(key, films)
    
    (cinema_films, tv_films) = films

    display = (not has_location) | bool(tv_films) | bool(cinema_films)

    return {
        'display': display,
        'has_location': has_location,
        'tv_films': tv_films,
        'cinema_films': cinema_films,
    }
Esempio n. 3
0
def top_recommendations_cinema(context, films_number=4):
    """
        Displays user's top recommended movies in cinemas
        (most popular for not logged in).
    """

    request = context['request']
    user = request.user

    key = cache.Key("cinema_user_recommended", user)
    films = cache.get(key)
    if films is None:
        channels = get_theaters(request)
        now = get_today(request.timezone)
        films = collect_unique_films(now, channels, films_number, days=3, user=user)
        cache.set(key, films)
    return films
Esempio n. 4
0
def top_recommendations_cinema(context, films_number=4):
    """
        Displays user's top recommended movies in cinemas
        (most popular for not logged in).
    """

    request = context['request']
    user = context.get('recommendations_user', context['request'].user)

    key = cache.Key("cinema_user_recommended", user)
    films = cache.get(key)
    if films is None:
        channels = get_theaters(request)
        now = get_today(request.timezone)
        films = collect_unique_films(now,
                                     channels,
                                     films_number,
                                     days=3,
                                     user=user)
        cache.set(key, films)
    return films