﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
195	Patch: Allow callables in the extra_context dictionary of django.views.generic.date_based	Moof <moof@…>	Adrian Holovaty	"Sometimes you want to add extra context to your generic views that needs to be recalculated every time. 

For example you currently have {{{<li><a href=""/weblog/2005/jul/"">July 2005</a></li>}}} in the static part of source:/djangoproject.com/django_website/templates/base_weblog.html because you can't pass an auto-generated list of months into the template, as it would get generated when the url map is generated.

The easiest way to solve this is to allow callables in the extra_context dictionary. Define a function or lambda which returns the data you want in the context when it's called, and then put a reference to it in the extra_context dict.

Example adapted from source:/djangoproject.com/django_website/apps/blog/urls/blog.py :

{{{
#!python

info_dict = {
    'app_label': 'blog',
    'module_name': 'entries',
    'date_field': 'pub_date',
    'extra_context': { 'month_list': 
        lambda: reverse(entries.get_pub_date_list('month', 
                            pub_date__lte=datetime.datetime.now())) }
}
}}}

Attached is a patch that enables this behaviour"	defect	closed	Core (Other)		normal	fixed			Unreviewed	0	0	0	0	0	0
