Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add admin trophy overview.
Roland Geiderdd2ecbd32e6d
diff --git a/wger/core/fixtures/groups.json b/wger/core/fixtures/groups.jsonindex 63cf32936..53a22fffc 100644--- a/wger/core/fixtures/groups.json+++ b/wger/core/fixtures/groups.json@@ -287,6 +287,21 @@"delete_weightunit","nutrition","weightunit"+ ],+ [+ "add_trophy",+ "trophies",+ "trophy"+ ],+ [+ "change_trophy",+ "trophies",+ "trophy"+ ],+ [+ "delete_trophy",+ "trophies",+ "trophy"]]},diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.htmlindex bfcd8c6c4..bd65504f7 100644--- a/wger/core/templates/navigation.html+++ b/wger/core/templates/navigation.html@@ -395,6 +395,16 @@</li>{% endif %}{% endif %}++ {% if perms.trophies.change_trophy %}+ <li>+ <a class="dropdown-item"+ href="{% url 'trophies:admin-overview' %}">+ {% translate "Trophies" %}+ </a>+ </li>+ {% endif %}+{% endif %}</ul></li>diff --git a/wger/trophies/templates/trophies/overview.html b/wger/trophies/templates/trophies/overview.htmlnew file mode 100644index 000000000..be92f4601--- /dev/null+++ b/wger/trophies/templates/trophies/overview.html@@ -0,0 +1,53 @@+{% extends "base_wide.html" %}+{% load i18n static wger_extras %}++{# #}+{# Title #}+{# #}+{% block title %}{% translate "Trophies" %}{% endblock %}+++{# #}+{# Content #}+{# #}+{% block content %}+<p>All trophies currently in the system</p>++<div class="row row-cols-sm-2 row-cols-md-4 row-cols-lg-6 g-4">+{% for trophy in trophy_list %}+ <div class="col">+ <div class="card h-100" style="min-width: 12rem;">+ <img src="{% static trophy.image_rel_path %}" class="card-img-top" alt="..." style="padding: 1rem;">+ <div class="card-body">+ <h5 class="card-title">+ {% if not trophy.is_active %}<s>{% endif %}+ {{ trophy.name }}+ {% if not trophy.is_active %}</s>{% endif %}+ </h5>+ <p class="card-text">+ {% if not trophy.is_active %}<s>{% endif %}+ {{ trophy.description }}+ {% if not trophy.is_active %}</s>{% endif %}+ </p>+ </div>+ <ul class="list-group list-group-flush">+ <li class="list-group-item">Type: {{ trophy.trophy_type }}</li>+ <li class="list-group-item">Hidden: {{ trophy.is_hidden }}</li>+ <li class="list-group-item">Progressive: {{ trophy.is_progressive }}</li>+ </ul>+ <div class="card-footer text-body-secondary">+ Awarded {{ trophy.user_trophies.count }} times+ </div>++ </div>+ </div>+{% endfor %}+</div>+{% endblock %}+++{# #}+{# Options #}+{# #}+{% block options %}+{% endblock %}diff --git a/wger/trophies/tests/test_overview.py b/wger/trophies/tests/test_overview.pynew file mode 100644index 000000000..5d57d08b9--- /dev/null+++ b/wger/trophies/tests/test_overview.py@@ -0,0 +1,45 @@+# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++# Standard Library+import logging++# wger+from wger.core.tests.base_testcase import WgerAccessTestCase++logger = logging.getLogger(__name__)+++class TrophiesOverviewTestCase(WgerAccessTestCase):+ """+ Test case for the trophies overview page+ """+ url = 'trophies:admin-overview'+ anonymous_fail = True+ user_success = 'admin'+ user_fail = (+ 'manager1',+ 'manager2',+ 'general_manager1',+ 'manager3',+ 'manager4',+ 'test',+ 'member1',+ 'member2',+ 'member3',+ 'member4',+ 'member5',+ )++diff --git a/wger/trophies/urls.py b/wger/trophies/urls.pyindex 59d698c52..5b5b8de40 100644--- a/wger/trophies/urls.py+++ b/wger/trophies/urls.py@@ -19,6 +19,8 @@ from django.urls import re_path# wgerfrom wger.core.views.react import ReactView+# Local+from .views import TrophiesOverviewurlpatterns = [re_path(@@ -26,4 +28,9 @@ urlpatterns = [ReactView.as_view(),name='overview',),+ re_path(+ 'admin/overview/',+ TrophiesOverview.as_view(),+ name='admin-overview',+ ),]diff --git a/wger/trophies/views.py b/wger/trophies/views.pynew file mode 100644index 000000000..a559930fe--- /dev/null+++ b/wger/trophies/views.py@@ -0,0 +1,47 @@+# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++# Standard Library+import logging++# Django+from django.contrib.auth.mixins import (+ LoginRequiredMixin,+ PermissionRequiredMixin,+)+from django.views.generic import ListView++# wger+from wger.trophies.models import Trophy++logger = logging.getLogger(__name__)+++class TrophiesOverview(LoginRequiredMixin, PermissionRequiredMixin, ListView):+ """+ All available trophies (even hidden ones).++ This is mainly to check that the descriptions, images, etc. are correct without having+ to earn them.+ """++ model = Trophy+ template_name = 'trophies/overview.html'+ permission_required = 'trophies.change_trophy'++ def get_queryset(self):+ """+ Return only the weight entries for the current user+ """+ return Trophy.objects.all()