Ticket #779: extra_lookup_kwargs_callable_r1217-fixed.patch

File extra_lookup_kwargs_callable_r1217-fixed.patch, 4.1 KB (added by Tom Tobin <korpios@…>, 19 years ago)

Patch against r1217 to implement callables for extra_lookup_kwargs (fixed)

  • views/generic/date_based.py

     
    2222    mod = get_module(app_label, module_name)
    2323    lookup_kwargs = {'%s__lte' % date_field: datetime.datetime.now()}
    2424    lookup_kwargs.update(extra_lookup_kwargs)
     25    for key, value in lookup_kwargs.items():
     26        if callable(value):
     27            lookup_kwargs[key] = value()
    2528    date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1]
    2629    if not date_list:
    2730        raise Http404("No %s.%s available" % (app_label, module_name))
     
    6972    if int(year) >= now.year:
    7073        lookup_kwargs['%s__lte' % date_field] = now
    7174    lookup_kwargs.update(extra_lookup_kwargs)
     75    for key, value in lookup_kwargs.items():
     76        if callable(value):
     77            lookup_kwargs[key] = value()
    7278    date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs)
    7379    if not date_list:
    7480        raise Http404
     
    121127    if last_day >= now.date():
    122128        lookup_kwargs['%s__lte' % date_field] = now
    123129    lookup_kwargs.update(extra_lookup_kwargs)
     130    for key, value in lookup_kwargs.items():
     131        if callable(value):
     132            lookup_kwargs[key] = value()
    124133    object_list = mod.get_list(**lookup_kwargs)
    125134    if not object_list:
    126135        raise Http404
     
    170179    if date >= now.date():
    171180        lookup_kwargs['%s__lte' % date_field] = now
    172181    lookup_kwargs.update(extra_lookup_kwargs)
     182    for key, value in lookup_kwargs.items():
     183        if callable(value):
     184            lookup_kwargs[key] = value()
    173185    object_list = mod.get_list(**lookup_kwargs)
    174186    if not allow_empty and not object_list:
    175187        raise Http404
     
    234246    else:
    235247        raise AttributeError("Generic detail view must be called with either an object_id or a slug/slugfield")
    236248    lookup_kwargs.update(extra_lookup_kwargs)
     249    for key, value in lookup_kwargs.items():
     250        if callable(value):
     251            lookup_kwargs[key] = value()
    237252    try:
    238253        object = mod.get_object(**lookup_kwargs)
    239254    except ObjectDoesNotExist:
  • views/generic/list_detail.py

     
    3737    """
    3838    mod = models.get_module(app_label, module_name)
    3939    lookup_kwargs = extra_lookup_kwargs.copy()
     40    for key, value in lookup_kwargs.items():
     41        if callable(value):
     42            lookup_kwargs[key] = value()
    4043    if paginate_by:
    4144        paginator = ObjectPaginator(mod, lookup_kwargs, paginate_by)
    4245        page = request.GET.get('page', 0)
     
    99102    else:
    100103        raise AttributeError("Generic detail view must be called with either an object_id or a slug/slug_field")
    101104    lookup_kwargs.update(extra_lookup_kwargs)
     105    for key, value in lookup_kwargs.items():
     106        if callable(value):
     107            lookup_kwargs[key] = value()
    102108    try:
    103109        object = mod.get_object(**lookup_kwargs)
    104110    except ObjectDoesNotExist:
  • views/generic/create_update.py

     
    9393    else:
    9494        raise AttributeError("Generic edit view must be called with either an object_id or a slug/slug_field")
    9595    lookup_kwargs.update(extra_lookup_kwargs)
     96    for key, value in lookup_kwargs.items():
     97        if callable(value):
     98            lookup_kwargs[key] = value()
    9699    try:
    97100        object = mod.get_object(**lookup_kwargs)
    98101    except ObjectDoesNotExist:
     
    169172    else:
    170173        raise AttributeError("Generic delete view must be called with either an object_id or a slug/slug_field")
    171174    lookup_kwargs.update(extra_lookup_kwargs)
     175    for key, value in lookup_kwargs.items():
     176        if callable(value):
     177            lookup_kwargs[key] = value()
    172178    try:
    173179        object = mod.get_object(**lookup_kwargs)
    174180    except ObjectDoesNotExist:
Back to Top