Skip to content

Commit

Permalink
Template fixes (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust authored Sep 2, 2024
1 parent 1359bbd commit 4182b7d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
5 changes: 5 additions & 0 deletions ladder/templates/invites.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load ladder_entry %}
<pre>
{% for entry in ladderentry_list %}{% ladder_entry_channels entry as channels %}{% for channel in channels %}/channel_invite "{{channel}}" {{entry.player}}
{% endfor %}{% endfor %}
</pre>
34 changes: 32 additions & 2 deletions ladder/templatetags/ladder_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging

from django import template

from ladder.models import Ladder, LadderEntry

register = template.Library()
Expand Down Expand Up @@ -32,7 +31,10 @@ def ladder_rank(obj, request):
key = f"data__{obj.ladder.metric}__gt"
flt = {key: obj.data.get(obj.ladder.metric, 0)}
return (
LadderEntry.objects.filter(ladder=obj.ladder).filter(visible=True).filter(**flt).count()
LadderEntry.objects.filter(ladder=obj.ladder)
.filter(visible=True)
.filter(**flt)
.count()
+ 1
)

Expand All @@ -57,3 +59,31 @@ def ladder_difficulties():
.values_list("difficulty", flat=True)
.distinct()
)


@register.simple_tag
def ladder_entry_channels(instance):
# <pre></pre>
# /channel_invite "{{channel}}" {{entry.player}} # {{entry.data.DPS|floatformat:0}} DPS
channels = []
if instance.ladder.internal_name in [
"Infected Space",
] and instance.ladder.internal_difficulty in ["Advanced", "Elite"]:
if instance.data.get("DPS", 0) >= 500000:
channels.append("DPS-#s-Prime")
if instance.data.get("DPS", 0) >= 150000:
channels.append("DPS-#s-Elites")
elif instance.ladder.internal_name in [
"Hive Space",
] and instance.ladder.internal_difficulty in ["Elite"]:
if instance.data.get("DPS", 0) >= 500000:
channels.append("DPS-#s-Prime")
if instance.data.get("DPS", 0) >= 150000:
channels.append("DPS-#s-Elites")
elif instance.ladder.internal_name in [
"Bug Hunt",
"Nukera Prime: Transdimensional Tactics",
]:
if instance.data.get("DPS", 0) >= 1000:
channels.append("DPS-#s-Ground")
return channels
5 changes: 5 additions & 0 deletions ladder/urls/ladder_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
views.LadderEntryView.as_view(template_name="ladder_entry.html"),
name="ui",
),
path(
"ui/invites/",
views.LadderInvitesView.as_view(template_name="invites.html"),
name="invites",
),
]
36 changes: 29 additions & 7 deletions ladder/views/ladder_entry.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
""" LadderEntry Views """
"""LadderEntry Views"""

import logging

from core.filters import BaseFilterBackend
from core.pagination import PageNumberPagination
from django.core.exceptions import ImproperlyConfigured
from django.db.models.query import QuerySet
from django_filters.views import FilterView
from rest_framework.filters import OrderingFilter
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet

from core.filters import BaseFilterBackend
from core.pagination import PageNumberPagination
from ladder.filters import LadderEntryFilter
from ladder.models import LadderEntry
from ladder.serializers import LadderEntrySerializer
from rest_framework.filters import OrderingFilter
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet

LOGGER = logging.getLogger("django")

Expand Down Expand Up @@ -74,3 +73,26 @@ def get_queryset(self):
queryset = queryset.order_by(*ordering)

return queryset.filter(visible=True)


class LadderInvitesView(FilterView):
"""LadderEntry View"""

model = LadderEntry
filter_backends = (BaseFilterBackend, OrderingFilter)
filterset_class = LadderEntryFilter

def get_queryset(self):
return (
LadderEntry.objects.filter(
ladder__internal_name__in=[
"Infected Space",
"Hive Space",
"Bug Hunt",
"Nukara Prime: Transdimensional Tactics",
],
)
.exclude(ladder__difficulty="Any")
.order_by("-data__DPS")
.distinct("player", "ladder__difficulty")
)

0 comments on commit 4182b7d

Please sign in to comment.