1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-07-21 08:29:11 +02:00

Challenge Update and Create View

This commit is contained in:
Ehouarn
2025-07-17 16:59:57 +02:00
parent 6f4fbecdd0
commit 3ebadf34bc
4 changed files with 62 additions and 3 deletions

View File

@ -1,15 +1,19 @@
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from datetime import date
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import DetailView, UpdateView
from django.utils.translation import gettext_lazy as _
from django_tables2 import SingleTableView
from permission.backends import PermissionBackend
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
from django.urls import reverse_lazy
from .models import Family, Challenge
from .tables import FamilyTable, ChallengeTable
from .models import Family, Challenge, FamilyMembership, User
from .tables import FamilyTable, ChallengeTable, FamilyMembershipTable
from .forms import ChallengeUpdateForm
class FamilyCreateView(ProtectQuerysetMixin, ProtectedCreateView):
@ -68,6 +72,9 @@ class ChallengeCreateView(ProtectQuerysetMixin, ProtectedCreateView):
description="Sample challenge",
points=0,
)
def get_success_url(self):
return reverse_lazy('family:challenge_list')
class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
@ -101,6 +108,7 @@ class ChallengeDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
return context
class ChallengeUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
"""
Update the information of a challenge
@ -109,3 +117,8 @@ class ChallengeUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
context_object_name = "challenge"
extra_context = {"title": _('Update challenge')}
template_name = 'family/challenge_update.html'
form_class = ChallengeUpdateForm
def get_success_url(self, **kwargs):
self.object.refresh_from_db()
return reverse_lazy('family:challenge_detail', kwargs={'pk': self.object.pk})