Finish packaging and change to src-based packaging layout, replace caddy with haproxy for performance, and update docker-compose and Dockerfiles for new packaging.
This commit is contained in:
parent
959b06c425
commit
762361a21b
210 changed files with 235 additions and 168 deletions
0
src/pkmntrade_club/common/__init__.py
Normal file
0
src/pkmntrade_club/common/__init__.py
Normal file
8
src/pkmntrade_club/common/apps.py
Normal file
8
src/pkmntrade_club/common/apps.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CommonConfig(AppConfig):
|
||||
name = "pkmntrade_club.common"
|
||||
|
||||
def ready(self):
|
||||
pass
|
||||
6
src/pkmntrade_club/common/context_processors.py
Normal file
6
src/pkmntrade_club/common/context_processors.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.conf import settings
|
||||
|
||||
def cache_settings(request):
|
||||
return {
|
||||
'CACHE_TIMEOUT': settings.CACHE_TIMEOUT,
|
||||
}
|
||||
34
src/pkmntrade_club/common/mixins.py
Normal file
34
src/pkmntrade_club/common/mixins.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
|
||||
|
||||
class ReusablePaginationMixin:
|
||||
per_page = 10
|
||||
|
||||
def get_page_number(self):
|
||||
try:
|
||||
return int(self.request.GET.get("page", 1))
|
||||
except (ValueError, TypeError):
|
||||
return 1
|
||||
|
||||
def paginate_data(self, data, page_number):
|
||||
"""
|
||||
Paginates data (a QuerySet or list) and returns a tuple: (page_data, pagination_context).
|
||||
"""
|
||||
paginator = Paginator(data, self.per_page)
|
||||
try:
|
||||
page = paginator.page(page_number)
|
||||
except PageNotAnInteger:
|
||||
page = paginator.page(1)
|
||||
except EmptyPage:
|
||||
page = paginator.page(paginator.num_pages)
|
||||
|
||||
pagination_context = {
|
||||
"number": page.number,
|
||||
"has_previous": page.has_previous(),
|
||||
"has_next": page.has_next(),
|
||||
"previous_page_number": page.previous_page_number() if page.has_previous() else 1,
|
||||
"next_page_number": page.next_page_number() if page.has_next() else paginator.num_pages,
|
||||
"paginator": {"num_pages": paginator.num_pages},
|
||||
"count": paginator.count
|
||||
}
|
||||
return page.object_list, pagination_context
|
||||
0
src/pkmntrade_club/common/templatetags/__init__.py
Normal file
0
src/pkmntrade_club/common/templatetags/__init__.py
Normal file
10
src/pkmntrade_club/common/templatetags/pagination_tags.py
Normal file
10
src/pkmntrade_club/common/templatetags/pagination_tags.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.inclusion_tag("templatetags/pagination_controls.html", takes_context=True)
|
||||
def render_pagination(context, page_obj, hide_if_one_page=True):
|
||||
"""
|
||||
Renders the pagination controls given a page_obj. Optionally hides the controls if there is only one page.
|
||||
"""
|
||||
return {"page_obj": page_obj, "hide_if_one_page": hide_if_one_page}
|
||||
Loading…
Add table
Add a link
Reference in a new issue