Skip to content

Commit

Permalink
Fix #1640 Pagination Added
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithBishal authored and DonnieBLT committed Dec 10, 2023
1 parent 1907317 commit e12b20a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
25 changes: 24 additions & 1 deletion website/templates/new_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,34 @@
grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
}
</style>
<div class="font-['Ubuntu'] text-[#2B2B2B] text-5xl tracking-wide font-semibold mb-0 mt-10 ms-[4.3%]">Find bugs, earn points, prize and cash!</div>
<div class="font-['Barlow'] text-[#2B2B2B] text-5xl tracking-wide font-semibold mb-0 mt-10 ms-[4.3%]">Find bugs, earn points, prize and cash!</div>
<div class="hero-bugs-container mx-[4%] my-[2.5rem] grid grid-flow-row gap-[25px]">
{% include '_report_widget.html' %}
{% for bug in bugs %}
{% include '_bug.html' %}
{% endfor %}
</div>
<div class="col-md-12">
<div class="text-center">
{% if bugs.has_previous %}
<a href="?page=1{% if user %}&user={{ user }}{% endif %}{% if label %}&label={{ label }}{% endif %}"
class="btn btn-default">First</a>
{% else %}
<button class="btn btn-default" disabled>First</button>
{% endif %}
{% for num in bugs.paginator.page_range %}
{% if num == bugs.number %}
<button class="btn btn-default" disabled>{{num}}</button>
{% elif num > bugs.number|add:"-5" and num < bugs.number|add:"5" %}
<a href="?page={{ num }}{% if user %}&user={{ user }}{% endif %}{% if label %}&label={{ label }}{% endif %}" class="btn btn-default">{{num}}</a>
{% endif %}
{% endfor %}
{% if bugs.has_next %}
<a href="?page={{ bugs.paginator.num_pages }}{% if user %}&user={{ user }}{% endif %}{% if label %}&label={{ label }}{% endif %}" class="btn btn-default">Last</a>
{% else %}
<button class="btn btn-default" disabled>Last</button>
{% endif %}
<div>Page {{ bugs.number }} of {{ bugs.paginator.num_pages }}</div>
</div>
</div>
{% endblock %}
9 changes: 7 additions & 2 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,17 @@ def newhome(request, template="new_home.html"):
except:
pass

bugs=Issue.objects.exclude(Q(is_hidden=True) & ~Q(user_id=request.user.id))
bugs=Issue.objects.exclude(Q(is_hidden=True) & ~Q(user_id=request.user.id)).all()
bugs_screenshots = {}

for bug in bugs:
bugs_screenshots[bug] = IssueScreenshot.objects.filter(issue=bug)[0:3]

paginator = Paginator(bugs, 7)
page_number = request.GET.get('page')
print(page_number)
page_obj = paginator.get_page(page_number)

# latest_hunts_filter = request.GET.get("latest_hunts",None)

# bug_count = Issue.objects.all().count()
Expand Down Expand Up @@ -237,7 +242,7 @@ def newhome(request, template="new_home.html"):


context = {
"bugs": bugs,
"bugs": page_obj,
"bugs_screenshots" : bugs_screenshots,
# "server_url": request.build_absolute_uri('/'),
# "activities": activities,
Expand Down

0 comments on commit e12b20a

Please sign in to comment.