Commit 9b0c752bedf93e87e3ff22f5f99d52f2d9332936

Authored by Zambom
1 parent 47ee8b1c

Fixing pagination script error in pages without pagination

app/templates/home.html
... ... @@ -3,53 +3,55 @@
3 3 {% load static i18n django_bootstrap_breadcrumbs permission_tags %}
4 4  
5 5 {% block javascript %}
6   - <script type="text/javascript">
7   - var pageNum = {{ page_obj.number }}; // The latest page loaded
8   - var numberPages = {{ paginator.num_pages }}; // Indicates the number of pages
9   - var baseUrl = '{% url "app:index" %}';
  6 + {% if page_obj %}
  7 + <script type="text/javascript">
  8 + var pageNum = {{ page_obj.number }}; // The latest page loaded
  9 + var numberPages = {{ paginator.num_pages }}; // Indicates the number of pages
  10 + var baseUrl = '{% url "app:index" %}';
10 11  
11   - // loadOnScroll handler
12   - var loadOnScroll = function() {
13   - // If the current scroll position is past out cutoff point...
14   - if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
15   - // temporarily unhook the scroll event watcher so we don't call a bunch of times in a row
16   - $(window).unbind();
17   - // execute the load function below that will visit the view and return the content
18   - loadItems();
19   - }
20   - };
  12 + // loadOnScroll handler
  13 + var loadOnScroll = function() {
  14 + // If the current scroll position is past out cutoff point...
  15 + if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
  16 + // temporarily unhook the scroll event watcher so we don't call a bunch of times in a row
  17 + $(window).unbind();
  18 + // execute the load function below that will visit the view and return the content
  19 + loadItems();
  20 + }
  21 + };
21 22  
22   - var loadItems = function() {
23   - // Check if page is equal to the number of pages
24   - if (pageNum == numberPages) {
25   - return false
26   - }
27   - // Update the page number
28   - pageNum = pageNum + 1;
  23 + var loadItems = function() {
  24 + // Check if page is equal to the number of pages
  25 + if (pageNum == numberPages) {
  26 + return false
  27 + }
  28 + // Update the page number
  29 + pageNum = pageNum + 1;
29 30  
30   - $("#loading").show();
31   - // Configure the url we're about to hit
32   - setTimeout(function (){
33   - $.ajax({
34   - url: baseUrl,
35   - data: {'page': pageNum},
36   - success: function(data) {
37   - $("#loading").hide();
  31 + $("#loading").show();
  32 + // Configure the url we're about to hit
  33 + setTimeout(function (){
  34 + $.ajax({
  35 + url: baseUrl,
  36 + data: {'page': pageNum},
  37 + success: function(data) {
  38 + $("#loading").hide();
38 39  
39   - $("#timeline").append(data);
40   - },
41   - complete: function(data, textStatus){
42   - // Turn the scroll monitor back on
43   - $(window).bind('scroll', loadOnScroll);
44   - }
45   - });
46   - }, 1000)
47   - };
  40 + $("#timeline").append(data);
  41 + },
  42 + complete: function(data, textStatus){
  43 + // Turn the scroll monitor back on
  44 + $(window).bind('scroll', loadOnScroll);
  45 + }
  46 + });
  47 + }, 1000)
  48 + };
48 49  
49   - $(document).ready(function(){
50   - $(window).bind('scroll', loadOnScroll);
51   - });
52   - </script>
  50 + $(document).ready(function(){
  51 + $(window).bind('scroll', loadOnScroll);
  52 + });
  53 + </script>
  54 + {% endif %}
53 55 {% endblock %}
54 56  
55 57 {% block breadcrumbs %}
... ...
app/views.py
... ... @@ -18,8 +18,6 @@ class AppIndex(LoginRequiredMixin, LogMixin, ListView, NotificationMixin):
18 18 context_object_name = 'objects'
19 19 paginate_by = 10
20 20  
21   -
22   -
23 21 def get_queryset(self):
24 22 if self.request.user.is_staff:
25 23 objects = Course.objects.all()
... ...
courses/migrations/0005_auto_20161021_1749.py 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# -*- coding: utf-8 -*-
  2 +# Generated by Django 1.10 on 2016-10-21 20:49
  3 +from __future__ import unicode_literals
  4 +
  5 +from django.conf import settings
  6 +from django.db import migrations, models
  7 +
  8 +
  9 +class Migration(migrations.Migration):
  10 +
  11 + dependencies = [
  12 + ('courses', '0004_auto_20161020_1808'),
  13 + ]
  14 +
  15 + operations = [
  16 + migrations.AlterField(
  17 + model_name='subject',
  18 + name='students',
  19 + field=models.ManyToManyField(blank=True, related_name='subject_student', to=settings.AUTH_USER_MODEL, verbose_name='Students'),
  20 + ),
  21 + ]
... ...