On 15 Apr, 00:05, fizban <[EMAIL PROTECTED]> wrote:
>
> I have finally solved my problem re-writing "myview":
>
> def myview(request, **kwargs):
>
> extra_context = {
> 'year': kwargs['year'],
> 'month': kwargs['month'],
> 'day': kwargs['day']
> }
>
> kwargs['extra_context'] = extra_context
>
> return date_based.object_detail(
> request, **kwargs
> )
Just in case anyone will land on this thread by searching on google or
something:
A better approach is the following (in views.py) since it is reusable
and it won't mess with other extra_context stuff you may pass in your
urlconf pattern.
def _entry_kwargs_helper(extra_context_list, kwarg_dict):
for item in extra_context_list:
kwarg_dict['extra_context'][item] = kwarg_dict[item]
return kwarg_dict
def entry_detail(request, **kwargs):
"""
Simple wrapper for object_detail from django.views.generic.date_based
Adds 'year', 'month' and 'day' to the context so that they can be
used directly
instead of obtaining them with object.<date_field>|
date:"<date_format>".
"""
extra_context_list = ('year', 'month', 'day')
kwarg_dict = _entry_kwargs_helper(extra_context_list, kwargs)
return date_based.object_detail(request, **kwarg_dict)
If anyone has a better (more elegant, clean, whatever) approach to
this I'd be glad to learn it :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---