From e046c3e801f38c6be08a46b93b449346d3ce86ff Mon Sep 17 00:00:00 2001 From: Alain Date: Fri, 13 Oct 2023 13:34:31 +0200 Subject: [PATCH] Added best of the rest view Do not show the toggle filter pos button when there is no filters. --- thefiltershop/filtershop_main/models.py | 2 + .../templates/thefiltershop/base_games.html | 2 +- .../thefiltershop/best_of_the_rest.html | 11 +++++ .../templates/thefiltershop/game.html | 4 +- .../templates/thefiltershop/online_shop.html | 4 +- .../partials/filters_on_top_or_bottom.html | 2 +- .../thefiltershop/partials/game_rating.html | 4 +- .../thefiltershop/physical_shop.html | 4 +- thefiltershop/filtershop_main/urls.py | 1 + .../filtershop_main/views/__init__.py | 1 + .../filtershop_main/views/list_games.py | 43 ++++++++++++++++++- .../filtershop_main/views/view_a_game.py | 15 ++++++- .../views/view_a_physical_shop.py | 8 +++- .../views/view_an_online_shop.py | 6 +++ 14 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 thefiltershop/filtershop_main/templates/thefiltershop/best_of_the_rest.html diff --git a/thefiltershop/filtershop_main/models.py b/thefiltershop/filtershop_main/models.py index 0dc8c09..19ba93e 100644 --- a/thefiltershop/filtershop_main/models.py +++ b/thefiltershop/filtershop_main/models.py @@ -267,6 +267,7 @@ class Videogame_rating(BaseModel): for_platform = models.ForeignKey(Platform, on_delete=models.PROTECT) f2play = models.BooleanField(default=False) f2pay = models.BooleanField(default=False) # Should maybe move to a filter? + # Ratings: higher is better. gameplay_rating = models.IntegerField(default=50) money_rating = models.IntegerField(default=0, validators=[MaxValueValidator(100), MinValueValidator(0)]) good_wo_iap = models.IntegerField(default=-1, validators=[MaxValueValidator(100), MinValueValidator(-1)]) @@ -275,6 +276,7 @@ class Videogame_rating(BaseModel): fully_rotten = models.BooleanField(default=False) would_be_good_if = models.TextField(max_length=1000, null=True, blank=True) could_be_good_if = models.TextField(max_length=1000, null=True, blank=True) + # here, lower is better (-1 is none) use_psycho_tech = models.IntegerField(default=-1, validators=[MaxValueValidator(100), MinValueValidator(-1)]) crapometer = models.IntegerField(default=0, validators=[MaxValueValidator(100), MinValueValidator(0)]) Videogame_common = models.ForeignKey(Videogame_common, on_delete=models.CASCADE, null=True, blank=False) diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/base_games.html b/thefiltershop/filtershop_main/templates/thefiltershop/base_games.html index 8daeb39..c39c9c6 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/base_games.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/base_games.html @@ -4,7 +4,7 @@ {% block content %} diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/best_of_the_rest.html b/thefiltershop/filtershop_main/templates/thefiltershop/best_of_the_rest.html new file mode 100644 index 0000000..d5a25c3 --- /dev/null +++ b/thefiltershop/filtershop_main/templates/thefiltershop/best_of_the_rest.html @@ -0,0 +1,11 @@ +{% extends "thefiltershop/base_games.html" %} + +{% block title %}Best of the rest{% endblock %} + +{% block content %} +
+

All these game could be good if...

+ +{% include "thefiltershop/partials/list_of_games.html" with page_obj=page_obj%} + +{% endblock %} \ No newline at end of file diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/game.html b/thefiltershop/filtershop_main/templates/thefiltershop/game.html index 3ef8037..522ada2 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/game.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/game.html @@ -4,7 +4,7 @@ {% block content %} -{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True is_filter=is_filter %}

{{a_game.name}} @@ -45,7 +45,7 @@

{% endfor %} -{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False is_filter=is_filter %} diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/online_shop.html b/thefiltershop/filtershop_main/templates/thefiltershop/online_shop.html index 1b2f16c..dd8b56a 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/online_shop.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/online_shop.html @@ -6,7 +6,7 @@ {% block content %} -{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True is_filter=is_filter %}
@@ -51,6 +51,6 @@

All games from : {{a_shop.name}}

-{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False is_filter=is_filter %} {% endblock %} \ No newline at end of file diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/partials/filters_on_top_or_bottom.html b/thefiltershop/filtershop_main/templates/thefiltershop/partials/filters_on_top_or_bottom.html index f472234..7cc5006 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/partials/filters_on_top_or_bottom.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/partials/filters_on_top_or_bottom.html @@ -31,7 +31,7 @@ } } -{% if is_on_top and not no_button %} +{% if is_on_top and is_filter and not no_button %} {% endif %}
diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/partials/game_rating.html b/thefiltershop/filtershop_main/templates/thefiltershop/partials/game_rating.html index cec1755..3b5b7eb 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/partials/game_rating.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/partials/game_rating.html @@ -2,7 +2,7 @@

Present on {{ a_rating_with_filters.rating.for_platform.name }}{% if a_rating_with_filters.rating.same_platform_alternative_shop %}, sold on {{a_rating_with_filters.rating.same_platform_alternative_shop}}{% endif %}

- {% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=a_rating_with_filters.negative_filters positive_filters=a_rating_with_filters.positive_filters is_on_top=True no_button=True %} + {% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=a_rating_with_filters.negative_filters positive_filters=a_rating_with_filters.positive_filters is_on_top=True no_button=True is_filter=a_rating_with_filters.is_filter %}
{{ a_rating_with_filters.rating.f2play | yesno:"F2P,Premium"}}
@@ -27,6 +27,6 @@

Present on {{ a_rating_with_filters.rating.for_platform.name }}{% if a_ratin
{{ a_rating_with_filters.rating.would_be_good_if }}
{{ a_rating_with_filters.rating.could_be_good_if }}
- {% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=a_rating_with_filters.negative_filters positive_filters=a_rating_with_filters.positive_filters is_on_top=False no_button=True %} + {% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=a_rating_with_filters.negative_filters positive_filters=a_rating_with_filters.positive_filters is_on_top=False no_button=True is_filter=a_rating_with_filters.is_filter %} {% endfor %} \ No newline at end of file diff --git a/thefiltershop/filtershop_main/templates/thefiltershop/physical_shop.html b/thefiltershop/filtershop_main/templates/thefiltershop/physical_shop.html index ddcbf0d..74344c9 100644 --- a/thefiltershop/filtershop_main/templates/thefiltershop/physical_shop.html +++ b/thefiltershop/filtershop_main/templates/thefiltershop/physical_shop.html @@ -5,7 +5,7 @@ {% block content %} -{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=True is_filter=is_filter %}

@@ -34,6 +34,6 @@

{% endfor %}

-{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False %} +{% include "thefiltershop/partials/filters_on_top_or_bottom.html" with negative_filters=negative_filters positive_filters=positive_filters is_on_top=False is_filter=is_filter %} {% endblock %} \ No newline at end of file diff --git a/thefiltershop/filtershop_main/urls.py b/thefiltershop/filtershop_main/urls.py index 7e54e28..4e2f66e 100644 --- a/thefiltershop/filtershop_main/urls.py +++ b/thefiltershop/filtershop_main/urls.py @@ -18,6 +18,7 @@ path("game_filters", views.get_all_filters_for_an_entity_type_videogame, name="game_filters"), path("one_filter//", views.get_one_filter_and_related_filters, name="one_filter"), path("they_made_it", views.get_artisans_and_indies_games_that_made_it, name="they_made_it"), + path("best_of_the_rest", views.get_best_of_the_rest, name="best_of_the_rest"), path("hall_of_shame", views.get_items_in_hall_of_shame, name="hall_of_shame"), path("physical_shop//", views.physical_shop, name="physical_shop"), path("index_physical_shops", views.index_physical_shops, name="index_physical_shops"), diff --git a/thefiltershop/filtershop_main/views/__init__.py b/thefiltershop/filtershop_main/views/__init__.py index a2ddf46..234d93c 100644 --- a/thefiltershop/filtershop_main/views/__init__.py +++ b/thefiltershop/filtershop_main/views/__init__.py @@ -5,6 +5,7 @@ from .list_games import get_artisans_games from .list_games import get_indies_games from .list_games import get_artisans_and_indies_games_that_made_it +from .list_games import get_best_of_the_rest from .show_curators import get_curators from .get_filters import get_all_filters from .get_filters import get_all_filters_for_an_entity_type_videogame diff --git a/thefiltershop/filtershop_main/views/list_games.py b/thefiltershop/filtershop_main/views/list_games.py index fd3e565..c96eab9 100644 --- a/thefiltershop/filtershop_main/views/list_games.py +++ b/thefiltershop/filtershop_main/views/list_games.py @@ -1,5 +1,6 @@ from django.shortcuts import render from django.db.models import Q +from django.db.models import Count from django.core.paginator import Paginator from ..models import Videogame_common, Game_Category, Studio, Publisher @@ -49,6 +50,18 @@ def get_artisans_and_indies_games_that_made_it(request): return render(request, "thefiltershop/they_made_it.html", context) +def get_best_of_the_rest(request): + list_of_best_of_the_rest = get_all_best_of_the_rest() + + paginator = Paginator(list_of_best_of_the_rest, 25) # Show 25 contacts per page. + + page_number = request.GET.get("page") + page_obj = paginator.get_page(page_number) + + context = {"page_obj": page_obj} + + return render(request, "thefiltershop/best_of_the_rest.html", context) + def get_all_games_for_size(max_size_of_studio) : if not isinstance(max_size_of_studio, Studio.SizeInPersons): raise TypeError('max_size_of_studio_or_publisher must be a Studio_and_Publisher_Size') @@ -66,4 +79,32 @@ def get_all_games_that_made_it() : all_for_size = Videogame_common.objects.filter(Q(studios__size_of_studio = Studio.SizeInPersons.ARTISAN) | Q(studios__size_of_studio = Studio.SizeInPersons.INDIE), ~Q(they_have_made_it = Videogame_common.TheyHaveMadeIt.NO)) print(all_for_size.query) - return all_for_size \ No newline at end of file + return all_for_size + +def get_all_best_of_the_rest() : + # On all filtered games, find which one would actually be good. + # Best of the rest: gameplay_rating > 80 & good_wo_iap > 80 & good_wo_ads > 80 & use_psycho_tech == 0 + # ! -1 for good_wo_iap or good_wo_ads or use_psycho_tech means that they don't use it at all! + all_filtered_games = Videogame_common.objects.annotate(number_of_filters=Count('valueforfilter', filter=Q(valueforfilter__filter__is_positive=False))).exclude( number_of_filters = 0).order_by("crapometer")[:100] + # And exclude all that don't respect the rules + remaining_games = [] + nb_of_remaing_games = 0 + + for a_game in all_filtered_games : + all_rating = a_game.videogame_rating_set.all() + will_add = True + for a_rating in all_rating : + if a_rating.gameplay_rating < 80 or a_rating.good_wo_iap < 80 or a_rating.good_wo_ads < 80 or a_rating.use_psycho_tech > 0 : + will_add = False + print(f"Will exclude {a_game.name}") + break + + if will_add : + remaining_games.append(a_game) + + nb_of_remaing_games+=1 + + if nb_of_remaing_games > 40 : + break + + return remaining_games \ No newline at end of file diff --git a/thefiltershop/filtershop_main/views/view_a_game.py b/thefiltershop/filtershop_main/views/view_a_game.py index 7ab5c74..52f5e2f 100644 --- a/thefiltershop/filtershop_main/views/view_a_game.py +++ b/thefiltershop/filtershop_main/views/view_a_game.py @@ -8,22 +8,33 @@ def game(request, videogame_id): a_game = get_object_or_404(Videogame_common, pk=videogame_id) + is_filter = False negative_filters = Filter.objects.filter(valueforfilter__for_entity__pk = a_game.pk, valueforfilter__filter__is_positive=False) positive_filters = Filter.objects.filter(valueforfilter__for_entity__pk = a_game.pk, valueforfilter__filter__is_positive=True) links_to_shops = Links_to_shops.objects.select_related("shop").filter(for_Entity=a_game.pk) ratings = Videogame_rating.objects.select_related("for_platform").filter(Videogame_common=a_game.pk) + if negative_filters.count() + positive_filters.count() > 0 : + is_filter = True + # Now add the filters to the ratings queryset ratings_with_filters = [] for one_rating in ratings.all(): + is_filter_rating = False + negative_filters_this_rating = Filter.objects.filter(filtersforavideogamerating__for_rating__pk = one_rating.pk, filtersforavideogamerating__filter__is_positive=False) positive_filters_this_rating = Filter.objects.filter(filtersforavideogamerating__for_rating__pk = one_rating.pk, filtersforavideogamerating__filter__is_positive=True) - ratings_with_filters.append({"rating" :one_rating, "negative_filters": negative_filters_this_rating, "positive_filters": positive_filters_this_rating}) + if negative_filters_this_rating.count() + positive_filters_this_rating.count() > 0 : + is_filter_rating = True # Mostly useless currently, but good for consistency + is_filter = True # At least one filter to show, so we want the button to appear! + + ratings_with_filters.append({"rating" :one_rating, "negative_filters": negative_filters_this_rating, "positive_filters": positive_filters_this_rating, "is_filter": is_filter_rating}) print(ratings_with_filters) return render(request, "thefiltershop/game.html", {"a_game": a_game, "title_image": a_game.image_set.first(), "screenshots": a_game.image_set.all()[2:], - "negative_filters": negative_filters, "positive_filters": positive_filters, "links_to_shops": links_to_shops.all(), "ratings_with_filters": ratings_with_filters}) + "negative_filters": negative_filters, "positive_filters": positive_filters, "is_filter": is_filter, + "links_to_shops": links_to_shops.all(), "ratings_with_filters": ratings_with_filters}) \ No newline at end of file diff --git a/thefiltershop/filtershop_main/views/view_a_physical_shop.py b/thefiltershop/filtershop_main/views/view_a_physical_shop.py index 069aa80..9825a2d 100644 --- a/thefiltershop/filtershop_main/views/view_a_physical_shop.py +++ b/thefiltershop/filtershop_main/views/view_a_physical_shop.py @@ -6,9 +6,15 @@ def physical_shop(request, shop_id): a_shop = get_object_or_404(Physical_shop, pk=shop_id) + + is_filter = False + negative_filters = Filter.objects.filter(valueforfilter__for_entity__pk = shop_id, valueforfilter__filter__is_positive=False) positive_filters = Filter.objects.filter(valueforfilter__for_entity__pk = shop_id, valueforfilter__filter__is_positive=True) + if negative_filters.count() + positive_filters.count() > 0 : + is_filter = True + return render(request, "thefiltershop/physical_shop.html", {"a_shop": a_shop, - "negative_filters": negative_filters, "positive_filters": positive_filters}) + "negative_filters": negative_filters, "positive_filters": positive_filters, "is_filter": is_filter}) \ No newline at end of file diff --git a/thefiltershop/filtershop_main/views/view_an_online_shop.py b/thefiltershop/filtershop_main/views/view_an_online_shop.py index 33b513d..6ae5c28 100644 --- a/thefiltershop/filtershop_main/views/view_an_online_shop.py +++ b/thefiltershop/filtershop_main/views/view_an_online_shop.py @@ -7,13 +7,19 @@ def online_shop(request, shop_id): a_shop = get_object_or_404(Online_Shop, pk=shop_id) # links_to_shops = a_shop.on_shop.all() + is_filter = False + negative_filters = Filter.objects.filter(valueforfilter__for_entity__pk = shop_id, valueforfilter__filter__is_positive=False) positive_filters = Filter.objects.filter(valueforfilter__for_entity__pk = shop_id, valueforfilter__filter__is_positive=True) + if negative_filters.count() + positive_filters.count() > 0 : + is_filter = True + return render(request, "thefiltershop/online_shop.html", { "a_shop": a_shop, "negative_filters": negative_filters, "positive_filters": positive_filters, # "links_to_shops": links_to_shops + "is_filter": is_filter }) \ No newline at end of file