Skip to content

Commit

Permalink
Added best of the rest view
Browse files Browse the repository at this point in the history
Do not show the toggle filter pos button when there is no filters.
  • Loading branch information
abecam committed Oct 13, 2023
1 parent beb2569 commit e046c3e
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 14 deletions.
2 changes: 2 additions & 0 deletions thefiltershop/filtershop_main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="Sub-Menu">
<!-- Glametrix Bold --><a href="/">Under the spotlight!</a> <a href="{% url 'filtershop_games:artisans_games' %}">Artisan's games</a> <a href="{% url 'filtershop_games:indies_games' %}">Indie's games</a>
<a href="{% url 'filtershop_games:game_filters' %}">Filters for games</a> <a href="{% url 'filtershop_games:they_made_it' %}">They made it!</a>
<a href="{% url 'filtershop_games:they_made_it' %}">Best of the rest...</a>
<a href="{% url 'filtershop_games:best_of_the_rest' %}">Best of the rest...</a>
</div>

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "thefiltershop/base_games.html" %}

{% block title %}Best of the rest{% endblock %}

{% block content %}
<br/>
<h2>All these game could be good if...</h2>

{% include "thefiltershop/partials/list_of_games.html" with page_obj=page_obj%}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<h1>
<img src="{{title_image.photo.url}}"" alt="{{a_game.name}}" class="game_title_image">
Expand Down Expand Up @@ -45,7 +45,7 @@ <h1>
{% endfor %}
</div>

{% 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 %}

<!-- Ratings for the game, including filters as well -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<div class="single_shop_view">
<div>
Expand Down Expand Up @@ -51,6 +51,6 @@ <h1>All games from : {{a_shop.name}}</h1>
</div>


{% 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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
}
</script>
{% if is_on_top and not no_button %}
{% if is_on_top and is_filter and not no_button %}
<button class="button_toggle_filters_pos" onclick="toggleVisibilityFilters('event')" id="button_toggle_filters_pos">Show filters at the end</button>
{% endif %}
<div class="filters">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h2>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 %}</h2>

{% 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 %}

<div class="grid-container">
<div class="grid-item">{{ a_rating_with_filters.rating.f2play | yesno:"F2P,Premium"}}</div>
Expand All @@ -27,6 +27,6 @@ <h2>Present on {{ a_rating_with_filters.rating.for_platform.name }}{% if a_ratin
<div class="info_would_be_good">{{ a_rating_with_filters.rating.would_be_good_if }}</div>
<div class="info_could_be_good">{{ a_rating_with_filters.rating.could_be_good_if }}</div>

{% 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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<h1>
<img src="{{a_shop.vignette.url}}"" alt="{{a_shop.name}}" width="400px" class="shop_logo">
Expand Down Expand Up @@ -34,6 +34,6 @@ <h1>
{% endfor %}
</div>

{% 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 %}
1 change: 1 addition & 0 deletions thefiltershop/filtershop_main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
path("game_filters", views.get_all_filters_for_an_entity_type_videogame, name="game_filters"),
path("one_filter/<int:filter_id>/", 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/<int:shop_id>/", views.physical_shop, name="physical_shop"),
path("index_physical_shops", views.index_physical_shops, name="index_physical_shops"),
Expand Down
1 change: 1 addition & 0 deletions thefiltershop/filtershop_main/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 42 additions & 1 deletion thefiltershop/filtershop_main/views/list_games.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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
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
15 changes: 13 additions & 2 deletions thefiltershop/filtershop_main/views/view_a_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

8 changes: 7 additions & 1 deletion thefiltershop/filtershop_main/views/view_a_physical_shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})

6 changes: 6 additions & 0 deletions thefiltershop/filtershop_main/views/view_an_online_shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

0 comments on commit e046c3e

Please sign in to comment.