Skip to content

Commit

Permalink
Refactoring for better clarity, and removable of obsolete code.
Browse files Browse the repository at this point in the history
  • Loading branch information
abecam committed Sep 30, 2023
1 parent ca49005 commit 876d0f0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
6 changes: 3 additions & 3 deletions thefiltershop/filtershop_main/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .main import index
from .main import game
from .main import index_online_shops
from .main import online_shop
from .viewAGame import game
from .indexOnlineShop import index_online_shops
from .indexOnlineShop import online_shop
14 changes: 14 additions & 0 deletions thefiltershop/filtershop_main/views/indexOnlineShop.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 Online_Shop

# TODO: pushed in a different file
def index_online_shops(request):
latest_shops = Online_Shop.objects.order_by("-date_creation")[:5]
context = {"latest_shops": latest_shops}
return render(request, "thefiltershop/index_online_shops.html", context)

def online_shop(request, shop_id):
a_game = get_object_or_404(Online_Shop, pk=shop_id)
return render(request, "thefiltershop/online_shop.html", {"a_shop": a_game})
23 changes: 3 additions & 20 deletions thefiltershop/filtershop_main/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from django.db.models import Q
from django.db.models import Max
from django.db.models import Count
from django.views.generic import ListView

from datetime import datetime, timedelta, timezone
from logging import Logger

from ..models import Videogame_common
from ..models import Filter
from ..models import Publisher
from ..models import Studio
from ..models import Online_Shop

from filtershop_main.constants import SPOTLIGHT_LIMIT
from filtershop_main.constants import Studio_and_Publisher_Size
Expand Down Expand Up @@ -90,22 +91,4 @@ def get_game_for_spotlight(max_size_of_studio_or_publisher) :
else :
# No game available...
game_in_spotlight = None
return game_in_spotlight
# To do:
#
def game(request, videogame_id):
a_game = get_object_or_404(Videogame_common, pk=videogame_id)
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)

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})

def index_online_shops(request):
latest_shops = Online_Shop.objects.order_by("-date_creation")[:5]
context = {"latest_shops": latest_shops}
return render(request, "thefiltershop/index_online_shops.html", context)

def online_shop(request, shop_id):
a_game = get_object_or_404(Online_Shop, pk=shop_id)
return render(request, "thefiltershop/online_shop.html", {"a_shop": a_game})
return game_in_spotlight
23 changes: 9 additions & 14 deletions thefiltershop/filtershop_main/views/viewAGame.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404

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

def index(request):
# For small studio first
#smallest_studio = Studio.objects.order_by("-known_popularity").order_by("-spotlight_count")[:5]
def game(request, videogame_id):
a_game = get_object_or_404(Videogame_common, pk=videogame_id)
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)

# also with no publisher or a small one
# Find the game with lowest time in the spotlight, and the fewer (bad) filters. Give a bonus for good filters
latest_games = Videogame_common.objects.filter(Videogame_common.studios_set__size <= 5).filter(Videogame_common.publishers_set__size <= 5).order_by("-known_popularity").order_by("-spotlight_count")[:5]
for aGame in latest_games:
aGame.spotlight_count+=1
aGame.save()

context = {"latest_games": latest_games}
return render(request, "thefiltershop/index.html", context)
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})

0 comments on commit 876d0f0

Please sign in to comment.