Browse Source

Move game list around and fix visiblity

Colin Powell 3 năm trước cách đây
mục cha
commit
ac381ffbfc

+ 3 - 1
emus/urls.py

@@ -4,6 +4,7 @@ from django.contrib import admin
 from django.urls import include, path
 from games import urls as games_urls
 from search import urls as search_urls
+from games.views import RecentGameList
 from games.api.views import (
     DeveloperViewSet,
     GameSystemViewSet,
@@ -28,7 +29,8 @@ urlpatterns = [
     path("api-auth/", include("rest_framework.urls")),
     path("api/v1/", include(router.urls)),
     path("search/", include(search_urls, namespace="search")),
-    path("", include(games_urls, namespace="games")),
+    path("games/", include(games_urls, namespace="games")),
+    path("", RecentGameList.as_view(), name="home"),
 ]
 
 if settings.DEBUG:

+ 3 - 8
games/urls.py

@@ -7,16 +7,11 @@ app_name = "games"
 urlpatterns = [
     path(
         "",
-        views.RecentGameList.as_view(),
-        name="game_list",
-    ),
-    path(
-        "library/",
         views.LibraryGameList.as_view(),
-        name="game_library_list",
+        name="game_list",
     ),
     path(
-        "library/update/",
+        "update/",
         views.trigger_rom_update,
         name="game_library_update",
     ),
@@ -61,7 +56,7 @@ urlpatterns = [
         name="game_play_detail",
     ),
     path(
-        "system/<str:slug>/",
+        "game-system/<str:slug>/",
         views.GameSystemDetail.as_view(),
         name="game_system_detail",
     ),

+ 10 - 10
games/views.py

@@ -23,7 +23,7 @@ logger = logging.Logger(__name__)
 IN_PROGRESS_STATES = [states.PENDING, states.STARTED, states.RETRY]
 
 
-class RecentGameList(LoginRequiredMixin, ListView):
+class RecentGameList(ListView):
     model = Game
     paginate_by = 12
     queryset = Game.objects.order_by("-created")[:64]
@@ -48,7 +48,7 @@ class RecentGameList(LoginRequiredMixin, ListView):
         )
 
 
-class LibraryGameList(ListView, LoginRequiredMixin):
+class LibraryGameList(ListView):
     template_name = "games/game_library_list.html"
     model = Game
     paginate_by = 200
@@ -71,7 +71,7 @@ class LibraryGameList(ListView, LoginRequiredMixin):
         return context
 
 
-class FilterableBaseListView(ListView, LoginRequiredMixin):
+class FilterableBaseListView(ListView):
     def get_queryset(self, **kwargs):
         order_by = self.request.GET.get("order_by", "name")
         queryset = super().get_queryset(**kwargs)
@@ -99,7 +99,7 @@ class GenreList(FilterableBaseListView):
     model = Genre
 
 
-class GameDetail(DetailView, LoginRequiredMixin):
+class GameDetail(DetailView):
     model = Game
 
 
@@ -108,11 +108,11 @@ class GamePlayDetail(DetailView, LoginRequiredMixin):
     model = Game
 
 
-class GameSystemList(ListView, LoginRequiredMixin):
+class GameSystemList(ListView):
     model = GameSystem
 
 
-class GameSystemDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
+class GameSystemDetail(DetailView, MultipleObjectMixin):
     model = GameSystem
     paginate_by = 20
 
@@ -124,7 +124,7 @@ class GameSystemDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
         return context
 
 
-class GenreDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
+class GenreDetail(DetailView, MultipleObjectMixin):
     model = Genre
     paginate_by = 20
 
@@ -136,7 +136,7 @@ class GenreDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
         return context
 
 
-class PublisherDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
+class PublisherDetail(DetailView, MultipleObjectMixin):
     model = Publisher
     paginate_by = 20
 
@@ -148,7 +148,7 @@ class PublisherDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
         return context
 
 
-class DeveloperDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
+class DeveloperDetail(DetailView, MultipleObjectMixin):
     model = Developer
     paginate_by = 20
 
@@ -160,7 +160,7 @@ class DeveloperDetail(DetailView, MultipleObjectMixin, LoginRequiredMixin):
         return context
 
 
-class GameCollectionList(ListView, LoginRequiredMixin):
+class GameCollectionList(ListView):
     model = GameCollection
 
 

+ 4 - 2
templates/base.html

@@ -89,10 +89,10 @@
             <div class="collapse navbar-collapse" id="navbarSupportedContent">
                 <ul class="navbar-nav mr-auto">
                 <li class="nav-item">
-                    <a class="nav-link" href="{% url 'games:game_list' %}">Recent<span class="sr-only"></span></a>
+                    <a class="nav-link" href="{% url 'home' %}">Recent<span class="sr-only"></span></a>
                 </li>
                 <li class="nav-item ">
-                    <a class="nav-link" href="{% url 'games:game_library_list' %}">Library<span class="sr-only"></span></a>
+                    <a class="nav-link" href="{% url 'games:game_list' %}">Library<span class="sr-only"></span></a>
                 </li>
                 <li class="nav-item dropdown">
                     <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Systems</a>
@@ -120,6 +120,8 @@
                 </form>
             </div>
             <a class="nav-link" href="{% url 'account_logout' %}">Logout<span class="sr-only"></span></a>
+            {% else %}
+            <a class="nav-link" href="{% url 'account_login' %}">Login<span class="sr-only"></span></a>
             {% endif %}
             </nav>
 

+ 7 - 5
templates/games/_game_card.html

@@ -21,15 +21,17 @@
                 {% endif %}
             </a>
         </div>
-        {% if featured == "true" %}
         <div class="col">
             <div class="card-block px-2">
-                <p class="card-text m-10">{{game.description|markdownify}}</p>
-                <a href="{{game.get_absolute_url}}" class="btn btn-primary">More</a>
-                <a href="{{game.rom_file.url}}" class="btn btn-alert">Download</a>
+                {% if request.user.is_authenticated %}
+                    {% if featured == "true" %}
+                    <p class="card-text m-10">{{game.description|markdownify}}</p>
+                    {% endif %}
+                    <a href="{{game.get_absolute_url}}" class="btn btn-primary">More</a>
+                    <a href="{{game.rom_file.url}}" class="btn btn-alert">Download</a>
+                {% endif %}
             </div>
         </div>
-        {% endif %}
         <div class="card-footer w-100 text-muted">
             <em class="{{game.rating_class}}">{{game.rating_by_100}}/100</em>
             <div id="genre-badges" style="float:right">

+ 5 - 1
templates/games/game_detail.html

@@ -6,7 +6,9 @@
 {% block title %}{{object.name}}{% endblock %}
 
 {% block content %}
+    {% if request.user.is_authenticated %}
     <a href="{% url "games:game_list" %}">Back to list</a>
+    {% endif %}
 
     <p><img src="{{object.screenshot.url}}" /></p>
 
@@ -38,7 +40,8 @@
         <dd>{{game.rating_by_100}}</dd>
     </dl>
 
-    {% if object.webretro_url  %}
+    {% if request.user.is_authenticated %}
+    {% if object.webretro_url %}
     <p><a href="{{game.webretro_url}}" class="btn btn-primary" targe="_blank">Play in browser</a></p>
     {% endif %}
     <h5>Retroarch command</h5>
@@ -51,6 +54,7 @@
             <img src="assets/clippy.svg" alt="Copy to clipboard">
         </button>
     </p>
+    {% endif %}
 
     <p>{{object.description|markdownify}}</p>
 {% endblock %}

+ 3 - 1
templates/games/game_library_list.html

@@ -12,7 +12,7 @@ $(document).ready(function () {
         event.preventDefault();
         console.log("form submitted!")  // sanity check
         $.ajax({
-            url : "/library/update/",
+            url : "/games/update/",
             type : "GET",
             // handle a successful response
             success : function(json) {
@@ -31,10 +31,12 @@ $(document).ready(function () {
 {% endblock %}
 
 {% block content %}
+    {% if request.user.is_authenticated %}
     <form id="library-update-form" class="form-inline my-2 my-lg-0" method="get" action="{% url 'games:game_library_update' %}">
     <button id="library-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update</button>
     </form>
     &nbsp;
+    {% endif %}
 
     {% include "games/_game_table.html" %}
     {% include "games/_pagination.html" %}

+ 3 - 1
templates/games/gamesystem_detail.html

@@ -12,7 +12,7 @@
             console.log('Form submitted');
             event.preventDefault();
             $.ajax({
-                url : '/library/update/?game_systems={{object.retropie_slug}}',
+                url : '/games/update/?game_systems={{object.retropie_slug}}',
                 type : "GET",
                 success : function(json) {
                     $('#{{object.retropie_slug}}-update-form').html("<button id='library-update-btn' class='btn btn-warning my-2 my-sm-0' type='submit' disabled>Update {{object.name}}</button>");
@@ -30,10 +30,12 @@
 {% block content %}
     <h4>Browsing {{object_list.count}} games</h4>
 
+    {% if request.user.is_authenticated %}
     <form id="{{object.retropie_slug}}-update-form" class="my-2 my-lg-0" method="get">
     <button id="{{object.retropie_slug}}-update-btn" class="btn btn-warning my-2 my-sm-0" type="submit" {% if update_in_progress %}disabled{% endif %}>Update {{object.name}}</button>
     </form>
     &nbsp;
+    {% endif %}
 
      <div class="d-flex flex-column">
         <div class="image-grid-container">