mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-18 23:30:20 +02:00
Challenge Update and Create View
This commit is contained in:
21
apps/family/forms.py
Normal file
21
apps/family/forms.py
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django import forms
|
||||
from django.forms.widgets import NumberInput
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note_kfet.inputs import Autocomplete
|
||||
|
||||
from .models import Challenge, FamilyMembership, User
|
||||
|
||||
|
||||
class ChallengeUpdateForm(forms.ModelForm):
|
||||
"""
|
||||
To update a challenge
|
||||
"""
|
||||
class Meta:
|
||||
model = Challenge
|
||||
fields = ('name', 'description', 'points',)
|
||||
widgets = {
|
||||
"points": NumberInput()
|
||||
}
|
@ -26,7 +26,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<a class="btn btn-sm btn-primary" href="{% url "family:challenge_list" %}">
|
||||
{% trans "Return to the challenge list" %}
|
||||
</a>
|
||||
|
||||
{% if update %}
|
||||
<a class="btn btn-sm btn-secondary" href="{% url "family:challenge_update" pk=challenge.pk %}">
|
||||
{% trans "Update" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
21
apps/family/templates/family/challenge_update.html
Normal file
21
apps/family/templates/family/challenge_update.html
Normal file
@ -0,0 +1,21 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
Copyright (C) 2018-2025 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 }}
|
||||
</h3>
|
||||
<div class="card-body" id="form">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<button class="btn btn-primary" type="submit">{% trans "Submit"%}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -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})
|
Reference in New Issue
Block a user