stringfellow committed e3b13b5 Draft

Use ListView generic for profile_list

Comments (0)

Files changed (2)

-                           views.profile_list,
+                           views.ProfileList.as_view(
+                                template_name='profiles/profile_list.html'),


 from django.shortcuts import get_object_or_404
 from django.shortcuts import render_to_response
 from django.template import RequestContext
-from django.views.generic.list_detail import object_list
+from django.views.generic.list import ListView
 from profiles import utils
                               { 'profile': profile_obj },
-def profile_list(request, public_profile_field=None,
-                 template_name='profiles/profile_list.html', **kwargs):
+class ProfileList(ListView):
     A list of user profiles.
     Additionally, all arguments accepted by the
-    :view:`django.views.generic.list_detail.object_list` generic view
+    :view:`django.views.generic.list.ListView` generic view
     will be accepted here, and applied in the same fashion, with one
     exception: ``queryset`` will always be the ``QuerySet`` of the
     model specified by the ``AUTH_PROFILE_MODULE`` setting, optionally
     filtered to remove non-publicly-viewable proiles.
-    **Context:**
-    Same as the :view:`django.views.generic.list_detail.object_list`
-    generic view.
-    ``template_name`` keyword argument or
-    :template:`profiles/profile_list.html`.
+    ``template_name`` keyword argument
-    profile_model = utils.get_profile_model()
-    queryset = profile_model._default_manager.all()
-    if public_profile_field is not None:
-        queryset = queryset.filter(**{ public_profile_field: True })
-    kwargs['queryset'] = queryset
-    return object_list(request, template_name=template_name, **kwargs)
+    def __init__(self, public_profile_field=None, **kwargs):
+        self.public_profile_field = public_profile_field
+        self.model = utils.get_profile_model()
+        super(ProfileList, self).__init__(**kwargs)
+    def get_queryset(self):
+        if self.queryset is not None:
+            queryset = self.queryset
+            if hasattr(queryset, '_clone'):
+                queryset = queryset._clone()
+        else:  # we couldn't init without a model so, should be fine, right?!
+            queryset = self.model._default_manager.all()
+            if self.public_profile_field is not None:
+                queryset = queryset.filter(**{self.public_profile_field: True})
+        return queryset
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.