Skip to content

Commit

Permalink
View followed summoners
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjp93 committed Jan 13, 2025
1 parent 5d976b3 commit b8d2895
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions lolsite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
path("", include("match.urls")),
path("", views.Home.as_view(), name="home"),
path("feed/", views.FeedView.as_view(), name="feed"),
path("following/", views.FollowingListView.as_view(), name="following"),
path("stats", include("stats.urls", namespace="stats")),
path("data/", include("data.urls", namespace="data")),
path("login/go/", player_views.login_action),
Expand Down
22 changes: 22 additions & 0 deletions lolsite/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import time
import logging

from django.contrib import messages
from django.db.models import Exists, OuterRef
from django.shortcuts import redirect
from django.views import generic
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.decorators.vary import vary_on_headers
Expand Down Expand Up @@ -62,3 +64,23 @@ def get_queryset(self):
.prefetch_related("participants", "participants__stats")
.order_by("-game_creation")
)


class FollowingListView(LoginRequiredMixin, generic.ListView):
template_name = "player/following.html"

def get_queryset(self):
return Summoner.objects.filter(
id__in=self.request.user.follow_set.all().values("summoner_id")
)

def get_context_data(self, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs)
context["count"] = self.get_queryset().count()
return context

def post(self, *args, **kwargs):
summoner_id = self.request.POST["summoner_id"]
count, _ = self.request.user.follow_set.filter(summoner_id=summoner_id).delete()
messages.info(self.request, f"Successfully removed {count} summoners from your follow list.")
return redirect("following")
8 changes: 8 additions & 0 deletions templates/player/feed.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

<div class="container mx-auto px-2 flex flex-col">
<h3>Match Feed</h3>
<div>
<div>
You are following {{ following.count }} summoner{{ following.count|pluralize }}.
</div>
<div>
<a href="{% url 'following' %}">View Here</a>
</div>
</div>
{% if following %}
<div hx-get="{% url 'feed' %}" hx-trigger="load" hx-swap="outerHTML">
<div>Refreshing matches...</div>
Expand Down
29 changes: 29 additions & 0 deletions templates/player/following.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends 'layout/base.html' %}
{% load static %}
{% block content %}

{% csrf_token %}
<div class="container mx-auto px-2 flex flex-col">
<h3>Follow List</h3>
<div>You are following {{ count }} summoner{{ count|pluralize}}.</div>
<div class="flex flex-col gap-y-2 mt-2">
{% for summoner in object_list %}
<div class="grid grid-cols-2">
<div>
{{ summoner.get_name }}
</div>
<div>
<form action="{% url 'following' %}" method="post">
{% csrf_token %}
<input type="hidden" name="summoner_id" value="{{ summoner.id }}">
<button class="btn btn-danger" title="remove" type="submit">
x
</button>
</form>
</div>
</div>
{% endfor %}
</div>
</div>

{% endblock content %}

0 comments on commit b8d2895

Please sign in to comment.