示例#1
0
def archive_index(request, *args, **kwargs):
    """
    Generic top-level paginatable archive of date-based objects.

    Templates: ``<app_label>/<model_name>_archive.html``
    Context:
        date_list
            List of years
        latest
            Latest N (defaults to 15) objects by date
    """
    NUM_LATEST = 15
    # Create context for `date_based.archive_index`
    extra_context = kwargs.get('extra_context', {})
    extra_context.update({
        'date_list': kwargs['queryset'].dates(kwargs['date_field'], 'year')[::-1],
        # add `latest` for make it handy.
        # Notice:
        #  set `latest` to `template_object_name` doesn't work as expect
        #  see  http://docs.djangoproject.com/en/1.2/ref/generic-views/
        'latest': kwargs['queryset'][:kwargs.get('num_latest', NUM_LATEST)],
    })
    kwargs['extra_context'] = extra_context
    kwargs = _remove_surplus_kwargs(kwargs)
    return object_list(request, *args, **kwargs)
示例#2
0
def archive_day(request, *args, **kwargs):
    """
    Generic paginatable daily archive view.

    Templates: ``<app_label>/<model_name>_archive_day.html``
    Context:
        object_list:
            list of objects published that day
        day:
            (datetime) the day
        previous_day
            (datetime) the previous day
        next_day
            (datetime) the next day, or None if the current day is today
    """
    # Calculate day with current time
    day = datetime.date(int(kwargs['year']), int(kwargs['month']), int(kwargs['day']))
    if day >= datetime.date.today():
        next_day = None
    else:
        next_day = day + relativedelta(days=1)
    previous_day = day - relativedelta(days=1)
    # Create context for `date_based.archive_index`
    extra_context = kwargs.get('extra_context', {})
    extra_context.update({
        'day': day,
        'next_day': next_day,
        'previous_day': previous_day,
    })
    kwargs = _remove_surplus_kwargs(kwargs)
    return object_list(request, *args, **kwargs)
示例#3
0
def archive_week(request, *args, **kwargs):
    """
    Generic paginatable weekly archive view.

    Templates: ``<app_label>/<model_name>_archive_week.html``
    Context:
        week:
            (date) this week
        object_list:
            list of objects published in the given week
    
    WARNING:
        this method doesn't work yet.
    """
    # TODO: Code it
    import warnings
    warnings.warn(u"'archive_week' method has not coded yet.")
    kwargs = _remove_surplus_kwargs(kwargs)
    return object_list(request, *args, **kwargs)
示例#4
0
def archive_year(request, *args, **kwargs):
    """
    Generic paginatable yearly archive view.

    Templates: ``<app_label>/<model_name>_archive_year.html``
    Context:
        date_list
            List of months in this year with objects
        year
            This year
        object_list
            List of objects published in the given month
            (Only available if make_object_list argument is True)
    """
    # Create context for `date_based.archive_index`
    extra_context = kwargs.get('extra_context', {})
    extra_context.update({
        'date_list': kwargs['queryset'].dates(kwargs['date_field'], 'month')[::-1],
        'year': kwargs['year'],
    })
    kwargs['extra_context'] = extra_context
    kwargs = _remove_surplus_kwargs(kwargs)
    return object_list(request, *args, **kwargs)
示例#5
0
def archive_month(request, *args, **kwargs):
    """
    Generic paginatable monthly archive view.

    Templates: ``<app_label>/<model_name>_archive_month.html``
    Context:
        date_list:
            List of days in this month with objects
        month:
            (date) this month
        next_month:
            (date) the first day of the next month, or None if the next month is in the future
        previous_month:
            (date) the first day of the previous month
        object_list:
            list of objects published in the given month
    """
    # Calculate the date with current time
    month = datetime.date(int(kwargs['year']), int(kwargs['month']), 1)
    if month >= datetime.date(datetime.date.today().year, datetime.date.today().month, 1):
        next_month = None
    else:
        next_month = month + relativedelta(months=1)
        next_month = datetime.date(next_month.year, next_month.month, 1)
    previous_month = month - relativedelta(months=1)
    previous_month = datetime.date(previous_month.year, previous_month.month, 1)
    # Create context for `date_based.archive_index`
    extra_context = kwargs.get('extra_context', {})
    extra_context.update({
        'date_list': kwargs['queryset'].dates(kwargs['date_field'], 'month')[::-1],
        'month': month,
        'next_month': next_month,
        'previous_month': previous_month,
    })
    kwargs['extra_context'] = extra_context
    kwargs = _remove_surplus_kwargs(kwargs)
    return object_list(request, *args, **kwargs)