mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-06 07:23:54 +02:00
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
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.views import ProtectQuerysetMixin, ProtectedCreateView
|
|
|
|
from .models import Family, Challenge
|
|
from .tables import FamilyTable, ChallengeTable
|
|
|
|
|
|
class FamilyCreateView(ProtectQuerysetMixin, ProtectedCreateView):
|
|
"""
|
|
Create family
|
|
"""
|
|
model = Family
|
|
extra_context = {"title": _('Create family')}
|
|
|
|
def get_sample_object(self):
|
|
return Family(
|
|
name="",
|
|
description="Sample family",
|
|
score=0,
|
|
rank=0,
|
|
)
|
|
|
|
|
|
class FamilyListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|
"""
|
|
List existing Families
|
|
"""
|
|
model = Family
|
|
table_class = FamilyTable
|
|
extra_context = {"title": _('Families list')}
|
|
|
|
|
|
class FamilyDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
|
"""
|
|
Display details of a family
|
|
"""
|
|
model = Family
|
|
context_object_name = "family"
|
|
extra_context = {"title": _('Family detail')}
|
|
|
|
|
|
class FamilyUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
|
"""
|
|
Update the information of a family.
|
|
"""
|
|
model = Family
|
|
context_object_name = "family"
|
|
extra_context = {"title": _('Update family')}
|
|
|
|
|
|
class ChallengeListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|
"""
|
|
List all challenges
|
|
"""
|
|
model = Challenge
|
|
table_class = ChallengeTable
|
|
extra_context = {"title": _('Challenges list')}
|