Commits

marinho committed 8bf4b13

Chaging views to support external set of model class

Comments (0)

Files changed (3)

diario/views/entries.py

     Tip: Uses the *View on site* button in Admin interface to access
     yours drafts and entries in future.
     """
+    model = kwargs.pop('model', Entry)
     kwargs['date_field'] = 'pub_date'
     kwargs['slug_field'] = 'slug'
     if request.user.has_perm('diario.change_entry'):
         kwargs['allow_future'] = True
-        kwargs['queryset'] = Entry.on_site.all()
+        kwargs['queryset'] = model.on_site.all()
     else:
         kwargs['allow_future'] = False
         if 'queryset' not in kwargs:
-            kwargs['queryset'] = Entry.published_on_site.all()
+            kwargs['queryset'] = model.published_on_site.all()
     return date_based.object_detail(request, *args, **kwargs)
 
 def entry_archive_year(request, *args, **kwargs):
     """
     A thin wrapper around ``django.views.generic.date_based.archive_year``.
     """
+    model = kwargs.pop('model', Entry)
     kwargs['date_field'] = 'pub_date'
     if 'queryset' not in kwargs:
-        kwargs['queryset'] = Entry.published_on_site.all()
+        kwargs['queryset'] = model.published_on_site.all()
     return date_based.archive_year(request, *args, **kwargs)
 
 def entry_archive_month(request, *args, **kwargs):
     """
     A thin wrapper around ``django.views.generic.date_based.archive_month``.
     """
+    model = kwargs.pop('model', Entry)
     kwargs['date_field'] = 'pub_date'
     if 'queryset' not in kwargs:
-        kwargs['queryset'] = Entry.published_on_site.all()
+        kwargs['queryset'] = model.published_on_site.all()
     return date_based.archive_month(request, *args, **kwargs)
 
 def entry_archive_day(request, *args, **kwargs):
     """
     A thin wrapper around ``django.views.generic.date_based.archive_day``.
     """
+    model = kwargs.pop('model', Entry)
     kwargs['date_field'] = 'pub_date'
     if 'queryset' not in kwargs:
-        kwargs['queryset'] = Entry.published_on_site.all()
+        kwargs['queryset'] = model.published_on_site.all()
     return date_based.archive_day(request, *args, **kwargs)
 
 def entry_list(request, *args, **kwargs):
     """
     A thin wrapper around ``django.views.generic.list_detail.object_list``.
     """
+    model = kwargs.pop('model', Entry)
     if 'queryset' not in kwargs:
-        kwargs['queryset'] = Entry.published_on_site.all()
+        kwargs['queryset'] = model.published_on_site.all()
     return list_detail.object_list(request, *args, **kwargs)

diario/views/entries_by_author.py

     ``author`` context variable will contain the ``User`` instance for the
     entry author.
     """
+    model = kwargs.pop('model', Entry)
     if author is None:
         try:
             author = kwargs.pop('author')
     except User.DoesNotExist:
         raise Http404(_('No User found matching "%s".') % author)
     if 'queryset' not in kwargs:
-        kwargs['queryset'] = Entry.published_on_site
+        kwargs['queryset'] = model.published_on_site
     kwargs['queryset'] = kwargs['queryset'].filter(author=user_instance)
     if 'extra_context' not in kwargs:
         kwargs['extra_context'] = {}

diario/views/tagged.py

     """
     A thin wrapper around ``tagging.views.tagged_object_list``.
     """
+    model = kwargs.pop('model', Entry)
     if 'queryset_or_model' not in kwargs:
-        kwargs['queryset_or_model'] = Entry.published_on_site.all()
+        kwargs['queryset_or_model'] = model.published_on_site.all()
     return tagged_object_list(request, *args, **kwargs)