mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-23 12:36:35 +02:00
Create team detail page
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_save
|
||||
|
||||
|
||||
class ParticipationConfig(AppConfig):
|
||||
name = 'participation'
|
||||
|
||||
def ready(self):
|
||||
from participation.signals import create_team_participation
|
||||
post_save.connect(create_team_participation, "participation.Team")
|
||||
|
5
apps/participation/signals.py
Normal file
5
apps/participation/signals.py
Normal file
@ -0,0 +1,5 @@
|
||||
from participation.models import Participation
|
||||
|
||||
|
||||
def create_team_participation(instance, **_):
|
||||
Participation.objects.get_or_create(team=instance)
|
34
apps/participation/templates/participation/team_detail.html
Normal file
34
apps/participation/templates/participation/team_detail.html
Normal file
@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
{% trans "any" as any %}
|
||||
|
||||
<div class="card bg-light shadow">
|
||||
<div class="card-header text-center">
|
||||
<h4>{{ team.name }}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-sm-6 text-right">{% trans "Name:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.name }}</dd>
|
||||
|
||||
<dt class="col-sm-6 text-right">{% trans "Trigram:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.trigram }}</dd>
|
||||
|
||||
<dt class="col-sm-6 text-right">{% trans "Access code:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.access_code }}</dd>
|
||||
|
||||
<dt class="col-sm-6 text-right">{% trans "Coachs:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.coachs.all|join:", "|default:any }}</dd>
|
||||
|
||||
<dt class="col-sm-6 text-right">{% trans "Participants:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.students.all|join:", "|default:any }}</dd>
|
||||
|
||||
<dt class="col-sm-6 text-right">{% trans "Chosen problem:" %}</dt>
|
||||
<dd class="col-sm-6">{{ team.participation.problem|default:any }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,6 +1,6 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import CreateTeamView, JoinTeamView
|
||||
from .views import CreateTeamView, JoinTeamView, MyTeamDetailView, TeamDetailView
|
||||
|
||||
|
||||
app_name = "participation"
|
||||
@ -8,4 +8,6 @@ app_name = "participation"
|
||||
urlpatterns = [
|
||||
path("create_team/", CreateTeamView.as_view(), name="create_team"),
|
||||
path("join_team/", JoinTeamView.as_view(), name="join_team"),
|
||||
path("team/", MyTeamDetailView.as_view(), name="my_team_detail"),
|
||||
path("team/<int:pk>/", TeamDetailView.as_view(), name="team_detail"),
|
||||
]
|
||||
|
@ -1,8 +1,9 @@
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, FormView
|
||||
from django.views.generic import CreateView, FormView, DetailView, RedirectView
|
||||
|
||||
from participation.forms import TeamForm, JoinTeamForm
|
||||
from participation.models import Team
|
||||
@ -58,3 +59,18 @@ class JoinTeamView(LoginRequiredMixin, FormView):
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("index")
|
||||
|
||||
|
||||
class MyTeamDetailView(LoginRequiredMixin, RedirectView):
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
user = self.request.user
|
||||
registration = user.registration
|
||||
if registration.participates:
|
||||
if registration.team:
|
||||
return reverse_lazy("participation:team_detail", args=(registration.team_id,))
|
||||
raise PermissionDenied(_("You are not in a team."))
|
||||
raise PermissionDenied(_("You don't participate, so you don't have any team."))
|
||||
|
||||
|
||||
class TeamDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Team
|
||||
|
Reference in New Issue
Block a user