home / django_tickets / tickets

tickets: 195

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
195 2005-07-25 18:55:15 2006-11-06 02:25:47 2022-03-06 03:20:02.972537 Unreviewed closed Core (Other) defect normal   fixed Patch: Allow callables in the extra_context dictionary of django.views.generic.date_based 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 adrian Moof <moof@metamoof.net>   0 0 0 0 0 0
Powered by Datasette · Queries took 0.928ms