Skip to content

Commit

Permalink
Working search, missing studio and publisher view (TBD)
Browse files Browse the repository at this point in the history
  • Loading branch information
abecam committed Jun 16, 2024
1 parent 4881ad4 commit f993126
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</div>
<div class="search_input">
<img width="40" src="{% static 'images/Search.png' %}" alt="Search">
<form action="/search_game/" method="get">
<input id="search" name="search" type="text" value="" minlength="3" required />
<form action="/videogames_search/" method="get">
<input id="keywords" name="keywords" type="text" value="" minlength="3" required />
<input type="submit" hidden />
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{% extends "thefiltershop/base_games.html" %}

{% block title %}Search results{% endblock %}

{% block title_content %}Search results{% endblock %}

{% block content %}

<h2>Artisans' Games</h2>
<div class="grid-container">

{% for game in artisan_games %}
<div class="game-card">
<a href="{% url 'filtershop_games:game' game.id %}" class="image_link">
<div class='game-card-content'>
<img src="{{game.vignette.url}}" alt="{{game.name}}"/>

<p>{{ game.description }}</p>
</div>
</a>
<div style="row-container">
{% for category in game.categories.all %}
<a class="badge" href="{% url 'filtershop_games:artisans_games' %}?category_id={{ category.id }}">{{ category.name }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
<br/>
</div>

<h2>Indies' Games</h2>
<div class="grid-container">

{% for game in indie_games %}
<div class="game-card">
<a href="{% url 'filtershop_games:game' game.id %}" class="image_link">
<div class='game-card-content'>
<img src="{{game.vignette.url}}" alt="{{game.name}}"/>

<p>{{ game.description }}</p>
</div>
</a>
<div style="row-container">
{% for category in game.categories.all %}
<a class="badge" href="{% url 'filtershop_games:artisans_games' %}?category_id={{ category.id }}">{{ category.name }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
<br/>
</div>

<h2>Other Games</h2>
<div class="grid-container">

{% for game in other_games %}
<div class="game-card">
<a href="{% url 'filtershop_games:game' game.id %}" class="image_link">
<div class='game-card-content'>
<img src="{{game.vignette.url}}" alt="{{game.name}}"/>

<p>{{ game.description }}</p>
</div>
</a>
<div style="row-container">
{% for category in game.categories.all %}
<a class="badge" href="{% url 'filtershop_games:artisans_games' %}?category_id={{ category.id }}">{{ category.name }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
<br/>
</div>

<h2>Studios</h2>
<div class="grid-container">

{% for game in studios %}
<div class="game-card">
<a href="{% url 'filtershop_games:game' game.id %}" class="image_link">
<div class='game-card-content'>
<img src="{{game.vignette.url}}" alt="{{game.name}}"/>

<p>{{ game.description }}</p>
</div>
</a>
<div style="row-container">
{% for category in game.categories.all %}
<a class="badge" href="{% url 'filtershop_games:artisans_games' %}?category_id={{ category.id }}">{{ category.name }}</a>
{% endfor %}
</div>
</div>
{% endfor %}
<br/>
</div>

<h2>Publishers</h2>
<div class="grid-container">

{% for game in publishers %}
<div class="game-card">
<a href="{% url 'filtershop_games:game' game.id %}" class="image_link">
<div class='game-card-content'>
<img src="{{game.vignette.url}}" alt="{{game.name}}"/>

<p>{{ game.description }}</p>
</div>
</a>
</div>
{% endfor %}
<br/>
</div>

<h2>Filters</h2>
<div class="grid-container">

{% for one_filter in filters %}
<div class="game-card">
<a href="{% url 'filtershop_games:one_filter' one_filter.id %}" class="image_link">
<div class='game-card-content'>
{{one_filter.name}}

<p>{{ one_filter.description }}</p>
</div>
</a>
</div>
{% endfor %}
<br/>
</div>

{% endblock %}
1 change: 1 addition & 0 deletions thefiltershop/filtershop_main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
path("physical_shop_filters", views.get_all_filters_for_an_entity_type_physical_shop, name="physical_shop_filters"),
path("a_random_artisan_game", views.get_a_random_unfiltered_artisan_game, name="a_random_artisan_game"),
path("a_random_indie_game", views.get_a_random_unfiltered_indie_game, name="a_random_indie_game"),
path("videogames_search/", views.get_search_results, name="videogames_search"),
path("four_o_four", TemplateView.as_view(template_name="404.html"), name="404"),
#path('admin/', admin_site.urls),
]
3 changes: 2 additions & 1 deletion thefiltershop/filtershop_main/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
from .list_shops import get_others_physical_shops
from .list_shops import get_artisans_and_indies_physical_shops_that_made_it
from .list_games import get_a_random_unfiltered_artisan_game
from .list_games import get_a_random_unfiltered_indie_game
from .list_games import get_a_random_unfiltered_indie_game
from .videogames_search import get_search_results
44 changes: 27 additions & 17 deletions thefiltershop/filtershop_main/views/videogames_search.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import random
import re

from django.shortcuts import render
from django.db.models import Q
from django.db.models import Count
from django.core.paginator import Paginator

from .view_a_game import game

from ..models import Videogame_common, Game_Category, Studio, Publisher
from ..models import Videogame_common, Studio, Publisher, Filter

"""Search view for the video game category
Expand All @@ -19,13 +21,21 @@ def get_search_results(request):

# Get the keywords from the string
# TODO: support AND/OR and others
keywords = request.GET.get('keywords')
keywords_txt = request.GET.get('keywords')

# Split using space or comma
keywords_not_curated = re.split(r';|,|\s', keywords_txt)
# Remove if too short

for k, v in list(keywords.items()):
if len(v[0] < 3):
keywords = []

for one_keyword in keywords_not_curated:
one_keyword = one_keyword.strip()
if len(one_keyword) >= 3 :
keywords.append(one_keyword)
print(f"One keyword {one_keyword}")
else :
was_one_short_keyword = True
del keywords[k]

if len(keywords) == 0 :
if was_one_short_keyword :
Expand All @@ -42,7 +52,7 @@ def get_search_results(request):

found_indie_games = get_all_games_for_keywords(keywords, Studio.SizeInPersons.INDIE)

found_other_games = get_all_games_for_keywords(keywords, Studio.SizeInPersons.MEDIUM) + get_all_games_for_keywords(keywords, Studio.SizeInPersons.BIG) + get_all_games_for_keywords(keywords, Studio.SizeInPersons.HUGE)
found_other_games = get_all_games_for_keywords(keywords, Studio.SizeInPersons.MEDIUM) | get_all_games_for_keywords(keywords, Studio.SizeInPersons.BIG) | get_all_games_for_keywords(keywords, Studio.SizeInPersons.HUGE)

found_studios = get_all_studios_for_keywords(keywords)

Expand All @@ -54,7 +64,7 @@ def get_search_results(request):
# The paginator cannot be used as we have several querysets. It might need to be addressed if the returned sets are too long.
context = {"artisan_games": found_artisan_games, "indie_games": found_indie_games, "other_games": found_other_games, "studios": found_studios, "publishers": found_publishers, "filters": found_filters}

return render(request, "thefiltershop/search_results.html", context)
return render(request, "thefiltershop/vg_search_results.html", context)



Expand All @@ -63,51 +73,51 @@ def get_all_games_for_keywords(keywords, max_size_of_studio) :
raise TypeError('max_size_of_studio_or_publisher must be a Studio_and_Publisher_Size')

# Build-up the query string for keywords
q_keyword = Q(Videogame_common.name__startswith(keywords[0]))
q_keyword = Q(name__icontains = keywords[0])

if len(keywords) > 1 :
for one_keyword in keywords[1:] :
q_keyword = q_keyword | Q(Videogame_common.name__startswith(one_keyword))
q_keyword = q_keyword | Q(name__icontains = one_keyword)

if max_size_of_studio != Studio.SizeInPersons.ARTISAN :
# No filter on publisher size for non-artisan
all_for_size = Videogame_common.objects.filter(studios__size_of_studio = max_size_of_studio).filter(q_keyword).order_by("known_popularity")
else :
all_for_size = Videogame_common.objects.filter(studios__size_of_studio = Studio.SizeInPersons.ARTISAN, publishers__size_of_publisher = Publisher.SizeInPersons.ARTISAN).filter(q_keyword).order_by("known_popularity")

print(all_for_size.query)
return all_for_size

def get_all_studios_for_keywords(keywords) :
# Build-up the query string for keywords
q_keyword = Q(Studio.name__startswith(keywords[0]))
q_keyword = Q(name__icontains = keywords[0])

if len(keywords) > 1 :
for one_keyword in keywords[1:] :
q_keyword = q_keyword | Q(Studio.name__startswith(one_keyword))
q_keyword = q_keyword | Q(name__icontains = one_keyword)

all_for_keyword = Studio.objects.filter(q_keyword)

return all_for_keyword

def get_all_publishers_for_keywords(keywords) :
# Build-up the query string for keywords
q_keyword = Q(Publisher.name__startswith(keywords[0]))
q_keyword = Q(name__icontains = keywords[0])

if len(keywords) > 1 :
for one_keyword in keywords[1:] :
q_keyword = q_keyword | Q(Publisher.name__startswith(one_keyword))
q_keyword = q_keyword | Q(name__icontains = one_keyword)

all_for_keyword = Publisher.objects.filter(q_keyword)

return all_for_keyword

def get_all_filters_for_keywords(keywords) :
# Build-up the query string for keywords
q_keyword = Q(Filter.name__startswith(keywords[0]))
q_keyword = Q(name__icontains = keywords[0])

if len(keywords) > 1 :
for one_keyword in keywords[1:] :
q_keyword = q_keyword | Q(Filter.name__startswith(one_keyword))
q_keyword = q_keyword | Q(name__icontains = one_keyword)

all_for_keyword = Filter.objects.filter(q_keyword)

Expand Down
14 changes: 14 additions & 0 deletions thefiltershop/filtershop_main/views/view_a_studio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404

from ..models import Videogame_common
from ..models import Filter
from ..models import Links_to_shops
from ..models import Videogame_rating
from ..models import Studio

def studio(request, studio_id):
a_studio = get_object_or_404(Studio, pk=studio_id)

return render(request, "thefiltershop/studio.html", {"a_studio": a_studio)

0 comments on commit f993126

Please sign in to comment.