diff --git a/lolsite/urls.py b/lolsite/urls.py index 17ce2365..3cc1f703 100644 --- a/lolsite/urls.py +++ b/lolsite/urls.py @@ -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), diff --git a/lolsite/views.py b/lolsite/views.py index 1840c912..ab80e708 100644 --- a/lolsite/views.py +++ b/lolsite/views.py @@ -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 @@ -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") diff --git a/templates/player/feed.html b/templates/player/feed.html index 2bb52c75..3514ac99 100644 --- a/templates/player/feed.html +++ b/templates/player/feed.html @@ -4,6 +4,14 @@

Match Feed

+
+
+ You are following {{ following.count }} summoner{{ following.count|pluralize }}. +
+
+ View Here +
+
{% if following %}
Refreshing matches...
diff --git a/templates/player/following.html b/templates/player/following.html new file mode 100644 index 00000000..d6bab714 --- /dev/null +++ b/templates/player/following.html @@ -0,0 +1,29 @@ +{% extends 'layout/base.html' %} +{% load static %} +{% block content %} + + {% csrf_token %} +
+

Follow List

+
You are following {{ count }} summoner{{ count|pluralize}}.
+
+ {% for summoner in object_list %} +
+
+ {{ summoner.get_name }} +
+
+
+ {% csrf_token %} + + +
+
+
+ {% endfor %} +
+
+ +{% endblock content %}