Ejemplo n.º 1
0
    def send_recommendations(self, user, type_label, date, days):
        from film20.showtimes.showtimes_helper import ScreeningSet

        cinemas = Channel.objects.selected_by(user, Channel.TYPE_CINEMA)
        tv = Channel.objects.selected_by(user, Channel.TYPE_TV_CHANNEL)

        to_date = date + datetime.timedelta(days=days)

        cinema_films = ScreeningSet(
            date, cinemas, user=user, days=days,
            without_unmatched=True).get_recommendations()
        tv_films = ScreeningSet(date,
                                tv,
                                user=user,
                                days=days,
                                without_unmatched=True).get_recommendations()

        if not cinema_films and not tv_films:
            logger.debug("no showtimes for %s found (at %s), skipping", user,
                         user.get_profile().location)
            return

        def limit(films):
            out = []
            for f in films:
                if f.on_wishlist and len(
                        out
                ) < settings.WEEKLY_RECOMMENDATIONS_MAX_NUMBER_OF_FILMS:
                    out.append(f)
                elif len(
                        out) < settings.WEEKLY_RECOMMENDATIONS_NUMBER_OF_FILMS:
                    out.append(f)
                else:
                    break
            return out

        from film20.notification.models import send

        context = dict(
            cinema_films=limit(cinema_films),
            tv_films=limit(tv_films),
            tv_channels=tv,
            cinemas=cinemas,
            date=date,
            to_date=to_date,
            days=days,
            user=user,
        )

        template = EmailTemplate.objects.get_template(
            7 if self.opts.get('weekly') else 1)
        if template:
            logger.info("using template: %s" % template)
            context['template'] = template.generate(context)

        if not self.opts.get('test'):
            send([user], type_label, context, now=True)
        else:
            logger.info('test mode, not sending')
Ejemplo n.º 2
0
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,
    }
Ejemplo n.º 3
0
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,
    }
Ejemplo n.º 4
0
def film_cinema_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 = []
    towns = ()

    MAX_NUMBER_OF_SCREENINGS = getattr(settings, 'MAX_NUMBER_OF_SCREENINGS', 8)

    channels = get_theaters(request) or ()

    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,
        'towns_playing': towns,
    }
Ejemplo n.º 5
0
def film_cinema_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 = []
    towns = ()

    MAX_NUMBER_OF_SCREENINGS = getattr(settings, 'MAX_NUMBER_OF_SCREENINGS', 8)

    channels = get_theaters(request) or ()

    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,
        'towns_playing': towns,
    }