def showtimes_menu(context): request = context['request'] channel = context.get('channel') return { 'menu_channels': showtimes_helper.get_tv_channels(request), 'channel': channel, }
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, }
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, }
def film_tv_screenings(request, film=None): user = request.user film = film or get_object_or_404(Film, id=request.GET.get('film_id')) today = get_today(request.timezone) days = [] channels = get_tv_channels(request) for n, name in enumerate((_("Today"), _("Tomorrow"), _("Day After Tomorrow"))): date = today + datetime.timedelta(days=n) screening_set = ScreeningSet(date, channels) playing = screening_set.get_channels(film.id) if playing: days.append({'name':name, 'channels':playing}) return { 'film':film, 'days':days, }
def film_tv_screenings(request, film=None): user = request.user film = film or get_object_or_404(Film, id=request.GET.get('film_id')) today = get_today(request.timezone) days = [] channels = get_tv_channels(request) for n, name in enumerate( (_("Today"), _("Tomorrow"), _("Day After Tomorrow"))): date = today + datetime.timedelta(days=n) screening_set = ScreeningSet(date, channels) playing = screening_set.get_channels(film.id) if playing: days.append({'name': name, 'channels': playing}) return { 'film': film, 'days': days, }
def top_recommendations_tv(context, films_number=4): """ Displays user's top recommended movies in tv (most popular for not logged in). """ request = context['request'] user = request.user key = cache.Key("tv_user_recommended", user) films = cache.get(key) if films is None: channels = get_tv_channels(request) now = get_today(request.timezone) films = collect_unique_films(now, channels, films_number, days=3, user=user) cache.set(key, films) return films
def top_recommendations_tv(context, films_number=4): """ Displays user's top recommended movies in tv (most popular for not logged in). """ request = context['request'] user = context.get('recommendations_user', request.user) key = cache.Key("tv_user_recommended", user) films = cache.get(key) if films is None: channels = get_tv_channels(request) now = get_today(request.timezone) films = collect_unique_films(now, channels, films_number, days=3, user=user) cache.set(key, films) return films
def showtimes_menu(context): request = context['request'] return {'menu_channels': showtimes_helper.get_tv_channels(request)}