Ticket #1071: patch-django-views-generic_login-required_#1071_2.diff

File patch-django-views-generic_login-required_#1071_2.diff, 7.2 KB (added by root.lastnode@…, 18 years ago)

update to revision 3490 now with .diff ending as recommended in contributing documentation

  • django/views/generic/date_based.py

     
    11from django.template import loader, RequestContext
     2from django.contrib.auth.views import redirect_to_login
    23from django.core.exceptions import ObjectDoesNotExist
    34from django.core.xheaders import populate_xheaders
    45from django.http import Http404, HttpResponse
    56import datetime, time
    67
    78def archive_index(request, queryset, date_field, num_latest=15,
    8         template_name=None, template_loader=loader,
     9        template_name=None, template_loader=loader, login_required=False,
    910        extra_context=None, allow_empty=False, context_processors=None,
    1011        mimetype=None, allow_future=False):
    1112    """
     
    1920            Latest N (defaults to 15) objects by date
    2021    """
    2122    if extra_context is None: extra_context = {}
     23    if login_required and request.user.is_anonymous():
     24        return redirect_to_login(request)
     25       
    2226    model = queryset.model
    2327    if not allow_future:
    2428        queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
     
    4751
    4852def archive_year(request, year, queryset, date_field, template_name=None,
    4953        template_loader=loader, extra_context=None, allow_empty=False,
     54        login_required=False, context_processors=None, template_object_name='object',
     55        mimetype=None, make_object_list=False, allow_future=False):
    5056        context_processors=None, template_object_name='object', mimetype=None,
    5157        make_object_list=False, allow_future=False):
    5258    """
     
    6369            (Only available if make_object_list argument is True)
    6470    """
    6571    if extra_context is None: extra_context = {}
     72    if login_required and request.user.is_anonymous():
     73        return redirect_to_login(request)
     74
    6675    model = queryset.model
    6776    now = datetime.datetime.now()
    6877
     
    95104
    96105def archive_month(request, year, month, queryset, date_field,
    97106        month_format='%b', template_name=None, template_loader=loader,
    98         extra_context=None, allow_empty=False, context_processors=None,
    99         template_object_name='object', mimetype=None, allow_future=False):
     107        extra_context=None, allow_empty=False, login_required=False,
     108        context_processors=None, template_object_name='object', mimetype=None,
     109        allow_future=False):
    100110    """
    101111    Generic monthly archive view.
    102112
     
    112122            list of objects published in the given month
    113123    """
    114124    if extra_context is None: extra_context = {}
     125    if login_required and request.user.is_anonymous():
     126        return redirect_to_login(request)
     127
    115128    try:
    116129        date = datetime.date(*time.strptime(year+month, '%Y'+month_format)[:3])
    117130    except ValueError:
     
    161174
    162175def archive_week(request, year, week, queryset, date_field,
    163176        template_name=None, template_loader=loader,
    164         extra_context=None, allow_empty=True, context_processors=None,
    165         template_object_name='object', mimetype=None, allow_future=False):
     177        extra_context=None, allow_empty=True, login_required=False,
     178        context_processors=None, template_object_name='object', mimetype=None,
     179        allow_future=False):
    166180    """
    167181    Generic weekly archive view.
    168182
     
    174188            list of objects published in the given week
    175189    """
    176190    if extra_context is None: extra_context = {}
     191    if login_required and request.user.is_anonymous():
     192        return redirect_to_login(request)
     193
    177194    try:
    178195        date = datetime.date(*time.strptime(year+'-0-'+week, '%Y-%w-%U')[:3])
    179196    except ValueError:
     
    210227def archive_day(request, year, month, day, queryset, date_field,
    211228        month_format='%b', day_format='%d', template_name=None,
    212229        template_loader=loader, extra_context=None, allow_empty=False,
    213         context_processors=None, template_object_name='object',
    214         mimetype=None, allow_future=False):
     230        login_required=False, context_processors=None,
     231        template_object_name='object', mimetype=None, allow_future=False):
    215232    """
    216233    Generic daily archive view.
    217234
     
    227244            (datetime) the next day, or None if the current day is today
    228245    """
    229246    if extra_context is None: extra_context = {}
     247    if login_required and request.user.is_anonymous():
     248        return redirect_to_login(request)
     249
    230250    try:
    231251        date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
    232252    except ValueError:
     
    286306        month_format='%b', day_format='%d', object_id=None, slug=None,
    287307        slug_field=None, template_name=None, template_name_field=None,
    288308        template_loader=loader, extra_context=None, context_processors=None,
    289         template_object_name='object', mimetype=None, allow_future=False):
     309        login_required=False, template_object_name='object', mimetype=None,
     310        allow_future=False):
    290311    """
    291312    Generic detail view from year/month/day/slug or year/month/day/id structure.
    292313
     
    296317            the object to be detailed
    297318    """
    298319    if extra_context is None: extra_context = {}
     320    if login_required and request.user.is_anonymous():
     321        return redirect_to_login(request)
     322
    299323    try:
    300324        date = datetime.date(*time.strptime(year+month+day, '%Y'+month_format+day_format)[:3])
    301325    except ValueError:
  • django/views/generic/list_detail.py

     
    11from django.template import loader, RequestContext
    22from django.http import Http404, HttpResponse
     3from django.contrib.auth.views import redirect_to_login
    34from django.core.xheaders import populate_xheaders
    45from django.core.paginator import ObjectPaginator, InvalidPage
    56from django.core.exceptions import ObjectDoesNotExist
    67
    78def object_list(request, queryset, paginate_by=None, page=None,
    89        allow_empty=False, template_name=None, template_loader=loader,
    9         extra_context=None, context_processors=None, template_object_name='object',
    10         mimetype=None):
     10        extra_context=None, login_required=False, context_processors=None,
     11        template_object_name='object', mimetype=None):
    1112    """
    1213    Generic list of objects.
    1314
     
    3536            number of objects, total
    3637    """
    3738    if extra_context is None: extra_context = {}
     39    if login_required and request.user.is_anonymous():
     40        return redirect_to_login(request)
     41   
    3842    queryset = queryset._clone()
    3943    if paginate_by:
    4044        paginator = ObjectPaginator(queryset, paginate_by)
     
    8084
    8185def object_detail(request, queryset, object_id=None, slug=None,
    8286        slug_field=None, template_name=None, template_name_field=None,
    83         template_loader=loader, extra_context=None,
     87        template_loader=loader, extra_context=None, login_required=False,
    8488        context_processors=None, template_object_name='object',
    8589        mimetype=None):
    8690    """
     
    9296            the object
    9397    """
    9498    if extra_context is None: extra_context = {}
     99    if login_required and request.user.is_anonymous():
     100        return redirect_to_login(request)
     101
    95102    model = queryset.model
    96103    if object_id:
    97104        queryset = queryset.filter(pk=object_id)
Back to Top