mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-05 02:24:08 +02:00
My team
This commit is contained in:
@ -9,7 +9,8 @@ from django.views import View
|
||||
from django.views.generic import CreateView, UpdateView, DetailView
|
||||
from django_tables2 import SingleTableView
|
||||
|
||||
from tournament.views import AdminMixin
|
||||
from tournament.models import Team
|
||||
from tournament.views import AdminMixin, TeamMixin
|
||||
from .forms import SignUpForm, TFJMUserForm
|
||||
from .models import TFJMUser, Document
|
||||
from .tables import UserTable
|
||||
@ -64,6 +65,30 @@ class UserDetailView(LoginRequiredMixin, DetailView):
|
||||
return context
|
||||
|
||||
|
||||
class MyTeamView(TeamMixin, DetailView):
|
||||
model = Team
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.request.user.team
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if isinstance(request.user, AnonymousUser):
|
||||
raise PermissionDenied
|
||||
|
||||
team = self.get_object()
|
||||
|
||||
if not request.user.participates or team is None:
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context["title"] = str(self.object)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class DocumentView(LoginRequiredMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
doc = Document.objects.get(file=self.kwargs["file"])
|
||||
|
Reference in New Issue
Block a user