My team
This commit is contained in:
parent
ac2790d327
commit
9499e10524
|
@ -1,7 +1,7 @@
|
|||
from django.urls import path
|
||||
from django.views.generic import RedirectView
|
||||
|
||||
from .views import CreateUserView, MyAccountView, UserDetailView,\
|
||||
from .views import CreateUserView, MyAccountView, UserDetailView, MyTeamView,\
|
||||
ProfileListView, OrphanedProfileListView, OrganizersListView, ResetAdminView
|
||||
|
||||
app_name = "member"
|
||||
|
@ -12,7 +12,7 @@ urlpatterns = [
|
|||
path("information/<int:pk>/", UserDetailView.as_view(), name="information"),
|
||||
path("add-team/", RedirectView.as_view(pattern_name="index"), name="add_team"),
|
||||
path("join-team/", RedirectView.as_view(pattern_name="index"), name="join_team"),
|
||||
path("my-team/", RedirectView.as_view(pattern_name="index"), name="my_team"),
|
||||
path("my-team/", MyTeamView.as_view(), name="my_team"),
|
||||
path("my-team/update/", RedirectView.as_view(pattern_name="index"), name="update_my_team"),
|
||||
path("profiles/", ProfileListView.as_view(), name="all_profiles"),
|
||||
path("orphaned-profiles/", OrphanedProfileListView.as_view(), name="orphaned_profiles"),
|
||||
|
|
|
@ -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"])
|
||||
|
|
|
@ -135,10 +135,11 @@ class TeamDetailView(LoginRequiredMixin, DetailView):
|
|||
class TeamUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Team
|
||||
form_class = TeamForm
|
||||
extra_context = dict(title=_("Udpate team"),)
|
||||
extra_context = dict(title=_("Update team"),)
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.admin and self.request.user not in self.get_object().tournament.organizers:
|
||||
if not request.user.admin and self.request.user not in self.get_object().tournament.organizers.all() \
|
||||
and self.get_object() != self.request.user.team:
|
||||
raise PermissionDenied
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
<ul class="navbar-nav">
|
||||
{% if "_fake_user_id" in request.session %}
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="{% url "member:reset_admin" %}?path={{ request.path }}"><i class="fas fa-cog"></i> {% trans "Return to admin view" %}</a>
|
||||
<a class="nav-link" href="{% url "member:reset_admin" %}?path={{ request.path }}"><i class="fas fa-tools"></i> {% trans "Return to admin view" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if not user.is_authenticated %}
|
||||
|
|
|
@ -26,13 +26,17 @@
|
|||
</dl>
|
||||
</div>
|
||||
|
||||
{% if user.admin or user in team.tournament.organizers.all %}
|
||||
{% if user.admin or user in team.tournament.organizers.all or team == user.team %}
|
||||
<div class="card-footer text-center">
|
||||
<a href="{% url "tournament:team_update" pk=team.pk %}"><button class="btn btn-secondary">{% trans "Edit team" %}</button></a>
|
||||
{% if user.admin and team.invalid %}
|
||||
{% if team.invalid %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<button name="delete" class="btn btn-danger">{% trans "Delete team" %}</button>
|
||||
{% if user.admin %}
|
||||
<button name="delete" class="btn btn-danger">{% trans "Delete team" %}</button>
|
||||
{% elif team == user.team %}
|
||||
<button name="leave" class="btn btn-danger">{% trans "Leave this team" %}</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue