mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-03-14 17:57:39 +00:00
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from hashlib import md5
|
|
|
|
from django.conf import settings
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.core.exceptions import PermissionDenied
|
|
from django.db import transaction
|
|
from django.db.models import F, Q
|
|
from django.http import HttpResponse
|
|
from django.urls import reverse_lazy
|
|
from django.utils import timezone
|
|
from django.utils.decorators import method_decorator
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.views import View
|
|
from django.views.decorators.cache import cache_page
|
|
from django.views.generic import DetailView, TemplateView, UpdateView
|
|
from django.views.generic.list import ListView
|
|
from django_tables2.views import MultiTableMixin, SingleTableMixin, SingleTableView
|
|
from api.viewsets import is_regex
|
|
from note.models import Alias, NoteSpecial, NoteUser
|
|
from permission.backends import PermissionBackend
|
|
from permission.views import ProtectQuerysetMixin, ProtectedCreateView
|
|
|
|
from .models import Wrapped
|
|
from .tables import WrappedTable
|
|
|
|
class WrappedListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
|
"""
|
|
Display all Wrapped, and classify by year
|
|
"""
|
|
model = Wrapped
|
|
table_class = WrappedTable
|
|
template_name = 'wrapped/wrapped_list.html'
|
|
extra_context = {'title': _("List of wrapped")}
|
|
|
|
def get_queryset(self, **kwargs):
|
|
return super().get_queryset(**kwargs).distinct()
|
|
|
|
def get_table_data(self):
|
|
return Wrapped.objects.filter(PermissionBackend.filter_queryset(
|
|
self.request, Wrapped, "change", field='public')).distinct().order_by("-bde__date_start")
|
|
|
|
def get_context_data(self, **kwargs):
|
|
return super().get_context_data(**kwargs)
|
|
|
|
class WrappedDetailView(ProtectQuerysetMixin, DetailView):
|
|
"""
|
|
View a wrapped
|
|
"""
|
|
model = Wrapped
|
|
template_name = 'wrapped/0/wrapped_view.html' #by default
|
|
|
|
def get(self, *args, **kwargs):
|
|
bde_id = Wrapped.objects.get(pk=kwargs['pk']).bde.id
|
|
self.template_name = 'wrapped/' + str(bde_id) + '/wrapped_view.html'
|
|
return super().get(*args, **kwargs)
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
return context
|