Skip to content

Commit

Permalink
Custom Invite API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust committed Sep 2, 2024
1 parent a91ae7a commit aaca777
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 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",
),
]
29 changes: 25 additions & 4 deletions ladder/views/ladder_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class LadderEntryViewSet(
):
"""LadderEntry API"""

queryset = LadderEntry.objects.filter(visible=True).exclude(
ladder__difficulty="Any"
)
queryset = LadderEntry.objects.filter(visible=True)
serializer_class = LadderEntrySerializer
pagination_class = PageNumberPagination
filter_backends = (BaseFilterBackend, OrderingFilter)
Expand Down Expand Up @@ -74,4 +72,27 @@ def get_queryset(self):
ordering = (ordering,)
queryset = queryset.order_by(*ordering)

return queryset.filter(visible=True).exclude(ladder__difficulty="Any")
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("name", "ladder__difficulty")
)

0 comments on commit aaca777

Please sign in to comment.