mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-18 23:30:20 +02:00
Challenge detail View
This commit is contained in:
@ -30,6 +30,11 @@ class ChallengeTable(tables.Table):
|
|||||||
"""
|
"""
|
||||||
List all challenges
|
List all challenges
|
||||||
"""
|
"""
|
||||||
|
name = tables.LinkColumn(
|
||||||
|
"family:challenge_detail",
|
||||||
|
args=[A("pk")],
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
attrs = {
|
attrs = {
|
||||||
'class': 'table table-condensed table-striped table-hover'
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
@ -37,4 +42,4 @@ class ChallengeTable(tables.Table):
|
|||||||
order_by = ('id',)
|
order_by = ('id',)
|
||||||
model = Challenge
|
model = Challenge
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
fields = ('name', 'points', 'category',)
|
fields = ('name', 'description', 'points',)
|
||||||
|
32
apps/family/templates/family/challenge_detail.html
Normal file
32
apps/family/templates/family/challenge_detail.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% comment %}
|
||||||
|
Copyright (C) by BDE ENS Paris-Saclay
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
{% endcomment %}
|
||||||
|
{% load i18n crispy_forms_tags %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="card bg-white mb-3">
|
||||||
|
<h3 class="card-header text-center">
|
||||||
|
{{ title }} {{ challenge.name }}
|
||||||
|
</h3>
|
||||||
|
<div class="card-body">
|
||||||
|
<ul>
|
||||||
|
{% for field, value in fields %}
|
||||||
|
<li> {{ field }} : {{ value }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
<li> {% trans "Obtained by " %} {{obtained}}
|
||||||
|
{% if obtained > 1 %}
|
||||||
|
{% trans "families" %}
|
||||||
|
{% else %}
|
||||||
|
{% trans "family" %}
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<a class="btn btn-sm btn-primary" href="{% url "family:challenge_list" %}">
|
||||||
|
{% trans "Return to the challenge list" %}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
5
apps/family/templates/family/family_detail.html
Normal file
5
apps/family/templates/family/family_detail.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% comment %}
|
||||||
|
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||||
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
{% endcomment %}
|
@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import FamilyListView, ChallengeListView
|
from .views import FamilyListView, FamilyDetailView, ChallengeListView, ChallengeDetailView, ChallengeUpdateView
|
||||||
|
|
||||||
app_name = 'family'
|
app_name = 'family'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('list/', FamilyListView.as_view(), name="family_list"),
|
path('list/', FamilyListView.as_view(), name="family_list"),
|
||||||
|
path('detail/<int:pk>/', FamilyDetailView.as_view(), name="family_detail"),
|
||||||
path('challenge/list/', ChallengeListView.as_view(), name="challenge_list"),
|
path('challenge/list/', ChallengeListView.as_view(), name="challenge_list"),
|
||||||
|
path('challenge/detail/<int:pk>/', ChallengeDetailView.as_view(), name="challenge_detail"),
|
||||||
|
path('challenge/update/<int:pk>/', ChallengeUpdateView.as_view(), name="challenge_update"),
|
||||||
]
|
]
|
||||||
|
@ -5,6 +5,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
|||||||
from django.views.generic import DetailView, UpdateView
|
from django.views.generic import DetailView, UpdateView
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
|
from permission.backends import PermissionBackend
|
||||||
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
||||||
|
|
||||||
from .models import Family, Challenge
|
from .models import Family, Challenge
|
||||||
@ -54,6 +55,21 @@ class FamilyUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
|||||||
extra_context = {"title": _('Update family')}
|
extra_context = {"title": _('Update family')}
|
||||||
|
|
||||||
|
|
||||||
|
class ChallengeCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||||
|
"""
|
||||||
|
Create challenge
|
||||||
|
"""
|
||||||
|
model = Challenge
|
||||||
|
extra_context = {"title": _('Create challenge')}
|
||||||
|
|
||||||
|
def get_sample_object(self):
|
||||||
|
return Challenge(
|
||||||
|
name="",
|
||||||
|
description="Sample challenge",
|
||||||
|
points=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
"""
|
"""
|
||||||
List all challenges
|
List all challenges
|
||||||
@ -61,3 +77,35 @@ class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVie
|
|||||||
model = Challenge
|
model = Challenge
|
||||||
table_class = ChallengeTable
|
table_class = ChallengeTable
|
||||||
extra_context = {"title": _('Challenges list')}
|
extra_context = {"title": _('Challenges list')}
|
||||||
|
|
||||||
|
|
||||||
|
class ChallengeDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||||
|
"""
|
||||||
|
Display details of a challenge
|
||||||
|
"""
|
||||||
|
model = Challenge
|
||||||
|
context_object_name = "challenge"
|
||||||
|
extra_context = {"title": _('Details of:')}
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
fields = ["name", "description", "points",]
|
||||||
|
|
||||||
|
fields = dict([(field, getattr(self.object, field)) for field in fields])
|
||||||
|
|
||||||
|
context["fields"] = [(
|
||||||
|
Challenge._meta.get_field(field).verbose_name.capitalize(),
|
||||||
|
value) for field, value in fields.items()]
|
||||||
|
context["obtained"] = getattr(self.object, "obtained")
|
||||||
|
context["update"] = PermissionBackend.check_perm(self.request, "family.change_challenge")
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
class ChallengeUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
"""
|
||||||
|
Update the information of a challenge
|
||||||
|
"""
|
||||||
|
model = Challenge
|
||||||
|
context_object_name = "challenge"
|
||||||
|
extra_context = {"title": _('Update challenge')}
|
||||||
|
template_name = 'family/challenge_update.html'
|
||||||
|
Reference in New Issue
Block a user