Ignore:
Timestamp:
Jun 15, 2014, 9:42:51 PM (11 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master
Children:
2e4e1fb
Parents:
f298bd7
git-author:
Alex Dehnert <adehnert@…> (06/15/14 17:59:25)
git-committer:
Alex Dehnert <adehnert@…> (06/15/14 21:42:51)
Message:

Django 1.6: Switch to class-based ListView?

Dango 1.5(?) removed function-based generic views, so we need to switch to the
class-based ones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • remit/util/shortcuts.py

    rf7dd5e7 r21360c8  
    22from django.template import RequestContext, Template
    33from django.template.loader import get_template
     4from django.views.generic.base import TemplateView
     5from django.views.generic.list import ListView
    46
    57def get_403_response(request, errmsg=None, **extra_context):
     
    810    page = tmpl.render(ctx, )
    911    return HttpResponseForbidden(page)
     12
     13
     14class ListViewWithContext(ListView):
     15    extra_context = {}
     16
     17    # I believe .queryset will work out-of-the-box
     18
     19    def get_context_data(self, **kwargs):
     20        context = super(ListViewWithContext,self).get_context_data(**kwargs)
     21        context.update(self.extra_context)
     22        return context
     23
     24
     25class TemplateViewWithContext(TemplateView):
     26    extra_context = {}
     27
     28    def get_context_data(self, **kwargs):
     29        context = super(TemplateViewWithContext,self).get_context_data(**kwargs)
     30        print context
     31        context.update(self.extra_context)
Note: See TracChangeset for help on using the changeset viewer.