Przeglądaj źródła

Update templates and add library view

Colin Powell 3 lat temu
rodzic
commit
e83773abb4

+ 1 - 1
games/admin.py

@@ -4,7 +4,7 @@ from games.models import Developer, Game, GameSystem, Genre, Publisher
 
 
 class GameAdmin(admin.ModelAdmin):
-    list_display = ("name", "game_system", "english_patched", "undub", "region")
+    list_display = ("name", "game_system", "rating", "region")
     list_filter = ("game_system", "undub", "english_patched", "hack")
 
 

+ 3 - 3
games/models.py

@@ -186,10 +186,10 @@ class Game(BaseModel):
     def __str__(self):
         return f"{self.name} for {self.game_system}"
 
-    def rating_by_5(self) -> float:
+    def rating_by_100(self) -> float:
         if self.rating:
-            return 5 * self.rating
-        return 0.0
+            return int(100 * self.rating)
+        return int(0)
 
     def get_absolute_url(self):
         return reverse("games:game_detail", args=[self.slug])

+ 6 - 1
games/urls.py

@@ -10,9 +10,14 @@ app_name = "games"
 urlpatterns = [
     path(
         "",
-        views.GameList.as_view(),
+        views.RecentGameList.as_view(),
         name="game_list",
     ),
+    path(
+        "library/",
+        views.LibraryGameList.as_view(),
+        name="game_library_list",
+    ),
     path(
         "<str:slug>/",
         views.GameDetail.as_view(),

+ 21 - 5
games/views.py

@@ -1,18 +1,34 @@
-from django.shortcuts import render
+from django.db.models import F
 from django.views.generic import DetailView, ListView
-from django.views.generic.base import TemplateView
 from django.views.generic.list import MultipleObjectMixin
 
+from .models import Developer, Game, GameSystem, Genre, Publisher
 
-from .models import Game, GameSystem, Genre, Developer, Publisher
 
-
-class GameList(ListView):
+class RecentGameList(ListView):
     model = Game
     paginate_by = 20
     queryset = Game.objects.order_by("-created")[:20]
 
 
+class LibraryGameList(ListView):
+    template_name = "games/game_library_list.html"
+    model = Game
+    paginate_by = 200
+
+    def get_context_data(self, **kwargs):
+        game_system_slug = self.request.GET.get("game_system")
+        object_list = Game.objects.order_by(F("rating").desc(nulls_last=True))
+        if game_system_slug:
+            object_list = object_list.filter(
+                game_system__retropie_slug=game_system_slug
+            )
+        context = super(LibraryGameList, self).get_context_data(
+            object_list=object_list, **kwargs
+        )
+        return context
+
+
 class GameDetail(DetailView):
     model = Game
 

+ 9 - 4
templates/base.html

@@ -32,13 +32,18 @@
          .card img { width:18em; padding: 1em; }
          .card-block { padding: 1em 0 1em 0; }
          .system-badge { padding: 1em; font-size: normal; }
-         .gba { background: #777777;}
+         .gba { background: #D5D5D5; color:black;}
+         .megadrive { background: #D03737; }
          .virtualboy { background: #99aa11; }
+         .psx { background: #E9DD00; color:black; }
          .ps2 { background:  #111caa; }
          .pcengine { background: #55b4cc; }
-         .gc { background:  #aa11ff; }
-         .snes { background: #bb1111; }
-         .scummvm { background: #cccc11; color:black; }
+         .gc { background:  #7461C7; }
+         .snes { background: #A060C7; }
+         .nds { background: #39D0D0; }
+         .nes { background: #656565; }
+         .n64 { background: #C76660; }
+         .scummvm { background: #E8B500; color:black; }
         </style>
         {% block head_extra %}{% endblock %}
 

+ 1 - 1
templates/games/_game_card.html

@@ -16,7 +16,7 @@
         <a href="{{game.game_system.get_absolute_url}}">
             <span class="system-badge badge badge-success {{game.game_system.retropie_slug}}">{{game.game_system.name|upper}}</span>
         </a>
-        &nbsp;&nbsp;{{game.rating_by_5}}/5
+        &nbsp;&nbsp;{{game.rating_by_100}}/100
 
         <div id="genre-badges" style="float:right">
         {% for genre in game.genre.all %}

+ 3 - 2
templates/games/developer_detail.html

@@ -1,12 +1,13 @@
 {% extends "base.html" %}
+{% block page_title %}{{object.name}} | Developer{% endblock %}
 
 {% block title %}Developer: {{object.name}}{% endblock %}
 
 {% block content %}
-    <h4>{{object.game_set.count}} games</h4>
+    <h4>Browsing {{object_list.count}} games</h4>
      <div class="d-flex flex-column">
         <div class="image-grid-container">
-        {% for  game in object_list.game_set.all %}
+        {% for  game in object_list %}
             {% include "games/_game_card.html" %}
         {% endfor %}
         </div>

+ 10 - 2
templates/games/game_detail.html

@@ -16,7 +16,12 @@
         <dd>{{object.players}}</dd>
 
         <dt>Game System</dt>
-        <dd>{{object.game_system.name}}</dd>
+
+        <dd>
+        <a href="{{game.game_system.get_absolute_url}}">
+            <span class="system-badge badge badge-success {{game.game_system.retropie_slug}}">{{game.game_system.name|upper}}</span>
+        </a>
+        </dd>
 
         <dt>Genre</dt>
         <dd>{% for genre in object.genre.all %}{{genre}}{% if not forloop.last %}, {% endif %}{% endfor %}</dd>
@@ -25,7 +30,10 @@
         <dd>{{object.region}}</dd>
 
         <dt>Publisher/Developer</dt>
-        <dd>{{object.publisher}}/{{object.developer}}</dd>
+        <dd><a href="{{object.publisher.get_absolute_url}}">{{object.publisher}}</a>/<a href="{{object.developer.get_absolute_url}}">{{object.developer}}</a></dd>
+
+        <dt>Rating</dt>
+        <dd>{{game.rating_by_100}}</dd>
     </dl>
 
     <p>{{object.description}}</p>

+ 34 - 0
templates/games/game_library_list.html

@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+{% block page_title %}Game Library{% endblock %}
+
+{% block title %}All games by raitng{% endblock %}
+
+{% block content %}
+    <table class="table table-bordered table">
+    <thead>
+        <tr>
+        <th scope="col">#</th>
+        <th scope="col">Name</th>
+        <th scope="col">System</th>
+        <th scope="col">Rating</th>
+        <th scope="col">Developer</th>
+        <th scope="col">Publisher</th>
+        <th scope="col">Genre</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for  game in object_list %}
+        <tr>
+        <th scope="row"><a href="{{game.get_absolute_url}}">{{game.id}}</a></th>
+        <td>{{game.name}}</td>
+        <td><a href="{{game.game_system.get_absolute_url}}">{{game.game_system}}</td>
+        <td>{{game.rating_by_100}}/100</td>
+        <td><a href="{{game.developer.get_absolute_url}}">{{game.developer}}</a></td>
+        <td><a href="{{game.publisher.get_absolute_url}}">{{game.publisher}}</a></td>
+        <td style="font-size:smaller;">{% for genre in game.genre.all %}<a href="{{genre.get_absolute_url}}">{{genre}}</a>{% if not forloop.last %}, {% endif %}{% endfor %}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+    </table>
+    {% include "games/_pagination.html" %}
+{% endblock %}

+ 1 - 1
templates/games/game_list.html

@@ -6,7 +6,7 @@
      <div class="d-flex flex-column">
         <div class="image-grid-container">
         {% for  game in object_list %}
-	    <h4>{{game.created}}</h4>
+        <h4>{{game.created}}</h4>
             {% include 'games/_game_card.html' %}
         {% endfor %}
         </div>

+ 3 - 2
templates/games/gamesystem_detail.html

@@ -1,12 +1,13 @@
 {% extends "base.html" %}
+{% block page_title %}{{object.name}}{% endblock %}
 
 {% block title %}{{object.name}}{% endblock %}
 
 {% block content %}
-    <h4>Browsing ({{object.game_set.count}}) games</h4>
+    <h4>Browsing {{object_list.count}} games</h4>
      <div class="d-flex flex-column">
         <div class="image-grid-container">
-        {% for  game in object_list.all %}
+        {% for  game in object_list %}
             {% include "games/_game_card.html" %}
         {% endfor %}
         </div>

+ 1 - 0
templates/games/genre_detail.html

@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% block page_title %}Game Library{% endblock %}
 
 {% block title %}Genre: {{object.name}}{% endblock %}
 

+ 3 - 2
templates/games/publisher_detail.html

@@ -1,12 +1,13 @@
 {% extends "base.html" %}
+{% block page_title %}{{object.name}} | Publisher {% endblock %}
 
 {% block title %}Publisher: {{object.name}}{% endblock %}
 
 {% block content %}
-    <h4>{{object.game_set.count}} games</h4>
+    <h4>Browsing {{object_list.count}} games</h4>
      <div class="d-flex flex-column">
         <div class="image-grid-container">
-        {% for  game in object_list.game_set.all %}
+        {% for  game in object_list %}
             {% include "games/_game_card.html" %}
         {% endfor %}
         </div>

+ 2 - 1
templates/search/search.html

@@ -1,6 +1,7 @@
 {% extends "base.html" %}
+{% block page_title %}Search for "{{request.GET.q}}"{% endblock %}
 
-{% block title %}Search for {{request.GET.q}}{% endblock %}
+{% block title %}Search for "{{request.GET.q}}"{% endblock %}
 
 {% block content %}
 {% regroup results by game_system as game_system_list %}