Hello,
I just found what I think is a couple of bugs in Generic Views:
First:
in the class MultipleObjectMixin, in the file django/views/generic/list.py
there is a couple of methods that i think have a possible bug or
missbehavior:
lines 65/101
def get_context_object_name(self, object_list):
"""
Get the name of the item to be used in the context.
"""
if self.context_object_name:
return self.context_object_name
elif hasattr(object_list, 'model'):
return smart_str(object_list.model._meta.verbose_name_plural)
else:
return None
def get_context_data(self, **kwargs):
"""
Get the context for this view.
"""
queryset = kwargs.pop('object_list')
page_size = self.get_paginate_by(queryset)
if page_size:
paginator, page, queryset, is_paginated =
self.paginate_queryset(queryset, page_size)
context = {
'paginator': paginator,
'page_obj': page,
'is_paginated': is_paginated,
'object_list': queryset
}
else:
context = {
'paginator': None,
'page_obj': None,
'is_paginated': False,
'object_list': queryset
}
context.update(kwargs)
context_object_name = self.get_context_object_name(queryset)
if context_object_name is not None:
context[context_object_name] = queryset
return context
The problem here is:
If i don't set a context_object_name in my app, the method
get_context_object_name puts a name based in the verbose_name_plural of my
model's name but in the method get_context_data, ithe queryset is set twice,
first as 'object_list' and then with the generated name. Querysets being
lazy, this is not really a problem in templates, but if I want to serialize
that context generated by get_context_data (to create a generic view that
outputs results in json), I will load the data twice and that could be a
problem.
Any Opinions?
Second:
In the edit,py file (django/views/generic) the class ModelFormMixin inherits
from FormMixin and the methods form_invalid from both classes are the same
code:
return self.render_to_response(self.get_context_data(form=form))
I think the method from ModelFormMixin just should call super from
FormMixin, like in form_valid, but perhaps this is intentional.
Regards,
--
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en.