mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-24 03:48:45 +02:00
Display popups to create and join team
This commit is contained in:
28
apps/participation/forms.py
Normal file
28
apps/participation/forms.py
Normal file
@ -0,0 +1,28 @@
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .models import Team
|
||||
|
||||
|
||||
class TeamForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ('name', 'trigram', 'grant_animath_access_videos',)
|
||||
|
||||
|
||||
class JoinTeamForm(forms.ModelForm):
|
||||
def clean_access_code(self):
|
||||
access_code = self.cleaned_data["access_code"]
|
||||
if not Team.objects.filter(access_code=access_code).exists():
|
||||
raise ValidationError("No team was found with this access code.")
|
||||
return access_code
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
if "access_code" in cleaned_data:
|
||||
self.instance = Team.objects.get(access_code=cleaned_data["access_code"])
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = Team
|
||||
fields = ('access_code',)
|
13
apps/participation/templates/participation/create_team.html
Normal file
13
apps/participation/templates/participation/create_team.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
</div>
|
||||
<button class="btn btn-success" type="submit">{% trans "Create" %}</button>
|
||||
</form>
|
||||
{% endblock content %}
|
@ -0,0 +1,21 @@
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
<div id="createTeamModal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="post" action="{% url "participation:create_team" %}">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{% trans "Create team" %}</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-success">{% trans "Create" %}</button>
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
13
apps/participation/templates/participation/join_team.html
Normal file
13
apps/participation/templates/participation/join_team.html
Normal file
@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">{% trans "Join" %}</button>
|
||||
</form>
|
||||
{% endblock content %}
|
@ -0,0 +1,21 @@
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
<div id="joinTeamModal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="post" action="{% url "participation:join_team" %}">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">{% trans "Join team" %}</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">{% trans "Join" %}</button>
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Close" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
@ -1 +1,11 @@
|
||||
urlpatterns = []
|
||||
from django.urls import path
|
||||
|
||||
from .views import CreateTeamView, JoinTeamView
|
||||
|
||||
|
||||
app_name = "participation"
|
||||
|
||||
urlpatterns = [
|
||||
path("create_team/", CreateTeamView.as_view(), name="create_team"),
|
||||
path("join_team/", JoinTeamView.as_view(), name="join_team"),
|
||||
]
|
||||
|
@ -1,3 +1,20 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, FormView
|
||||
|
||||
# Create your views here.
|
||||
from participation.forms import TeamForm, JoinTeamForm
|
||||
from participation.models import Team
|
||||
|
||||
|
||||
class CreateTeamView(LoginRequiredMixin, CreateView):
|
||||
model = Team
|
||||
form_class = TeamForm
|
||||
extra_context = dict(title=_("Create team"))
|
||||
template_name = "participation/create_team.html"
|
||||
|
||||
|
||||
class JoinTeamView(LoginRequiredMixin, FormView):
|
||||
model = Team
|
||||
form_class = JoinTeamForm
|
||||
extra_context = dict(title=_("Join team"))
|
||||
template_name = "participation/create_team.html"
|
||||
|
@ -55,6 +55,10 @@ class Registration(PolymorphicModel):
|
||||
def type(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def participates(self):
|
||||
return isinstance(self, StudentRegistration) or isinstance(self, CoachRegistration)
|
||||
|
||||
def __str__(self):
|
||||
return _("registration of {first_name} {last_name}")\
|
||||
.format(first_name=self.user.first_name, last_name=self.user.last_name)
|
||||
|
@ -5,7 +5,7 @@ from .views import SignupView, UserValidationEmailSentView, UserResendValidation
|
||||
app_name = "registration"
|
||||
|
||||
urlpatterns = [
|
||||
path("signup", SignupView.as_view(), name="signup"),
|
||||
path("signup/", SignupView.as_view(), name="signup"),
|
||||
path('validate_email/sent/', UserValidationEmailSentView.as_view(), name='email_validation_sent'),
|
||||
path('validate_email/resend/<int:pk>/', UserResendValidationEmailView.as_view(),
|
||||
name='email_validation_resend'),
|
||||
|
Reference in New Issue
Block a user