from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
+from django.views.generic import ListView
from taggit.models import Tag
from .models import Recipe
return render_to_response(
'cookbook/recipes.html', {'recipes': recipes, 'title': tag.name},
RequestContext(request))
+
+class StaticContextListView (ListView):
+ _name_counter = 0
+ def get_context_data(self, **kwargs):
+ context = super(StaticContextListView, self).get_context_data(**kwargs)
+ context.update(self._extra_context)
+ return context
+
+def static_context_list_view_factory(extra_context):
+ class_name = 'StaticContextListView_{:d}'.format(
+ StaticContextListView._name_counter)
+ StaticContextListView._name_counter += 1
+ class_bases = (StaticContextListView,)
+ class_dict = dict(StaticContextListView.__dict__)
+ new_class = type(class_name, class_bases, class_dict)
+ new_class._extra_context = extra_context
+ return new_class