Пример #1
0
def _view_diary(request, startdate, enddate, tag=None, extra_title=None):
    # Returns public diary view, for given date range, optionally filtered by
    # an event tag.

    # Build query. The select_related() and prefetch_related on the end
    # encourages it to get the associated showing/event data, to reduce the
    # number of SQL queries
    showings = (Showing.objects.public()
                               .start_in_range(startdate, enddate)
                               .order_by('start')
                               .select_related()
                               .prefetch_related('event__media')
                               .prefetch_related('event__tags'))
    if tag:
        showings = showings.filter(event__tags__slug=tag)

    # Build a list of events for that list of showings:
    events = OrderedDict()
    for showing in showings:
        events.setdefault(showing.event, list()).append(showing)

    context = {
        'start': startdate,
        'end': enddate,
        # Make sure user input is escaped:
        'event_type': mark_for_escaping(tag) if tag else None,
        # Set page title:
        'extra_title': extra_title,
        # Set of Showing objects for date range
        'showings': showings,
        # Ordered dict mapping event -> list of showings:
        'events': events,
        # This is prepended to filepaths from the MediaPaths table to use
        # as a location for images:
        'media_url': settings.MEDIA_URL,
        'printed_programmes': PrintedProgramme.objects.month_in_range(
            startdate, enddate)
    }

    return render(request, 'view_showing_index.html', context)
Пример #2
0
def view_diary(request, year=None, month=None, day=None, event_type=None):
    # Returns public diary view, starting at specified year/month/day, filtered
    # by event type.
    #
    # Returns different things depending on the supplied parameters;
    # - if only year is passed, and no daysahead parameter,listings for the
    #   whole of that year
    # - if only year & month passed, and no daysahead parameter, listings for
    #   the whole of that month
    # - if year, month & day, and no daysahead parameter, listings for that day
    #   only
    # - if dayssahead parameter is passed, that many days from the specified
    #   year/month/date
    context = {}
    query_days_ahead = request.GET.get('daysahead', None)

    # Shared utility method to parse HTTP parameters and return a date range
    startdate, days_ahead = get_date_range(year, month, day, query_days_ahead)
    if startdate is None:
        raise Http404(days_ahead)
    enddate = startdate + datetime.timedelta(days=days_ahead)

    # Start getting together data to send to the template...

    context['today'] = datetime.date.today()
    context['start'] = startdate
    context['end'] = enddate

    # Following is user input passed back, so make doubly sure that it gets
    # escaped in the template:
    context['event_type'] = mark_for_escaping(event_type) if event_type else None

    # Set page title
    if year:
        # If some specific dates were provided, use those
        context['event_list_name'] = u"Cube Programme for {0}".format(
            u"/".join([str(s) for s in (day, month, year) if s])
        )
    else:
        # Default title
        context['event_list_name'] = "Cube Programme"

    # Build query. The select_related() and prefetch_related on the end
    # encourages it to get the associated showing/event data, to reduce the
    # number of SQL queries
    showings = (Showing.objects.public()
                               .start_in_range(startdate, enddate)
                               .order_by('start')
                               .select_related()
                               .prefetch_related('event__media'))
    if event_type:
        showings = showings.filter(event__tags__slug=event_type)

    # Build a list of events for that list of showings:
    events = OrderedDict()
    for showing in showings:
        events.setdefault(showing.event, list()).append(showing)

    context['showings'] = showings  # Set of Showing objects for date range
    context['events'] = events  # Ordered dict mapping event -> list of showings
    # This is prepended to filepaths from the MediaPaths table to use
    # as a location for images:
    context['media_url'] = settings.MEDIA_URL

    context['printed_programmes'] = PrintedProgramme.objects.month_in_range(
        startdate, enddate)

    return render(request, 'view_showing_index.html', context)