The community_all page should work properly lol

- Fixed community page back button showing even though no communities existed in a specific category
- Fixed Next button showing up when it shouldn't
This commit is contained in:
some weird guy
2023-09-19 11:36:49 -07:00
parent 863bd0e172
commit 85047883cc
+15 -25
View File
@@ -101,46 +101,36 @@ def community_list(request):
}) })
def community_all(request, category): def community_all(request, category):
"""All communities, with pagination""" """All communities, with pagination"""
PAGE_SIZE = 12
try: try:
offset = int(request.GET.get('offset', '0')) offset = int(request.GET.get('offset', '0'))
except ValueError: except ValueError:
offset = 0 offset = 0
if request.user.is_authenticated:
classes = ['guest-top']
else:
classes = []
g = [0, "General Communities"]
category_enum = { category_enum = {
'gen': g, 'gen': [0, "General Communities"],
'game': [1, "Game Communities"], 'game': [1, "Game Communities"],
'special': [2, "Special Communities"], 'special': [2, "Special Communities"],
'usr': [3, "User Communities"], 'usr': [3, "User Communities"],
}.get(category, g) }
category_type = category_enum[0] category_type, category_text = category_enum.get(category, category_enum['gen'])
communities = Community.get_all(category_type, offset) # Fetch PAGE_SIZE + 1 communities to determine if there's a next page
# Closedverse was NEVER meant to have 20000000 communities. communities = Community.get_all(category_type, offset, limit=PAGE_SIZE + 1)
if communities.count() > 12: total_communities = len(communities)
has_next = True has_next = total_communities > PAGE_SIZE
else: has_back = offset > 0
has_next = False # Only display PAGE_SIZE communities on the current page
if communities.count() < 1: communities = communities[:PAGE_SIZE]
has_back = True
else:
has_back = False
back = offset - 12
next = offset + 12
return render(request, 'closedverse_main/community_all.html', { return render(request, 'closedverse_main/community_all.html', {
'title': 'All Communities', 'title': 'All Communities',
'classes': classes, 'classes': ['guest-top'] if request.user.is_authenticated else [],
'communities': communities, 'communities': communities,
'category': category, 'category': category,
'text': category_enum[1], 'text': category_text,
'has_next': has_next, 'has_next': has_next,
'has_back': has_back, 'has_back': has_back,
'next': next, 'next': offset + PAGE_SIZE,
'back': back, 'back': max(offset - PAGE_SIZE, 0),
}) })
def community_search(request): def community_search(request):
"""Community searching""" """Community searching"""
query = request.GET.get('query') query = request.GET.get('query')