From e63cfe05cfa60a07ab8df90c2b0ee5119abaa44b Mon Sep 17 00:00:00 2001 From: jarvisdev Date: Fri, 26 Oct 2018 10:18:13 +0530 Subject: [PATCH] infinite scroll on leaderboard implemented --- ContriHub/settings.py | 40 ++++++++++---------- Projects/templates/Projects/leaderboard.html | 32 +++++++++++++--- Projects/views.py | 11 ++++++ 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/ContriHub/settings.py b/ContriHub/settings.py index ab2c66a..ed8dd11 100644 --- a/ContriHub/settings.py +++ b/ContriHub/settings.py @@ -122,12 +122,12 @@ else: #this is for local you need not to make any changes here, # it'll work unless you are sure about how to setup postgres/mysql etc - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } - } + # DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + # } + # } #An example how you can setup postgres sql in local, create a postgres db and provide relevant details in this format # DB_PASS = os.environ.get('CONTRIHUB_PASS', "") # DATABASES = { @@ -140,20 +140,20 @@ # 'PORT': '', # } # } - # DATABASES = { - # 'default': { - # 'ENGINE': 'django.db.backends.mysql', - # 'OPTIONS': { - # # 'read_default_file': '/path/to/my.cnf', - # }, - # # 'NAME': os.path.join(BASE_DIR, 'testdb'), - # 'NAME': 'contrihub_db', - # 'USER': 'user', - # 'PASSWORD': '1234', - # 'HOST': '127.0.0.1', - # 'PORT': '', - # } - # } + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'OPTIONS': { + # 'read_default_file': '/path/to/my.cnf', + }, + # 'NAME': os.path.join(BASE_DIR, 'testdb'), + 'NAME': 'contrihub_db', + 'USER': 'user', + 'PASSWORD': '1234', + 'HOST': '127.0.0.1', + 'PORT': '', + } + } # Password validation diff --git a/Projects/templates/Projects/leaderboard.html b/Projects/templates/Projects/leaderboard.html index 01a011d..c2316e8 100644 --- a/Projects/templates/Projects/leaderboard.html +++ b/Projects/templates/Projects/leaderboard.html @@ -24,11 +24,11 @@ Score
(click on score to see Contributions) - + {% for user in users %} - - {{forloop.counter}} + + {{forloop.counter0|add:users.start_index}} {{user.username}} {{user.profile.points}} @@ -37,10 +37,17 @@ - + + +{% if users.has_next %} + + +
+ loading more issues +
+ +{% endif %} @@ -49,4 +56,17 @@ {% block js_extra %} + {% endblock js_extra %} diff --git a/Projects/views.py b/Projects/views.py index 74c2a92..43724d9 100644 --- a/Projects/views.py +++ b/Projects/views.py @@ -11,6 +11,8 @@ from .models import Issues, Prs +import time + def home(request): if request.method == 'GET': @@ -55,6 +57,15 @@ def home(request): def leaderboard(request): if request.method == 'GET': users = User.objects.all().filter(profile__role='student').order_by('-profile__points') + paginator = Paginator(users,5) + page = request.GET.get('page',1) + try: + users = paginator.get_page(page) + except PageNotAnInteger: + users = paginator.get_page(1) + except EmptyPage: + users = paginator.objects.none() + time.sleep(0.5) return render(request, 'Projects/leaderboard.html', {'users': users})