Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replace deprecated generic FBV with equivalent CBV in aggregator.

  • Loading branch information...
commit d82240a1dc755ba6ab86c64aa7d285fbc5336550 1 parent e2563ef
Aymeric Augustin authored
2  aggregator/urls.py
@@ -15,7 +15,7 @@
15 15
     ),
16 16
     url(
17 17
         r'^(?P<feed_type_slug>[-\w]+)/$',
18  
-        views.feed_list,
  18
+        views.FeedListView.as_view(),
19 19
         name='community-feed-list'
20 20
     ),
21 21
     url(
21  aggregator/views.py
@@ -3,7 +3,7 @@
3 3
 from django.shortcuts import render, get_object_or_404, redirect
4 4
 from django.contrib import messages
5 5
 from django.contrib.auth.decorators import login_required
6  
-from django.views.generic.list_detail import object_list
  6
+from django.views.generic.list import ListView
7 7
 
8 8
 from .models import FeedItem, Feed, FeedType, APPROVED_FEED
9 9
 from .forms import FeedModelForm
@@ -15,16 +15,21 @@ def index(request):
15 15
     ctx = {'feedtype_list': FeedType.objects.all()}
16 16
     return render(request, 'aggregator/index.html', ctx)
17 17
 
18  
-def feed_list(request, feed_type_slug):
  18
+class FeedListView(ListView):
19 19
     """
20 20
     Shows the latest feeds for the given type.
21 21
     """
22  
-    feed_type = get_object_or_404(FeedType, slug=feed_type_slug)
23  
-    return object_list(request,
24  
-        queryset = FeedItem.objects.filter(feed__feed_type=feed_type, feed__approval_status=APPROVED_FEED),
25  
-        paginate_by = 25,
26  
-        extra_context = {'feed_type': feed_type},
27  
-    )
  22
+
  23
+    paginate_by = 25
  24
+
  25
+    def get_queryset(self):
  26
+        self.feed_type = get_object_or_404(FeedType, slug=self.kwargs.pop('feed_type_slug'))
  27
+        return FeedItem.objects.filter(feed__feed_type=self.feed_type, feed__approval_status=APPROVED_FEED)
  28
+
  29
+    def get_context_data(self, **kwargs):
  30
+        context = super(FeedListView, self).get_context_data(**kwargs)
  31
+        context['feed_type'] = self.feed_type
  32
+        return context
28 33
 
29 34
 @login_required
30 35
 def my_feeds(request):

0 notes on commit d82240a

Please sign in to comment.
Something went wrong with that request. Please try again.