Kevin Veroneau avatar Kevin Veroneau committed e145dfb Draft

Fixed pagination when using filters, added grand total of movies to multiple pages.

Comments (0)

Files changed (7)

collection/templates/collection/format_list.html

 {% extends "base.html" %}
 {% load bootstrap %}
+{% load moviedb %}
 
 {% block jquery %}  $('#nav_format').addClass('active');{% endblock %}
 
     {% endfor %}
   </tbody>
 </table>
+<h3>Total movies in collection: {% total_movies %}.</h3>
 {% endblock %}

collection/templates/collection/genre_list.html

 {% extends "base.html" %}
 {% load bootstrap %}
 {% load cache %}
+{% load moviedb %}
 
 {% block jquery %}  $('#nav_genre').addClass('active');{% endblock %}
 
     {% endcache %}
   </tbody>
 </table>
+<h3>Total movies in collection: {% total_movies %}.</h3>
 {% endblock %}

collection/templates/collection/movie_list.html

 <div class="pagination">
     <ul>
         {% if page_obj.has_previous %}
-            <li><a href="?page={{ page_obj.previous_page_number }}">&laquo;</a></li>
+            <li><a href="?page={{ page_obj.previous_page_number }}{{extra_query}}">&laquo;</a></li>
         {% endif %}
         {% for tick in page_obj.paginator.num_pages|make_range %}
-            <li><a href="?page={{ tick }}">{{tick}}</a></li>
+            <li><a href="?page={{ tick }}{{extra_query}}">{{tick}}</a></li>
         {% endfor %}
         {% if page_obj.has_next %}
-            <li><a href="?page={{ page_obj.next_page_number }}">&raquo;</a></li>
+            <li><a href="?page={{ page_obj.next_page_number }}{{extra_query}}">&raquo;</a></li>
         {% endif %}
     </ul>
 </div>

collection/templatetags/bootstrap.py

 
 @register.filter
 def make_range(value):
-    return range(1, int(value))
+    return range(1, int(value+1))

collection/templatetags/moviedb.py

 def latest_movies():
     movie_list = Movie.objects.order_by('-added_on')[:9]
     return {'movie_list':movie_list, 'span':'4'}
+
+@register.simple_tag
+def total_movies():
+    return Movie.objects.all().count()

collection/views.py

     model = Movie
     paginate_by = 100
     def get_queryset(self):
+        self.query = ''
         qs = super(BrowseCollection, self).get_queryset().select_related()
         if 'ordering' in self.request.GET:
+            self.query = '&ordering=%s' % self.request.GET.get('ordering')
             return qs.order_by(self.request.GET.get('ordering'))
         if 'startswith' in self.request.GET:
+            self.query = '&startswith=%s' % self.request.GET.get('startswith')
             return qs.filter(title__startswith=self.request.GET.get('startswith'))
         return qs
+    def get_context_data(self, **kwargs):
+        kwargs.update({'extra_query':self.query})
+        return super(BrowseCollection, self).get_context_data(**kwargs)
 
 class BrowseGenre(ListView):
     model = Movie
     paginate_by = 100
     template_name = 'collection/genre_detail.html'
     def get_queryset(self):
+        self.query = ''
         self.genre = get_object_or_404(Genre, slug=self.kwargs['slug'])
         qs = super(BrowseGenre, self).get_queryset().select_related().filter(genre=self.genre)
         if 'ordering' in self.request.GET:
+            self.query = '&ordering=%s' % self.request.GET.get('ordering')
             return qs.order_by(self.request.GET.get('ordering'))
         if 'startswith' in self.request.GET:
+            self.query = '&startswith=%s' % self.request.GET.get('startswith')
             return qs.filter(title__startswith=self.request.GET.get('startswith'))
         return qs
     def get_context_data(self, **kwargs):
-        kwargs.update({'genre': self.genre})
+        kwargs.update({'genre': self.genre, 'extra_query':self.query})
         return super(BrowseGenre, self).get_context_data(**kwargs)
 
 class GenreList(ListView):
     paginate_by = 100
     template_name = 'collection/format_detail.html'
     def get_queryset(self):
+        self.query = ''
         self.format = int(self.kwargs['format_id'])
         qs = super(BrowseFormat, self).get_queryset().select_related().filter(format=self.format)
         if 'ordering' in self.request.GET:
+            self.query = '&ordering=%s' % self.request.GET.get('ordering')
             return qs.order_by(self.request.GET.get('ordering'))
         if 'startswith' in self.request.GET:
+            self.query = '&startswith=%s' % self.request.GET.get('startswith')
             return qs.filter(title__startswith=self.request.GET.get('startswith'))
         return qs
     def get_context_data(self, **kwargs):
-        kwargs.update({'format': self.format})
+        kwargs.update({'format': self.format, 'extra_query':self.query})
         return super(BrowseFormat, self).get_context_data(**kwargs)
 
 class AddMovie(OnlyNickMixin, CreateView):

templates/homepage.html

       <div class="hero-unit">
         <h1>Nick's DVD collection</h1>
         <p>This website is dedicated to my best friend Nick whom has the largest movie collection I know of.  Happy Birthday Nick!</p>
-        <p><a href="{% url 'browse_collection' %}" class="btn btn-primary btn-large">Browse collection &raquo;</a></p>
+        <p><a href="{% url 'browse_collection' %}" class="btn btn-primary btn-large">Browse all {% total_movies %} movies &raquo;</a></p>
       </div>
       {% include "search_form.html" %}
       <h3>Latest Movies</h3>
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 ProjectModifiedEvent.java.
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.