[damned-lies] Replace people list view by a class-based view and add test for it



commit a96489faf53913d886ef80d7b02497f1ebea0c2a
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat May 14 22:29:44 2011 +0200

    Replace people list view by a class-based view and add test for it

 people/tests/__init__.py |   18 ++++++++++++++----
 people/urls.py           |   18 ++++--------------
 people/views.py          |   11 +++++++++++
 3 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/people/tests/__init__.py b/people/tests/__init__.py
index c2c5a1a..bde4b00 100644
--- a/people/tests/__init__.py
+++ b/people/tests/__init__.py
@@ -28,6 +28,13 @@ from people import forms
 
 class PeopleTestCase(TestCase):
 
+    def _create_person(self):
+        pn = Person(first_name='John', last_name='Nothing',
+            email='jn devnull com', username= 'jn')
+        pn.set_password('password')
+        pn.save()
+        return pn
+
     def test_register(self):
         response = self.client.post(reverse('register'),
                           {'username': u'test01', 'password1': u'1234567',
@@ -35,11 +42,14 @@ class PeopleTestCase(TestCase):
         self.assertRedirects(response, reverse('register_success'))
         self.assertEqual(Person.objects.filter(username=u'test01').count(), 1)
 
+    def test_person_list(self):
+        self.pn = self._create_person()
+        response = self.client.get(reverse('people'))
+        self.assertContains(response, "GNOME is being developed by following people:")
+        self.assertContains(response, "John Nothing")
+
     def test_edit_details(self):
-        self.pn = Person(first_name='John', last_name='Nothing',
-            email='jn devnull com', username= 'jn')
-        self.pn.set_password('password')
-        self.pn.save()
+        self.pn = self._create_person()
         self.client.login(username='jn', password='password')
         post_data = {
             'first_name': "Johnny", 'last_name': "Nothing", 'email': u'test02 example org',
diff --git a/people/urls.py b/people/urls.py
index 258e3a3..0cd6aba 100644
--- a/people/urls.py
+++ b/people/urls.py
@@ -1,13 +1,7 @@
 from django.conf.urls.defaults import *
-from people.models import Person
 
-info_dict_list = {
-    'queryset': Person.objects.all(),
-    'template_object_name': 'person',
-    'extra_context': {
-        'pageSection': "teams"
-    }
-}
+from people.views import PeopleListView
+
 
 # Regex order is really important here
 urlpatterns = patterns('people.views',
@@ -38,10 +32,6 @@ urlpatterns = patterns('people.views',
         name='person_detail_username'),
 )
 
-urlpatterns += patterns('django.views.generic.list_detail',
-    url(
-        regex = r'^$',
-        view = 'object_list',
-        kwargs = dict(info_dict_list),
-        name = 'people'),
+urlpatterns += patterns('',
+    url(r'^$', PeopleListView.as_view(), name='people'),
 )
diff --git a/people/views.py b/people/views.py
index 2256901..9c64b33 100644
--- a/people/views.py
+++ b/people/views.py
@@ -33,12 +33,23 @@ from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 from django.utils import formats
 from django.utils.translation import ugettext_lazy, ugettext as _
+from django.views.generic import ListView
 
 from people.models import Person
 from teams.models import Team, Role
 from people.forms import TeamJoinForm, DetailForm
 from vertimus.models import StateDb
 
+
+class PeopleListView(ListView):
+    model = Person
+
+    def get_context_data(self, **kwargs):
+        context = super(PeopleListView, self).get_context_data(**kwargs)
+        context['pageSection'] = "teams"
+        return context
+
+
 def person_detail(request, person_id=None, person_username=None):
     if person_id:
         person = get_object_or_404(Person, pk=person_id)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]