From 1644079be9026b50a49f6b6f09e11f7d0f208f62 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Feb 09 2017 19:13:00 +0000
Subject: [PATCH 1/5] fix odd pagination error


---

diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index a74c1c5..71ec893 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -669,10 +669,10 @@ def view_issues(repo, username=None, namespace=None):
             author=author,
             private=private,
             priority=priority,
-            count=True,
             search_pattern=search_pattern,
             custom_search=custom_search,
-        )
+            count=True,
+            )
         oth_issues_cnt = total_issues_cnt - issues_cnt
     else:
         issues = pagure.lib.search_issues(
@@ -682,12 +682,17 @@ def view_issues(repo, username=None, namespace=None):
             search_pattern=search_pattern,
             custom_search=custom_search,
         )
-        issues_cnt = total_issues_cnt
-
+        issues_cnt = pagure.lib.search_issues(
+            SESSION, repo, tags=tags, assignee=assignee,
+            author=author, private=private, priority=priority,
+            offset=flask.g.offset, limit=flask.g.limit,
+            search_pattern=search_pattern,
+            custom_search=custom_search,
+            count=True
+        )
     tag_list = pagure.lib.get_tags_of_project(SESSION, repo)
 
     total_page = int(ceil(issues_cnt / float(flask.g.limit)) if issues_cnt > 0 else 1)
-
     return flask.render_template(
         'issues.html',
         select='issues',

From 3515ad388540aad07d17851428daed661b3773bf Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Feb 09 2017 19:13:00 +0000
Subject: [PATCH 2/5] fix pep8 error


---

diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index 71ec893..c37af20 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -688,7 +688,7 @@ def view_issues(repo, username=None, namespace=None):
             offset=flask.g.offset, limit=flask.g.limit,
             search_pattern=search_pattern,
             custom_search=custom_search,
-            count=True
+            count=True,
         )
     tag_list = pagure.lib.get_tags_of_project(SESSION, repo)
 

From 4ad119a07957e8f9b4b9b986dcbfa3602aea4618 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Feb 09 2017 19:13:00 +0000
Subject: [PATCH 3/5] adjust indentation


---

diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index c37af20..a51c045 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -672,7 +672,7 @@ def view_issues(repo, username=None, namespace=None):
             search_pattern=search_pattern,
             custom_search=custom_search,
             count=True,
-            )
+        )
         oth_issues_cnt = total_issues_cnt - issues_cnt
     else:
         issues = pagure.lib.search_issues(

From b1da01c2ac0bdafe2424d3f97c5e48ea542baa73 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Feb 09 2017 19:13:00 +0000
Subject: [PATCH 4/5] add unit-test patch and bug-fix patch


---

diff --git a/pagure/__init__.py b/pagure/__init__.py
index 8cfce94..de640b3 100644
--- a/pagure/__init__.py
+++ b/pagure/__init__.py
@@ -436,7 +436,7 @@ def set_variables():
         flask.g.repo_admin = is_repo_admin(flask.g.repo)
         flask.g.branches = sorted(flask.g.repo_obj.listall_branches())
 
-    items_per_page = 100
+    items_per_page = APP.config['ITEM_PER_PAGE']
     flask.g.offset = 0
     flask.g.page = 1
     flask.g.limit = items_per_page
diff --git a/pagure/templates/issues.html b/pagure/templates/issues.html
index da1f81d..77e9fd4 100644
--- a/pagure/templates/issues.html
+++ b/pagure/templates/issues.html
@@ -16,7 +16,7 @@
     {% elif status|lower not in ['open', 'true', 'all', 'none'] %}
       {{ issues|count }} Closed Issues (of {{ issues_cnt }})
     {% else %}
-      {{ issues|count }} Issues
+      {{ issues|count }} Issues (of {{ issues_cnt }})
     {% endif %}
     <span class="btn-group btn-group-sm pull-xs-right" role="group">
     {% if repo.milestones %}
diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index a51c045..3220229 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -685,7 +685,6 @@ def view_issues(repo, username=None, namespace=None):
         issues_cnt = pagure.lib.search_issues(
             SESSION, repo, tags=tags, assignee=assignee,
             author=author, private=private, priority=priority,
-            offset=flask.g.offset, limit=flask.g.limit,
             search_pattern=search_pattern,
             custom_search=custom_search,
             count=True,
diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py
index afc6d27..2be9339 100644
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -37,7 +37,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
     """ Tests for flask issues controller of pagure """
 
     def setUp(self):
-        """ Set up the environnment, ran before every tests. """
+        """ Set up the environnment, run before every tests. """
         super(PagureFlaskIssuestests, self).setUp()
 
         pagure.APP.config['TESTING'] = True
@@ -353,11 +353,32 @@ class PagureFlaskIssuestests(tests.Modeltests):
 
         # All tickets
         output = self.app.get('/test/issues?status=all')
+
         self.assertEqual(output.status_code, 200)
         self.assertIn('<title>Issues - test - Pagure</title>', output.data)
         self.assertTrue(
             '<h2>\n      2 Issues' in output.data)
 
+        # All tickets - different pagination
+        before = pagure.APP.config['ITEM_PER_PAGE']
+        pagure.APP.config['ITEM_PER_PAGE'] = 1
+        output = self.app.get('/test/issues?status=all')
+        self.assertEqual(output.status_code, 200)
+        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
+        self.assertIn('<h2>\n      1 Issues (of 2)', output.data)
+        self.assertIn(
+            '<li class="active">page 1 of 2</li>', output.data)
+
+        # All tickets - filtered for 1 - checking the pagination
+        output = self.app.get(
+            '/test/issues?status=all&search_pattern=invalid')
+        self.assertEqual(output.status_code, 200)
+        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
+        self.assertIn('<h2>\n      1 Issues (of 1)', output.data)
+        self.assertIn(
+            '<li class="active">page 1 of 1</li>', output.data)
+        pagure.APP.config['ITEM_PER_PAGE'] = before
+
         # New issue button is shown
         user = tests.FakeUser()
         with tests.user_set(pagure.APP, user):
@@ -2270,8 +2291,7 @@ class PagureFlaskIssuestests(tests.Modeltests):
         # After update, list tags
         tags = pagure.lib.get_tags_of_project(self.session, repo)
         self.assertEqual([tag.tag for tag in tags], ['blue', 'green', 'red'])
-
-
+        
 if __name__ == '__main__':
     SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskIssuestests)
     unittest.TextTestRunner(verbosity=2).run(SUITE)

From 939665508cd0880e50740394b45e606edff80254 Mon Sep 17 00:00:00 2001
From: Vibhor Verma <vibhcool@gmail.com>
Date: Feb 09 2017 20:16:27 +0000
Subject: [PATCH 5/5] fix spaces error


---

diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py
index 2be9339..9897ab7 100644
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -2291,7 +2291,8 @@ class PagureFlaskIssuestests(tests.Modeltests):
         # After update, list tags
         tags = pagure.lib.get_tags_of_project(self.session, repo)
         self.assertEqual([tag.tag for tag in tags], ['blue', 'green', 'red'])
-        
+
+
 if __name__ == '__main__':
     SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskIssuestests)
     unittest.TextTestRunner(verbosity=2).run(SUITE)

